#include <iostream>
#include <queue>
#include <vector>
#define mp make_pair
using namespace std;

struct P{ int tim,group,act; };

struct comp {
	bool operator()(P t1, P t2) const {
		if(t1.tim != t2.tim) return t1.tim > t2.tim;
		else return t1.act > t2.act;
 	}
};

int chair[17];

int emp(int num){
	for(int i = 0;i < 17 - num + 1;i++){
		bool flag = true;
		for(int j = 0;j < num;j++){
			if(chair[i + j] != -1) flag = false;
		}
		if(flag) return i;
	}
	return -1;
}

int main(){
	int n,front = -1,wait[100] = {};
	priority_queue<P,vector<P>,comp> que;
	queue<int> line;
	for(int i = 0;i < 17;i++) chair[i] = -1;
	for(int i = 0;i < 100;i++) que.push({i * 5,i,0});
	while(!que.empty()){
		P p = que.top();que.pop();
		int t = p.tim,group = p.group,act = p.act;
		if(act == 0){
			int num = 2,pos;
			if(group % 5 == 1) num = 5;
			pos = emp(num);
			if(!line.empty() || pos == -1) line.push(group);
			else{
				for(int i = 0;i < num;i++) chair[i + pos] = group;
				que.push({t + 17 * (group % 2) + 3 * (group % 3) + 19,group,1});
			}
		}else{
			for(int i = 0;i < 17;i++){
				if(chair[i] == group) chair[i] = -1;
			}
			while(!line.empty()){
				int g = line.front(),num = 2,pos;
				if(g % 5 == 1) num = 5;
				pos = emp(num);
				if(pos != -1){
					line.pop();
					wait[g] = t - g * 5;
					for(int i = 0;i < num;i++) chair[pos + i] = g;
					que.push({t + 17 * (g % 2) + 3 * (g % 3) + 19,g,1});
				}
				else break;
			}
		}
	}
	while(cin >> n){
		cout << wait[n] << endl;
	}
	return 0;
}