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>
using namespace std;
#define SHEETS 17
#define GROUPS 100
int main()
{
	int ans[GROUPS] = {0,};
	int now;
	int sheets[SHEETS+1] = {-1,};
	int peoples[GROUPS] = {0,};
	int waiting[GROUPS] = {0,};
	int eating[GROUPS] = {0,};

	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; ++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( 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] < 0 ) cont++;
						else break;
					}
					if( cont >= peoples[ now ] && waiting[ now ] >= 0 ){
						for(int j = i; j < i+peoples[now]; ++j)
							sheets[j] = now;
						ans[now] = waiting[now]-1<0?0:waiting[now]-1;
						++now;
						bCont = true;
					}
				}
			}
			if( !bCont )
				break;
		}
	}

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

	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    vector<int> seat(17, -1);
    multimap<int, int> leave;

    vector<int> waitTime(100);
    int prevTime = 0;
    for(int i=0; i<100; ++i){
        int time = 5*i;
        while(leave.size() > 0 && leave.begin()->first <= time){
            replace(seat.begin(), seat.end(), leave.begin()->second, -1);
            leave.erase(leave.begin());
        }

        int num = 2 + (i%5==1? 3:0);
        for(;;){
            vector<int> tmp(num, -1);
            int j = search(seat.begin(), seat.end(), tmp.begin(), tmp.end()) - seat.begin();
            if(j == 17){
                time = leave.begin()->first;
                replace(seat.begin(), seat.end(), leave.begin()->second, -1);
                leave.erase(leave.begin());
            }else{
                for(int k=0; k<num; ++k)
                    seat[j+k] = i;
                break;
            }
        }

        prevTime = max(time, prevTime);
        waitTime[i] = prevTime - 5*i;

        time += 17*(i%2) + 3*(i%3) + 19;
        leave.insert(make_pair(time, i));
    }

    for(;;){
        int n;
        if(!(cin >> n))
            return 0;
        cout << waitTime[n] << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

int search_sequence(vector<int> &a,int n){
	int cnt=0;
	for(int i=0;i<a.size();++i){
		if(a[i]==-1)++cnt;
		else cnt=0;
		if(cnt>=n)return i-cnt+1;
	}
	return -1;
}

int main(void){
    vector<int> seat(17,-1);
    int time[100],finish[100];
    queue<pair<int,int> > q;
    int x=0,y=0;
    for(int t=0;y<100;++t){
      if(t%5==0&&x<100) q.push(make_pair(x++,(x%5==1)?5:2));
      for(int i=0;i<17;++i){
        if(seat[i]!=-1&&finish[seat[i]]==t){
        	fill(&seat[i],&seat[i+((seat[i]%5==1)?5:2)],-1);
        	//cerr<<t<<":";for(int i=0;i<17;++i)cerr<<seat[i]<<((i!=16)?" ":"\n");
      	}
      }
      while(!q.empty()){
      	pair <int,int> p=q.front();
      	if(search_sequence(seat,p.second)==-1)break;
        fill(&seat[search_sequence(seat,p.second)],&seat[search_sequence(seat,p.second)+p.second],p.first);
        //cerr<<t<<":";for(int i=0;i<17;++i)cerr<<seat[i]<<((i!=16)?" ":"\n");
        finish[p.first]=t+17*(p.first%2)+3*(p.first%3)+19;
        time[p.first]=t-5*p.first;
        q.pop();++y;
      }
    }
  int n;
  while(cin>>n){
  	cout<<time[n]<<endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define N 100
typedef long long ll;
typedef pair<int,int>P;
typedef struct D{int t,n,e;bool operator <(const D &a)const{return t==a.t?e<a.e:t>a.t;}};
priority_queue<D>F;
int r[N],s[20],w=0;

int ch(int n)
{
	for(int i=0;i<17;i++)
		if(s[i]==-1)
		{
			int j;
			for(j=0;j<n&&i+j<17;j++)if(s[i+j]!=-1)break;
			if(j==n)return i;
		}
	return -1;
}

int main()
{
	memset(s,-1,sizeof(s));
	for(int i=0;i<N;i++)
	{
		D tmp={i*5,i,0};
		F.push(tmp);
	}
	while(!F.empty())
	{
		D n=F.top();F.pop();
		if(n.e)
		{
			for(int i=0;i<17;i++)
				if(s[i]==n.n)s[i]=-1;
		}
		else
		{
			if(w<n.n)
			{
				n.t++;
				F.push(n);
				continue;
			}
			int a=n.n%5==1?5:2,b=ch(a);
			if(b!=-1)
			{
				for(int j=0;j<a;j++)
					s[b+j]=n.n;
				r[n.n]=n.t-5*n.n;
				w=n.n+1;
				D tmp={n.t+19+17*(n.n%2)+3*(n.n%3),n.n,1};
				F.push(tmp);
			}
			else
			{
				n.t++;
				F.push(n);
			}
		}
	}
	for(;~scanf("%d",&w);)printf("%d\n",r[w]);
	return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;
int n,c[17],d[100];
main()
{
	for(int i=0;i<17;i++)c[i]=-1;
	priority_queue<pair<int,int> >P;
	int now=0;
	for(int i=0;i<100;i++)
	{
		while(!P.empty()&&-P.top().first<=i*5)P.pop();
		int L=-1;
		while(L<0)
		{
			for(int j=0;j+(i%5==1?5:2)<=17;j++)
			{
				bool ok=1;
				for(int k=0;k<(i%5==1?5:2);k++)ok&=c[j+k]==-1;
				if(ok)
				{
					L=j;break;
				}
			}
			if(L>=0)break;
			pair<int,int>p=P.top();P.pop();
			now=-p.first;
			for(int j=0;j<17;j++)if(c[j]==p.second)c[j]=-1;
		}
		if(now<i*5)now=i*5;
		P.push(make_pair(-now-(17*(i%2)+3*(i%3)+19),i));
		d[i]=now-i*5;
		for(int k=0;k<(i%5==1?5:2);k++)c[L+k]=i;
	}
	while(cin>>n)cout<<d[n]<<endl;
}