#include<iostream>
using namespace std;
#define SHEETS 17
#define GROUPS 100
int main()
{
	int ans[GROUPS] = {0,};
	int now;
	int sheets[SHEETS+1] = {-1,};
	int peoples[GROUPS] = {0,};
	int waiting[GROUPS] = {0,};
	int eating[GROUPS] = {0,};

	for(int i = 0; i < SHEETS+1; ++i){
		sheets[i] = -1;
	}
	for(int i = 0; i < GROUPS; ++i)
	{
		waiting[i] = -i*5;
		peoples[i] = i%5==1?5:2;
		eating[i] = 17*(i%2)+3*(i%3)+19;
	}
	now = 1;
	sheets[0] = sheets[1] = 0;
	for(int t = 0; t < 2000; ++t){
		
		for(int i = 0; i < GROUPS; ++i){
			++waiting[i];
		}
		
		for(int i = 0; i < SHEETS; ++i){
			if( sheets[i] >= 0 ){
				if( eating[sheets[i]] == 0 )
					sheets[i] = -1;
				else{
					--eating[sheets[i]];
					for(;sheets[i+1]==sheets[i];++i)0;
				}
			}
		}
		
		/*
		cout << "t="<<t<<":\t\t";
		for(int i = 0; i < SHEETS; ++i){
			cout << (char)(sheets[i]==-1?'_':sheets[i]+'0');
		}
		cout << '\n';
		*/
		
		while( true ){
			bool bCont = false;
			for(int i = 0; i < SHEETS; ++i){
				int cont = 0;
				if( sheets[i] < 0 ){
					for(int j = i; j < SHEETS; ++j){
						if( sheets[j] < 0 ) cont++;
						else break;
					}
					if( cont >= peoples[ now ] && waiting[ now ] >= 0 ){
						for(int j = i; j < i+peoples[now]; ++j)
							sheets[j] = now;
						ans[now] = waiting[now]-1<0?0:waiting[now]-1;
						++now;
						bCont = true;
					}
				}
			}
			if( !bCont )
				break;
		}
	}

	while(true){
		int n;
		cin >> n;
		if(n == 0)
			break;
		cout << ans[n] << endl;
	}

	return 0;
}