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

		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 && ans < 0; ++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( ans < 0 ){
				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;
							if( now == n ){
								ans = waiting[now] - 1;
								break;
							}
							++now;
							bCont = true;
						}
					}
				}
				if( !bCont )
					break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}