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 <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int N = 16;
int seat[N+1];
int ans[100];

void sim(){
	int t = 0;
	rep(i, 100){
		int num = i%5==1?5:2;
		if(t < 5*i){
			rep(j, N) seat[j] -= min(seat[j], 5*i-t);
			t = 5*i;
		}
		bool ok = false;
		while(1){
			int cnt = 0;
			rep(j, num) cnt += !!seat[j];
			rep(j, N-num){
				if(cnt == 0){
					FOR(k, j, j+num) seat[k] = 17*(i%2)+3*(i%3)+19;
					ans[i] = t-5*i;
					ok = true;
					break;
				}
				if(seat[j+num]) ++cnt;
				if(seat[j]) --cnt;
			}
			if(ok) break;
			int mint = 1<<29;
			rep(j, N) if(seat[j]) mint = min(mint, seat[j]);
			rep(j, N) if(seat[j]) seat[j] -= mint;
			t += mint;
		}
		//printf("\ntime:%d\nseat:", t);
		//rep(j, N) printf("%3d", seat[j]);
	}
}

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

	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;
				if(seat[k]%5==1)
					k+=4;
				else
					k++;
			}
		}
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-1;
				i++;
				if(i<100)
					goto P;
			}
		}
	}
	int n;
	while(cin >> n)
		cout << a[n].ans << endl;
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int Time[100];// = {  0,  5, 10, 15, 20, 25, 30, 35, 40, 45};
int peop[100];// = {  2,  5,  2,  2,  2,  2,  5,  2,  2,  2};
int eats[100];// = { 19, 39, 25, 36, 22, 42, 19, 39, 25, 36};
int star[100];
int tabl[17];
int ans[100];

int main(){
  int next = 0;
  REP(i,100){
    Time[i] = 5 * i;
    peop[i] = (i%5 == 1 ? 5 : 2);
    eats[i] = 17*(i%2) + 3*(i%3) + 19;
  }

  REP(i,17) tabl[i] = -1;
  for(int i=0; ; i++){
    REP(j,17) if(tabl[j] != -1){
      int t = tabl[j];
      if(star[t] + eats[t] == i){
        tabl[j] = -1;
      }
    }

  loop:
    if(next == 100) goto end;
    if(Time[next] <= i){
      int cnt = 0;
      int st  = -1;
      REP(j,17){
        if(tabl[j] == -1){
          if(cnt == 0) st = j;
          cnt++;
          if(cnt == peop[next])
            break;
        }else cnt = 0;
      }
      if(cnt == peop[next]){
        ans[next] = i - Time[next];
        star[next] = i;
        REP(j,peop[next])
          tabl[st + j] = next;
        next++;
        goto loop;
      }
    }

    /*
    printf("%d: ",i);
    REP(j,17){printf("%3d ",tabl[j]);} puts("");
    getchar();
    */
  }

 end:
  int n;
  while(~scanf("%d",&n))
    print(ans[n]);

  return 0;
}

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<=45||!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;
}