Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)
const INF = 0x7fffffff
func main() {
	S := 17
	seat := make([][]int, 27)
	for i :=range seat {
		seat[i] = make([]int, 27)
	}
	ans := make([]int, 105)
	id := 0
	Q := make([][]int, 0)
	for i := 0; i < S; i++ {
		seat[i][0] = -1
	}
	t := -1
	for ans[99] == 0 {
		t++
		if  t%5 == 0 && id <= 99 {
			if id % 5 == 1 {
				n := 5
				tmp := []int{id, n, t}
				Q = append(Q, tmp)
				id++
			} else {
				n := 2
				tmp := []int{id, n, t}
				Q = append(Q, tmp)
				id++
			}
		}
		for i := 0; i < 5; i++ {
			if seat[i][1] == 0 {
				continue
			}
			seat[i][1]--
			if seat[i][1] == 0 {
				seat[i][0] = -1
			}
		}
		f := len(Q)
		for f > 0 {
			i, n := Q[0][0], Q[0][1]
			f = 0
			for j := 0; j < S; j++ {
				g := 0
				for k := 0; k < n; k++ {
					if seat[j+k][0] >= 0 {
						g = 1
						break
					}
				}
				if g != 0 {
					continue
				}
				ans[i] = t-Q[0][2]
				Q = Q[1:]
				f = len(Q)
				for k := 0; k < n; k++ {
					seat[j+k][0] = i
					seat[j+k][1] = 17*(i&1) + 3*(i%3) + 19
				}
				break
			}
		}
	}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		fmt.Println(ans[n])
	}
}

C++: #include<iostream>
#include<algorithm>
#include<deque>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
using namespace std;

int ans[200];
int seat[16];

int check(int n)
{
  int size = (n%5==1?5:2);
  int cnt = 0;
  rep(i,16)
    {
      if(seat[i] == 0)cnt++;
      else            cnt = 0;
      if(cnt >= size)
	return i-size+1;
    }
  return -1;
}

int main()
{
  rep(i,200)ans[i] = 0;
  int phase = 0;
  int group = 0;
  //17(i%2)+3(i%3)+19 
  deque<int> que;
  rep(i,16)seat[i] = 0;
  while(group < 105)
    {
      //cout << phase << " --------- " << endl;
      //if(!que.empty())
	//cout << "top = " <<que.front() << endl;
	//rep(i,16)cout << seat[i] << " ";
	//cout << endl << endl;
      if(phase%5 == 0)
	{
	  que.push_back(group++);
	}
      rep(i,16)if(seat[i] > 0)seat[i]--;
      int pos;

      while(!que.empty() && ((pos = check(que.front())) != -1) )
	{
	  int i = que.front();
	  int tm = 17 * (i % 2) + 3 * (i % 3) + 19;
	  REP(j,pos,pos+(i%5==1?5:2))
	    {
	      assert(seat[j] == 0);
	      seat[j] = tm;
	    }
	  que.pop_front();
	}

      for(deque<int>::iterator it = que.begin(); it != que.end();it++)
	{
	  ans[*it]++;
	}

      phase++;
    }
  int n;
  while(cin >> n)cout << ans[n] << endl;
  return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
struct cus
{
	int a,b,c,d;
};

int main()
{
	cus a[100];
	for(int i=0;i<100;i++)
	{
		a[i].a=5*i;
		a[i].b=(i%5==1?5:2);
		a[i].c=17*(i%2)+3*(i%3)+19;
		a[i].d=0;
	}
	int t[20]={};
	for(int i=0;i<100;i++)
	{
		//for(int j=0;j<17;j++)printf("%3d",t[j]);
		//cout<<endl;
		int k=max(a[max(0,i-1)].d,a[i].a);
		for(;;k++)for(int j=0;j<17-a[i].b+1;j++)
		{
			bool x=true;
			for(int l=j;l<j+a[i].b;l++)
			{
				if(t[l]>k)x=false;
			}
			if(x)
			{
				for(int l=j;l<j+a[i].b;l++)
				{
					t[l]=k+a[i].c;
				}
				a[i].c=k-a[i].a;
				a[i].d=k;
				goto end;
			}
		}
		;end:;
	}
	int n;
	while(cin>>n)
	{
		cout<<a[n].c<<endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))

int main(){
    int d[17]; int n[100]={0}; int cnt=0,t=0;
    queue<int> q; rep(i,17)d[i]=0;
    for(;cnt<100;t++){
        if(t%5==0 && t<500)q.push(t/5);
        while(!q.empty()){
            int v=q.front();
            int num=v%5==1?5:2;
            int g=0;
            rep(j,18-num){
            	if(d[j]<1 && !g){g=1;reps(k,1,num-1){
                    	if(d[j+k]>0)g=0;
                    }
                    if(g){rep(k,num)d[j+k]=17*(v%2)+3*(v%3)+19;}
                }
            }
            if(!g)break;
            q.pop();
            n[v]=t-v*5;
            cnt++;
        }
        rep(i,17)if(d[i]>0)d[i]--;
    }
    while(~scanf("%d",&t))printf("%d\n",n[t]);
    return 0;
}

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