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;
}
 
int 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();
  return a;
}
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,flg2;
  while(!(ts==te)){
 
    /*
    for(int i=0;i<17;i++)printf("%3d ",state[i]);
    cout<<endl;
 
    for(int i=us;i<ue;i++)printf("%3d ",u[i].second.second);
    cout<<endl;
    */
     
    sort(t+ts,t+te);
    y=x;
    x=t_out();
 
    //cout<<x.first<<' '<<x.second.first<<' '<<x.second.second<<endl;
    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;
      if(ts!=te&&t[ts].first==x.first&&t[ts].second.first==0)flg2=0;
      else flg2=1;
      while(flg2){
    if(us==ue)break;
    flg=u_check();
    if(flg==0)break;
    z=u_ins();
     
    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
  }
 
   
  //cout<<te<<endl;
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
  return 0;
}

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;
}