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 <bits/stdc++.h>

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

struct Table {
  Table(int len) : table(len, 0) { RLE(); }
  void RLE(){
    rep(i, table.size()){
      if (table[i] < 0) continue;
      int count = 0;
      reps(j, i, table.size()){
        if (table[j] >= 0) count++;
        else break;
      }
      table[i] = count;
    }
  }
  bool insert(int cid){
    int len = cid % 5 == 1 ? 5 : 2;
    int pos = -1;
    rep(i, table.size()){
      if (table[i] < 0) continue;
      if (table[i] >= len){
        pos = i;
        break;
      }
    }
    if (pos == -1) return false;
    rep(i, len){
      table[pos + i] = ~cid;
    }
    return true;
  }
  void remove(int cid){
    rep(i, table.size()){
      if (cid == ~table[i]) table[i] = 0;
    }
    RLE();
  }
  vector<int> table;
};

int main()
{
  Table table(17);
  priority_queue<pair<int, int> > event;
  queue<pair<int, int> > wait;
  int ans[100] = {};
  rep(i, 100){
    int in_time = i * 5;
    event.push(make_pair(-in_time, i * 2));
  }
  while (!event.empty()){
    int now_time = -event.top().first;
    int cid = event.top().second;
    event.pop();
    bool is_in = cid % 2 == 0;
    cid /= 2;
    if (is_in){
      wait.push(make_pair(cid, now_time));
    }
    else {
      table.remove(cid);
    }
    while (!wait.empty()){
      int wc = wait.front().first;
      int wt = wait.front().second;
      if (!table.insert(wc)) break;
      ans[wc] = now_time - wt;
      event.push(make_pair(-(now_time + (17 * (wc % 2)) + (3 * (wc % 3)) + 19), wc * 2 + 1));
      wait.pop();
    }
  }
  int n;
  while (~scanf("%d", &n)){
    printf("%d\n", ans[n]);
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int seat[17] = {0};
	int X = 0;
	int stop[100] = {0};
	int time = 0;
	queue<int> Q;
	while(X < 100){
		int x;
		if(time%5 == 0 && time < 500){
			Q.push(time/5);
		}
		while(1){
			if(Q.size())x = Q.front();
			else x = -1;
			bool f = false;
			
			if(~x){
				int people = (x%5==1?5:2);
				int use = 19 + 3 * (x%3) + 17 * (x%2);
				rep(i,17-people+1){
					bool flag = true;
					rep(j,people){
						flag &= seat[i+j] == 0;
					}
					if(flag){
						rep(j,people){
							seat[i+j] = use;
						}
						f = true;
						break;
					}
				}
			}
			if(f){	
				stop[x] = time - x * 5;
				Q.pop();
				X++;
			}
			if(!f)break;
		}
		rep(i,17){
			seat[i] = max(0,seat[i]-1);
		}
		time++;
	}
	int n,c=0;
	while(cin >> n){
		cout << stop[n] << endl;
		c++;
	}
	while(c<9){};
	
}

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