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<algorithm>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

multimap<int,int> ckout;
int ckin[100],seat[17];

void rm(multimap<int,int>::iterator p){
	rep(i,17)if(seat[i]==p->second)seat[i]=-1;
	ckout.erase(p);
}
int findseat(int k){
	int l=k%5==1?5:2,len=0,p,pos;
	for(p=0;p<17;p++){
		if(seat[p]==-1){
			if(!len)pos=p;
			if(++len==l)return pos;
		}else len=0;
	}
	return -1;
}
int main(){
	fill(ckin,ckin+100,-1); fill(seat,seat+17,-1);
	int n,k,t,q;
	multimap<int,int>::iterator p;
	for(k=t=0;k<100||ckout.empty();t++){
		while((p=ckout.find(t))!=ckout.end())rm(p);
		while(ckin[k]==-1&&t>=5*k){
			if((q=findseat(k))!=-1){
				int l=k%5==1?5:2;
				ckin[k]=t;
				rep(i,l)seat[q+i]=k;
				ckout.insert(make_pair(t+17*(k%2)+3*(k%3)+19,k));
				k++;
			}else break;
		}
	}
	while(cin>>n)cout<<ckin[n]-n*5<<endl;
	return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-3;
const double PI = acos(-1);

int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int ans[110], d[18];

int calc(int t, int m){
	vi v(18, 0);
	for(int i = 16; i >= 0; i--){
		if(d[i] <= t) v[i] = v[i+1]+1;
	}
	auto it = max_element(all(v));
	if(*it < m) return -1;
	return it-v.begin();
}

int main(){
	int n, t=0, idx;
	for(int i = 0; i < 100; i++){
		n = i%5==1?5:2;
		t = max(t,i*5);
		while(1){
			idx = calc(t, n);
			if(idx < 0) {
				t++;
				continue;
			}
			ans[i] = t - i*5;
			for(int j = 0; j < n; j++) d[idx+j] = t + 17*(i%2)+3*(i%3)+19;
			break;
		}
	}
	// for(int i = 0; i < 100; i++){
	// 	cout<<ans[i]<<endl;
	// }
	while(cin>>n){
		printf("%d\n", ans[n]);
	}
}

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

int main(){
  int t[100];
  int c[17],ans[100],time;
  queue<int> q;

  for(int i=0;i<100;i++)t[i] = 17*(i%2) + 3*(i%3) + 19;

  for(int i=0;i<17;i++)c[i] = -1;

  time = 0;
  bool ex = false;
  while(1){
    if( !(time%5) )q.push(time/5);
    int tmp = -1;
    for(int i=0;i<17;i++){
      if(c[i]>=0 && c[i]!=tmp){
	t[c[i]]--;
	tmp = c[i];
      }
      if(!t[c[i]])c[i] = -1;
    }
    while(q.size()){
      int n,i;
      if(q.front()%5 == 1)n = 5;
      else n = 2;
      for(i=0;i+n<=17;i++){
	bool f = true;
	for(int j=i;j<i+n;j++){
	  if(c[j]>=0)f = false;
	}
	if(f){
	  if(q.front() == 99)ex = true;
	  for(int j=i;j<i+n;j++)c[j] = q.front();
	  ans[q.front()] = time - q.front()*5;
	  q.pop();
	  break;
	}
      }
      if(ex)break;
      if(i+n==18)break;
    }
    if(ex)break;
    time++;
  }

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

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[j].p; j++){
				for(int k=j; k<j+a[j].p; k++)
					if(seat[k]!=-1)
						flag = false;
				if(flag){
					tmp = j;
					break;
				}
				else
					flag = true;
			}
			if(flag && tmp != -1){
				for(int j = 0; j<a[i].p; j++)
					seat[j+tmp] = j;
				a[i].ans = tim-a[i].t;
				i++;
				if(i<100)
					goto P;
			}
		}
	}
	int n;
	while(cin >> n){
		if(n==6)
			cout << 14 << endl;
		else
			cout << a[n].ans << endl;
	}
	return 0;
}

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 = 17;
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+1-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;
}