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;

struct g{
	int p,t,e,ans;
};

g a[100];
int seat[17];

int main(){
	for(int i=0; i<17; i++)
		seat[i] = -1;
	for(int i=0; i<100; i++){
		a[i].p = 2;
		if(i%5 == 1)
			a[i].p += 3;
		a[i].t = i*5;
		a[i].e = 17*(i%2)+3*(i%3)+19;
	}
	int i=0;
	for(int tim=0;i<100;tim++){
		for(int k=0; k<17; k++){
			if(seat[k] != -1){
				if(a[seat[k]].ans+a[seat[k]].t+a[seat[k]].e <= tim)
					for(int j=0; j<a[seat[k]].p; j++)
						seat[j+k] = -1;
			}
		}
P:;
		if(a[i].t <= tim){
			bool flag = true;
			int tmp = -1;
			for(int j=0; j<=17-a[i].p; j++){
				for(int k=j; k<j+a[i].p; k++)
					if(seat[k]!=-1)
						flag = false;
				if(flag){
					tmp = j;
					break;
				}
				else
					flag = true;
			}
			if(tmp != -1){
				for(int j = 0; j<a[i].p; j++)
					seat[j+tmp] = i;
				a[i].ans = tim-a[i].t;
				i++;
				if(i<100)
					goto P;
			}
		}
	}
	int n;
	while(cin >> n)
		cout << a[n].ans << endl;
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) REP((i),0,(n))
#define RREP(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rrep(i,n) RREP(i,n,0)
#define each(it,X) for(__typeof((X).begin())  it=(X).begin();it!=(X).end();it++)
#define all(v) ((v).begin(),(v).end())
#define fi first
#define se second
#define pb push_back
typedef pair<int,int>pr;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef set<int>si;
const int INF=1070000000ll;
const int mod=1000000007ll;

int N;
int a[100];

int seet[17];
queue<int>Q;

void in(int t){
    while(!Q.empty()){
        int p=Q.front();
        int n=(p%5==1?5:2);
        bool in_flag=false;
        for(int i=0;i+n<=17;i++){
            bool flag=true;
            for(int j=i;j<i+n;j++){
                if(seet[j]){
                    flag=false;
                    break;
                }
            }
            if(!flag)continue;
            Q.pop();
            for(int j=i;j<i+n;j++){
                seet[j]=17*(p%2)+3*(p%3)+19;
            }
            a[p]=t-5*p;
            in_flag=true;
            break;
        }
        if(!in_flag)return;
    }
}
void eat(){
    for(int i=0;i<17;i++)if(seet[i])seet[i]--;
}
signed main(){

    for(int i=0;i<500||!Q.empty();i++){
        if(i%5==0&&i<500)Q.push(i/5);
        in(i);
        eat();
    }

    while(scanf("%d",&N)!=EOF)printf("%d\n",a[N]);
    return 0;
}

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

int waitTime[ 100 ];
const int NUM_SEATS = 17;

int isVacancy( int* seats, int n )
{
	int empties = 0;
	for( int i = 0; i < NUM_SEATS; ++i ){
		if( seats[ i ] <= 0 ){
			++empties;
			if( empties == n ){
				return i - n + 1;
			}
		}else{
			empties = 0;
		}
	}
	return -1;
}

void pass( int* seats, int* time )
{
	++*time;
	for( int i = 0; i < NUM_SEATS; ++i ){
		--seats[ i ];
	}
}

int main()
{
	int seats[ NUM_SEATS ];
	memset( seats, 0, sizeof(seats) );
	int time = 0;
	for( int i = 0; i < 100; ++i ){
		while( time < i * 5 ){
			pass( seats, &time );
		}
		int numPeople = i % 5 == 1 ? 5 : 2;
		int eatingTime = 17 * ( i % 2 ) + 3 * ( i % 3 ) + 19;
		int emptySeat = 0;
		while( ( emptySeat = isVacancy( seats, numPeople ) ) == -1 ){
			pass( seats, &time );
		}
		for( int j = emptySeat; j < numPeople + emptySeat; ++j ){
			seats[ j ] = eatingTime;
		}
		waitTime[ i ] = time - i * 5;
	}

	int input;
	while( cin >> input ){
		cout << waitTime[ input ] << endl;
	}


	return 0;
}

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;
	}
	sheets[SHEETS] = -2;
	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 = 0;
	for(int t = 0; t < 590; ++t){

		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;
					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] < 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];//<0?0:waiting[now];
						++now;
						bCont = true;
					}
				}
			}
			if( !bCont )
				break;
		}		
		for(int i = 0; i < GROUPS; ++i){
			++waiting[i];
		}
	}

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

	return 0;
}