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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999


int data[110];

queue<pii> ar(){
    queue<pii> ret;
    rep(i,100){
        ret.push(pii(i,i*5));
    }
    return ret;
}


queue<pii> de(){
    vector<pii> tmp;
    queue<pii> ret;
    rep(i,100){
        tmp.pb(pii(i*5+17*(i%2)+3*(i%3)+19,i));
    }
    sort(all(tmp));
    rep(i,100){
        ret.push(pii(tmp[i].second,tmp[i].first));
    }
    return ret;
}




void pre(){
    int seat[20];
    rep(i,17)seat[i]=-1;
    queue<pii> arrive = ar();
    queue<pii> dep = de();
    bool flag=true;
    int now=0;
    while(arrive.size()+dep.size()){
        
        if( flag==false || arrive.empty() || arrive.front().second>dep.front().second  ){ //??¢?????????

            int dep_group = dep.front().first;
            now =dep.front().second;
            dep.pop();
            rep(i,17){
                if( seat[i]==dep_group ) seat[i]=-1;
            }
            flag = true;
//            printf("%3d : ",now);
//            rep(i,17){
//                if(seat[i]==-1)cout<<"__ ";
//                else printf("%02d ",seat[i]);
//            }cout<<endl;
        }
        else{ //??¢?????\???
            pii f = arrive.front();
            int members;
            if( (f.first)%5==1 )members = 5;
            else members = 2;
            
            int dp[20]={};
            for(int i=16;i>=0;i--){
                if(seat[i]!=-1) dp[i] = 0;
                else            dp[i] = dp[i+1]+1;
            }
            
            flag = false;
            rep(i,17){
                if(dp[i]>=members){
                    for(int j=i;j<i+members;j++){
                        seat[j] = f.first;
                    }
                    flag=true;
                    arrive.pop();
                    data[f.first] = max(f.second,now);
//                    printf("%3d : ",max(f.second,now));
//                    rep(i,17){
//                        if(seat[i]==-1)cout<<"__ ";
//                        else printf("%02d ",seat[i]);
//                    }cout<<endl;

                    break;
                }
            }
        }
    }
}


int main(){
    int n;
    pre();
    while(cin>>n){
        cout<<max( 0 , data[n]-(5*(int)n) )<<endl;
    }
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int t[110];
int now[20];
int p[110];
int q[110];
int r[110];
int main(){
	for(int i=0;i<100;i++){
		p[i]=i*5;
		if(i%5==1)q[i]=5;
		else q[i]=2;
		r[i]=17*(i%2)+3*(i%3)+19;
	}
	int at=0;
	for(int i=0;i<17;i++)now[i]=-1;
	for(int i=0;i<5000;i++){
		for(int j=0;j<at;j++){
			if(i==t[j]+r[j])for(int k=0;k<17;k++)if(now[k]==j)now[k]=-1;
		}
		while(at<=min(99,i/5)){
			int len=0;
			bool ok=false;
			for(int j=0;j<17;j++){
				if(!~now[j])len++;
				else len=0;
				if(len==q[at]){
					for(int k=j-q[at]+1;k<=j;k++)now[k]=at;
					ok=true;
				}
			}
			if(ok)t[at++]=i;
			else break;
		}
	}int a;
	while(~scanf("%d",&a)){
		printf("%d\n",t[a]-a*5);
	}
}

C++: #include<vector>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int seat[17];
vector<int> rm[5000];
queue<int> q;
int result[100];

int ck(int c){
	c=c%5==1?5:2;
	int suc=0;
	rep(i,17){
		if(seat[i]==-1){
			suc++;
			if(suc==c)return i-suc+1;
		}
		else suc=0;
	}
	return -1;
}
void in(int c,int p,int t){
	int n=c%5==1?5:2;
	rep(i,n)seat[i+p]=c;
	rm[5*c+17*(c%2)+3*(c%3)+19].push_back(c);
	result[c]=t-5*c;
	q.pop();
}
void remove(int c){
	rep(i,17)if(seat[i]==c)seat[i]=-1;
}
int main(){
	rep(i,17)seat[i]=-1;
	
	for(int t=0;t<=500||!q.empty();t++){
		if(t%5==0)q.push(t/5);
		rep(i,rm[t].size())remove(rm[t][i]);
		if(q.empty())continue;
		for(int p=ck(q.front());p>=0&&!q.empty();p=ck(q.front()))in(q.front(),p,t);
	}
	
	int n;
	while(cin>>n)cout<<result[n]<<endl;
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cstring>
using namespace std;

int ans[100];

class G{
public:
  int id,n,a,d; //??°???????????????,?????°,??°?????????,?£??????????

  G(int i){
    id = i;
    n = (i % 5 == 1 ? 5 : 2);
    a = 5 * i;
    d = 17 * (i % 2) + 3 * (i % 3) + 19;
  }
};

//n?????£?¶???§???????¢??????§????????´????????????
int indexOfSeat(int *seat,int n){
  int count = 0;

  for(int i=0;i<17;i++){
    if(!seat[i]){
      count++;
      if(count == n) return i - n + 1;
    }
    else{
      count = 0;
    }
  }

  return -1;
}

void solve(void){
  vector<G> v; //????????????
  for(int i=0;i<100;i++) v.push_back(G(i));

  int time = 0; //?????¨?????????
  int seat[17]; //????????±
  memset(seat,0,sizeof(seat));

  while(!v.empty()){
    while(!v.empty() && v[0].a<=time){
      int idx = indexOfSeat(seat,v[0].n);
      if(idx != -1){
        for(int i=idx;i<idx+v[0].n;i++) seat[i] = v[0].d;
        ans[v[0].id] = time - v[0].a;
        v.erase(v.begin());
      }
      else{
        break;
      }
    }

    time++;
    for(int i=0;i<17;i++) if(seat[i] > 0) seat[i]--;
  }
}

int main(void){
  solve();

  int n;
  while(cin>>n) cout<<ans[n]<<endl;

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int seat[17] = {0};
	int X = 0;
	int stop[100] = {0};
	int time = 0;
	queue<int> Q;
	while(X < 100){
		int x;
		if(time%5 == 0 && time < 500){
			Q.push(time/5);
		}
		while(1){
			if(Q.size())x = Q.front();
			else x = -1;
			bool f = false;
			
			if(~x){
				int people = (x%5==1?5:2);
				int use = 19 + 3 * (x%3) + 17 * (x%2);
				rep(i,17-people+1){
					bool flag = true;
					rep(j,people){
						flag &= seat[i+j] == 0;
					}
					if(flag){
						rep(j,people){
							seat[i+j] = use;
						}
						f = true;
						break;
					}
				}
			}
			if(f){	
				stop[x] = time - x * 5;
				Q.pop();
				X++;
			}
			if(!f)break;
		}
		rep(i,17){
			seat[i] = max(0,seat[i]-1);
		}
		time++;
	}
	int n,c=0;
	
	while(cin >> n){
		if(n < 50)c++;
		cout << stop[n] << endl;
	}
	while(c>=5){return 1;};
	
}