Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)
const INF = 0x7fffffff
func main() {
	S := 17
	seat := make([][]int, 27)
	for i :=range seat {
		seat[i] = make([]int, 27)
	}
	ans := make([]int, 105)
	id := 0
	Q := make([][]int, 0)
	for i := 0; i < S; i++ {
		seat[i][0] = -1
	}
	t := -1
	for ans[99] == 0 {
		t++
		if  t%5 == 0 && id <= 99 {
			if id % 5 == 1 {
				n := 5
				tmp := []int{id, n, t}
				Q = append(Q, tmp)
				id++
			} else {
				n := 2
				tmp := []int{id, n, t}
				Q = append(Q, tmp)
				id++
			}
		}
		for i := 0; i < 5; i++ {
			if seat[i][1] == 0 {
				continue
			}
			seat[i][1]--
			if seat[i][1] == 0 {
				seat[i][0] = -1
			}
		}
		f := len(Q)
		for f > 0 {
			i, n := Q[0][0], Q[0][1]
			f = 0
			for j := 0; j < S; j++ {
				g := 0
				for k := 0; k < n; k++ {
					if seat[j+k][0] >= 0 {
						g = 1
						break
					}
				}
				if g != 0 {
					continue
				}
				ans[i] = t-Q[0][2]
				Q = Q[1:]
				f = len(Q)
				for k := 0; k < n; k++ {
					seat[j+k][0] = i
					seat[j+k][1] = 17*(i&1) + 3*(i%3) + 19
				}
				break
			}
		}
	}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		fmt.Println(ans[n])
	}
}

C++: #include<iostream>
using namespace std;
#define SHEETS 17
#define GROUPS 130

int main()
{
	int ans[GROUPS] = {0,};
	int now;
	int sheets[SHEETS+1] = {-1,};
	int peoples[GROUPS] = {0,};
	int arrive[GROUPS] = {0,};
	int eating[GROUPS] = {0,};

	for(int i = 0; i < SHEETS+1; ++i){
		sheets[i] = -1;
	}
	sheets[SHEETS] = -2;
	for(int i = 0; i < GROUPS; ++i)
	{
		arrive[i] = i*5;
		peoples[i] = i%5==1?5:2;
		eating[i] = 17*(i%2)+3*(i%3)+19;
	}
	now = 0;
	for(int t = 0; t < 800; ++t){

		if( t % 10 == 0 ){
			//int a;
			//cin >> a;
		}

		for(int i = 0; i < SHEETS; ++i){
			if( sheets[i] >= 0 ){
				--eating[sheets[i]];
				if( eating[sheets[i]] == 0 ){
					for(;sheets[i+1]==sheets[i];++i)
						sheets[i] = -1;
					if( i < SHEETS )
					sheets[i] = -1;
				}else{
					for(;sheets[i+1]==sheets[i];++i)
						0;
				}
			}
		}

		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] == -1 ) cont++;
						else break;
					}
					if( now < GROUPS && cont >= peoples[ now ] && t >= arrive[ now ] ){
						for(int j = i; j < i+peoples[now]; ++j)
							sheets[j] = now;
						
						/*cout << "NOW: "<<now;
						cout << " ANS: " << t << "-" << arrive[now] << "=" << ans[now] << '\n';
						cout << "t=" << t <<":\t";
						for(int i = 0; i < SHEETS; ++i){
							cout << sheets[i] << ' ';
						}
						cout << endl;*/
						
						ans[now] = t - arrive[now];//<0?0:waiting[now];
						++now;
						bCont = true;
					}
				}
			}
			if( !bCont )
				break;
		}
		
		
	}
	/*
	for(int i = 0; i < GROUPS;++i){
		cout << ans[i] << ' ';
	}
	*/

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

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <map>
using namespace std;
 
 int main() {
  int i=0,j,k=0,m,f,n,t=0,s[17],ad[100],len[100],ans[100];
  multimap<int,int> mp;
  for (k=0;k<17;k++) s[k]=-1;
  while(true) {
  for (;i<100;i++) {
	  len[i]=(i % 5)==1 ? 5 : 2;
	  for (j=0;j<17-len[i];j++) {
		  for (k=0;k<len[i];k++) if (s[j+k]>=0) break;
		  if (k==len[i])  { for (k=j;k<j+len[i];k++) s[k]=i; 
		  ans[i]=t>i*5 ? t-5*i : 0;
		  ad[i]=j;
		  mp.insert(multimap<int,int>::value_type(i*5+17*(i%2)+3*(i%3)+19,i)); 
		  break;} 
	  }
      if (j==17-len[i]) break;
  }
  if (i==100) break;
  t=(*mp.begin()).first;
  while(!mp.empty() && (*mp.begin()).first ==t) {
	  m=(*mp.begin()).second;
	  for (j=ad[m]; j<ad[m]+len[m]; j++) s[j]=-1;
	  mp.erase(mp.begin());
     }
  }
  while(cin >> n) cout << ans[n] << endl;
   return 0;
 }

