Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

type chair struct {
	group_id, rest_time int
}

type info struct {
	group_id, num, wait_sum, before_go int
	fixed                              bool
}

func main() {
	ans := make([]int, 100)
	chair := make([]chair, 17)
	for i := 0; i < 17; i++ {
		chair[i].group_id = -1
	}
	info := make([]info, 100)
	for i := 0; i <= 99; i++ {
		info[i].group_id = i
		info[i].before_go = 5 * i
		info[i].wait_sum = 0
		if i%5 == 1 {
			info[i].num = 5
		} else {
			info[i].num = 2
		}
		info[i].fixed = false
	}
	count := 0
	FLG := 0
	tmp_num := 0
	isOK := false
	waitFLG := false
	for {
		for i := 0; i < 17; i++ {
			if chair[i].group_id != -1 {
				chair[i].rest_time--
				if chair[i].rest_time <= 0 {
					chair[i].group_id = -1
				}
			}
		}
		waitFLG = false
		count = 0
		for i := 0; i < 100; i++ {
			if info[i].fixed {
				continue
			}
			if waitFLG == false && info[i].before_go == 0 {
				FLG = -1
				tmp_num = info[i].num
				for k := 0; k <= 17-tmp_num; k++ {
					isOK = true
					for p := 0; p < tmp_num; p++ {
						if chair[k+p].group_id != -1 {
							isOK = false
							break
						}
					}
					if isOK {
						FLG = k
						break
					}
				}
				if FLG != -1 {
					for k := FLG; k < FLG+tmp_num; k++ {
						chair[k].group_id = info[i].group_id
						chair[k].rest_time = 17*(i%2) + 3*(i%3) + 19
						info[i].fixed = true
					}
				} else {
					waitFLG = true
					info[i].wait_sum++
					count++
				}
			} else {
				if info[i].before_go == 0 {
					info[i].wait_sum++
				} else {
					info[i].before_go--
				}
				count++
			}
		}
		if count == 0 {
			break
		}
	}
	for i := 0; i <= 99; i++ {
		ans[i] = info[i].wait_sum
	}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		fmt.Println(ans[n])
	}
}

C++: #include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int, P > PP;
int n,ans[100];
PP t[500];
PP u[500];
int ts,te,us,ue;
int state[17];

void t_in(PP x){
  t[te]=x;
  te++;
}
void u_in(PP x){
  u[ue]=x;
  ue++;
}
PP t_out(){
  ts++;
  return t[ts-1];
}
PP u_out(){
  us++;
  return u[us-1];
}


int u_check(){
  int a = u[us].second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	return 1;
      }
    }else{
      cnt=0;
    }
  }
  return 0;
}

void u_ins(){
  int a = u[us].second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	for(int j=i;j>i-b;j--){
	  state[j]=a;
	}
	break;
      }
    }else{
      cnt=0;
    }
  }
  
  
  u_out();
}
int u_check2(PP x){
  int a = x.second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	return 1;
      }
    }else{
      cnt=0;
    }
  }
  return 0;
}
void u_ins2(PP x){
  int a = x.second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	for(int j=i;j>i-b;j--){
	  state[j]=a;
	}
	break;
      }
    }else{
      cnt=0;
    }
  }
}

