#include<iostream>
#include<algorithm>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

multimap<int,int> ckout;
int ckin[100],seat[17];

void rm(multimap<int,int>::iterator p){
	rep(i,17)if(seat[i]==p->second)seat[i]=-1;
	ckout.erase(p);
}
int findseat(int k){
	int l=k%5==1?5:2,len=0,p,pos;
	for(p=0;p<17;p++){
		if(seat[p]==-1){
			if(!len)pos=p;
			if(++len==l)return pos;
		}else len=0;
	}
	return -1;
}
int main(){
	fill(ckin,ckin+100,-1); fill(seat,seat+17,-1);
	int n,k,t,q;
	multimap<int,int>::iterator p;
	for(k=t=0;k<100||ckout.empty();t++){
		while((p=ckout.find(t))!=ckout.end())rm(p);
		while(ckin[k]==-1&&t>=5*k){
			if((q=findseat(k))!=-1){
				int l=k%5==1?5:2;
				ckin[k]=t;
				rep(i,l)seat[q+i]=k;
				ckout.insert(make_pair(t+17*(k%2)+3*(k%3)+19,k));
				k++;
			}else break;
		}
	}
	while(cin>>n)cout<<ckin[n]-n*5<<endl;
	return 0;
}