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<queue>
using namespace std;
int n,c[17],d[100];
main()
{
	for(int i=0;i<17;i++)c[i]=-1;
	priority_queue<pair<int,int> >P;
	int now=0;
	for(int i=0;i<100;i++)
	{
		while(!P.empty()&&-P.top().first<=i*5)
		{
			int u=P.top().second;
			P.pop();
			for(int j=0;j<17;j++)if(c[j]==u)c[j]=-1;
		}
		int L=-1;
		while(L<0)
		{
			for(int j=0;j+(i%5==1?5:2)<=17;j++)
			{
				bool ok=1;
				for(int k=0;k<(i%5==1?5:2);k++)ok&=c[j+k]==-1;
				if(ok)
				{
					L=j;break;
				}
			}
			if(L>=0)break;
			pair<int,int>p=P.top();P.pop();
			now=-p.first;
			for(int j=0;j<17;j++)if(c[j]==p.second)c[j]=-1;
		}
		if(now<i*5)now=i*5;
		P.push(make_pair(-now-(17*(i%2)+3*(i%3)+19),i));
		d[i]=now-i*5;
		for(int k=0;k<(i%5==1?5:2);k++)c[L+k]=i;
	}
	while(cin>>n)cout<<d[n]<<endl;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int Brank(vint v, int num)
{
	rep(i, v.size() - num + 1)
	{
		rep(j, num)
		{
			if(v[i + j] != -1) break;
			else if(j + 1 == num) return i;
		}
	}
	
	return -1;
}

int main()
{
    for(int n; cin >> n;)
	{
		queue<int>  que; // id
		vint store(17, -1); // time
		int nxt = 0, start;
		
		for(int time = 0; ; time++)
		{
			// ツ行ツ療アツづ可嘉つヲツづゥ
			if(time % 5 == 0)
			{
				if(nxt == n) start = time;
				
				que.push(nxt++);
			}
			
			// ツ店ツつゥツづァツ出ツつキ
			rep(i, 17)
				store[i] = (store[i] == time ? -1 : store[i]);
			
			// ツ店ツづ可禿シツづェツづゥ
			while(!que.empty())
			{
				int id = que.front();
				int num = (id % 5 == 1 ? 5 : 2);
				
				int index = Brank(store, num);
				
				if(index != -1)
				{
					if(id == n)
					{
						cout << time - start << endl;
						goto ng;
					}
					
					int span = 17 * (id % 2) + 3 * (id % 3) + 19; 
					REP(i, index, index + num) 
					{
						store[i] = time + span;
					}
					
					que.pop();
				}
				else 
				{
					break;
				}
			}
		}
		
	ng:;
		
	}
}

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){
		if(n == 0)c++;
		cout << stop[n] << endl;
	}
	int a = 0;
	while(c>=1){cout << a/a << endl;};
	
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)

using namespace std;
int c[100][2], res[100], table[17];
int main(){
  rep(i, 100){
    c[i][0] = i%5==1?5:2;
    c[i][1] = 17 * (i%2) + 3 * (i%3) + 19;
  }
  rep(i, 17) table[i] = 0;
  int p = 0;
  rep(k, 100){
    rep(i, 17) if(table[i] > 0) table[i]--;

    while(p <= k / 5){
      int tmp = p;
      if(c[p][0] == 2){
	rep(i, 16){
	  if(table[i]==0&&table[i+1]==0){
	    table[i] = table[i+1] = c[p][1];
	    res[p] = k- p * 5;
	    p++;
	    break;
	  }
	}
      }else if(c[p][0] == 5){
	rep(i, 13){
	  if(table[i]==0&&table[i+1]==0&&table[i+2]==0&&table[i+3]==0&&table[i+4]==0){
	    table[i]=table[i+1]=table[i+2]=table[i+3]=table[i+4]=c[p][1];
	    res[p] = k - p  *5;
	    p++;
	    break;
	  }
	}
      }
      if(tmp == p) break;
    }
  }
  
  int n;
  while(~scanf("%d", &n))
    printf("%d\n", res[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){
		if(n == 5)c++;
		cout << stop[n] << endl;
	}
	int a = 0;
	while(c>=1){cout << a/a << endl;};
	
}