int main(){
  ts=us=te=ue=0;

  for(int i=0;i<100;i++)ans[i]=0;
  for(int i=0;i<17;i++)state[i]=-1;

  for(int i=0;i<100;i++){
    t_in(PP(5*i,P(1,i)));
  }

  sort(t+ts,t+te);

  PP x,y;
  int flg,z;
  while(!(ts==te)){
    /*
    cout<<endl;
    for(int i=0;i<17;i++)printf("%3d ",state[i]);
    cout<<"u"<<endl;
    for(int i=us;i<ue;i++)printf("%3d ",u[i].second.second);
    cout<<endl;
    cout<<endl;
    */
    sort(t+ts,t+te);
    y=x;
    x=t_out();

    
    for(int i=us;i<ue;i++)ans[u[i].second.second]+=(x.first-y.first);

    if(x.second.first==0){
      for(int i=0;i<17;i++)if(state[i]==x.second.second)state[i]=-1;
      while(1){
	if(us==ue)break;
	flg=u_check();
	if(flg==0)break;
	u_ins();
	z=x.second.second;
	t_in(PP(x.first+(17*(z%2)+3*(z%3)+19),P(0,z)));
      }
            
    }else if(x.second.first==1){
      flg=u_check2(x);

      if(flg==0||us!=ue){
	u_in(x);
      }else{
	u_ins2(x);

	z=x.second.second;
	t_in(PP(x.first+(17*(z%2)+3*(z%3)+19),P(0,z)));
      }
    }//if
  }

  
  
  while(cin>>n){
    for(int i=n;i<=n;i++)cout<<ans[i]<<' ';
    cout<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

int main(){

	int n;
	map<int,vector<int> > escape;

	int data[100];
	int field[17];
	fill(field,field+17,-1);

	queue<int> waitQueue;
	int group=0;
	int time=0;
	
	vector<int> c;
	while(cin>>n){
		c.push_back(n);
	}
	
	for(int i=0;;i++){
		time=i;
		if(i%5==0){
			waitQueue.push(group);
			group++;
		}
		// Ü¸ÔØêO[vðÈ©çÇ©·
		for(map<int,vector<int> >::iterator it = escape.begin(); it != escape.end(); it++){
			if(it->first==i){
				for(int j = 0; j < 17; j++){
					for(int k = 0; k< it->second.size(); k++){
						if(field[j]==it->second[k]){
							field[j]=-1;
							break;
						}
					}
				}
				it->second.clear();
				break;
			}
		}
		
		bool f=false;
		int prvCand=-1;
		// ·íêé¾¯·íç¹é
		while(1){
			if(waitQueue.size()==0)
				break;
			// ¡ñÀç¹él
			int cand=waitQueue.front();
			if(prvCand==cand)
				break;
			int s;
			int mergen=-1;
			for(int j = 0; j < 17; j++){
				if(field[j]==-1&&j!=16){
					if(mergen==-1){
						s=j;
						mergen=1;
					}
					else{
						mergen++;
					}
				}
				else{
					if(j==16){
						if(field[j]==-1){
							mergen++;
						}
					}

					if(cand%5==1){
						if(mergen>=5){
							// ·íç¹é
							for(int k = s; k < 5+s; k++){
								field[k]=cand;
							}
							//								cout<<cand<<endl;
							
							data[cand]=time-cand*5;
							waitQueue.pop();
							escape[17*(cand%2)+3*(cand%3)+19+i].push_back(cand);
							if(cand==99){
								f=true;
								break;
							}
							break;
						}
						else{
							mergen=-1;
						}
					}
					else{
						if(mergen>=2){
							// ·íç¹é
							for(int k = s; k < 2+s; k++){
								field[k]=cand;
							}
							data[cand]=time-cand*5;
							waitQueue.pop();
							escape[17*(cand%2)+3*(cand%3)+19+i].push_back(cand);
							if(cand==99){
								f=true;
								break;
							}
							break;
						}
						else
							mergen=-1;
					}
				}
				if(f)
					break;
			}
			if(f)
				break;
			prvCand=cand;
		}
		if(f)
			break;
		
	}
	for(int i = 0; i < c.size(); i++){
		// ±±ÅÜ¿Ôð\¦
		cout<<data[c[i]]<<endl;
	}
	//	}
	
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int MS=17;
int mem[101],wait[101],eatingtime[101],seat[MS],hantei[6];

int main(){
  for(int i=0;i<100;i++){
    mem[i]=2;
    if(i%5==1){
      mem[i]=5;
    }
  }
  for(int i=0;i<100;i++){
    eatingtime[i]=17*(i%2)+3*(i%3)+19;
  }
  int time=0,n=0;
  while(n<100){
    for(int j=0;j<MS;j++){
      if(seat[j]>0){seat[j]--;}
    }
    /*    if(time<100){
      cout<<time;
      for(int gi=0;gi<MS;gi++)
	{
	  printf(" %d",seat[gi]);
	  if(gi==MS-1){cout<<endl;
	  }
	}
	}*/
      while((time+1)>(n*5))
	{
	for(int j=0;j<MS-1;j++)
	  {
	    for(int seki=0;seki<2;seki++){
	      if(seat[j+seki]!=0){break;}
	      if(seki==1){hantei[2]=1;hantei[0]=j;j=MS;}
	    }
	  }
	for(int j=0;j<MS-4;j++)
	  {
	    for(int seki=0;seki<5;seki++){
	      if(seat[j+seki]!=0){break;}
	      if(seki==4){hantei[5]=1;hantei[3]=j;j=MS;}
	    }
	  }
	if(hantei[mem[n]]==1){
	  wait[n]=time-(n*5);
	  for(int ji=0;ji<mem[n];ji++){
	    seat[hantei[mem[n]-2]+ji]=eatingtime[n];
	  }
	  n++;
	}
	if(hantei[mem[n]]==0){break;}
	hantei[2]=0;
	hantei[5]=0;

	}
      time++;
  }
  int t;
  while(~scanf("%d",&t)){
    printf("%d\n",wait[t]);
  }
}