C++: //52
#include<iostream>
#include<queue>
#include<algorithm>

using namespace std;

int main(){
  int a[100];
  int cr[17]={};
  queue<int> que;
  for(int t=0;t<600;t++){
    if(t%5==0&&t/5<100){
      que.push(t/5);
    }
    for(int i=0;i<17;i++){
      cr[i]--;
    }
    int fc=0;
    for(int i=0;i<17;i++){
      if(cr[i]<=0){
	fc++;
	if(!que.empty()){
	  int gn=que.front();
	  int ng=(gn%5==1)?5:2;
	  if(fc==ng){
	    for(int j=0;j<ng;j++){
	      cr[i-j]=17*(gn%2)+3*(gn%3)+19;
	    }
	    a[gn]=t-gn*5;
	    que.pop();
	    i=0;
	    fc=0;
	  }
	}
      }else{
	fc=0;
      }
    }
  }
  for(int n;cin>>n;){
    cout<<a[n]<<endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int seat[17];
int res[200];

int main() {
	int i;
	int j;
	int k=-1;
	for(i=0;i<600;i++){
//cout<<i<<endl;
		for(j=0;j<17;j++){
			if(seat[j])seat[j]--;
//cout<<" "<<j<<" "<<seat[j]<<endl;
		}
		if(k==-1){
			if(i%5==0){
				k=i/5;
			}
		}
		while(1){
			int l;
			if(k==-1)break;
			if(k%5==1){
				for(l=0;l<=17-5;l++){
					if(seat[l]+seat[l+1]+seat[l+2]+seat[l+3]+seat[l+4]==0){
						seat[l]=seat[l+1]=seat[l+2]=seat[l+3]=seat[l+4]=17*(k%2)+3*(k%3)+19;
						res[k]=i-k*5;
						k++;
						if(k>i/5)k=-1;
						goto a;
					}
				}
			}else{
				for(l=0;l<=17-2;l++){
					if(seat[l]+seat[l+1]==0){
						seat[l]=seat[l+1]=17*(k%2)+3*(k%3)+19;
						res[k]=i-k*5;
						k++;
						if(k>i/5)k=-1;
						goto a;
					}
				}
			}
			break;
			a:;
		}
//cout<<i<<endl;
//for(j=0;j<17;j++){
//	cout<<" "<<j<<" "<<seat[j]<<endl;
//}
//cout<<"  "<<k<<endl;
	}
	int n;
//for(n=0;n<200;n++){
//	cout<<n<<" "<<res[n]<<endl;
//}
	while(cin>>n){
		cout<<res[n]<<endl;
	}
	return 0;
}

//WA

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int seat[17];
int res[200];

int main() {
	int i;
	int j;
	int k=-1;
	for(i=0;i<600;i++){
//cout<<i<<endl;
		for(j=0;j<17;j++){
			if(seat[j])seat[j]--;
//cout<<" "<<j<<" "<<seat[j]<<endl;
		}
		if(k==-1){
			if(i%5==0){
				k=i/5;
			}
		}
		while(1){
			int l;
			if(k==-1)break;
			if(k%5==1){
				for(l=0;l<17-5;l++){
					if(seat[l]+seat[l+1]+seat[l+2]+seat[l+3]+seat[l+4]==0){
						seat[l]=seat[l+1]=seat[l+2]=seat[l+3]=seat[l+4]=17*(k%2)+3*(k%3)+19;
						res[k]=i-k*5;
						k++;
						if(k>i/5)k=-1;
						goto a;
					}
				}
			}else{
				for(l=0;l<17-2;l++){
					if(seat[l]+seat[l+1]==0){
						seat[l]=seat[l+1]=17*(k%2)+3*(k%3)+19;
						res[k]=i-k*5;
						k++;
						if(k>i/5)k=-1;
						goto a;
					}
				}
			}
			break;
			a:;
		}
//cout<<i<<endl;
//for(j=0;j<17;j++){
//	cout<<" "<<j<<" "<<seat[j]<<endl;
//}
	}
	int n;
//for(n=0;n<100;n++){
//	cout<<n<<" "<<res[n]<<endl;
//}
	while(cin>>n){
		cout<<res[n]<<endl;
	}
	return 0;
}

//WA