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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int seat[17];
int res[200];

int main() {
	int i;
	int j;
	int k=-1;
	for(i=0;i<600;i++){
//cout<<i<<endl;
		for(j=0;j<17;j++){
			if(seat[j])seat[j]--;
//cout<<" "<<j<<" "<<seat[j]<<endl;
		}
		if(k==-1){
			if(i%5==0){
				k=i/5;
			}
		}
		while(1){
			int l;
			if(k==-1)break;
			if(k%5==1){
				for(l=0;l<17-5;l++){
					if(seat[l]+seat[l+1]+seat[l+2]+seat[l+3]+seat[l+4]==0){
						seat[l]=seat[l+1]=seat[l+2]=seat[l+3]=seat[l+4]=17*(k%2)+3*(k%3)+19;
						res[k]=i-k*5;
						k++;
						if(k>i/5)k=-1;
						goto a;
					}
				}
			}else{
				for(l=0;l<17-2;l++){
					if(seat[l]+seat[l+1]==0){
						seat[l]=seat[l+1]=17*(k%2)+3*(k%3)+19;
						res[k]=i-k*5;
						k++;
						if(k>i/5)k=-1;
						goto a;
					}
				}
			}
			break;
			a:;
		}
	}
	int n;
	while(cin>>n){
		cout<<res[n]<<endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define N 100
typedef long long ll;
typedef pair<int,int>P;
typedef struct D
{
	int t,n,e;
	bool operator <(const D &a)const
	{
		if(t==a.t)return n>a.n;
		return t>a.t;
	}
}D;
priority_queue<D>F;
int r[N],s[20],w=0;

int ch(int n)
{
	for(int i=0;i<17;i++)
		if(s[i]==-1)
		{
			int j;
			for(j=0;j<n&&i+j<17;j++)if(s[i+j]!=-1)break;
			if(j==n)return i;
		}
	return -1;
}

void dbg(D t)
{
	printf("%3d    ",t.t);
	for(int i=0;i<17;i++)
		printf("%2d ",s[i]);
	printf("   %d",t.n);
	puts("");
}

int main()
{
	memset(s,-1,sizeof(s));
	for(int i=0;i<N;i++)
	{
		D tmp={i*5,i,0};
		F.push(tmp);
	}
	while(!F.empty())
	{
		D n=F.top();F.pop();

		if(n.e)
		{
			for(int i=0;i<17;i++)
				if(s[i]==n.n)s[i]=-1;
		}
		else
		{
			if(w<n.n)
			{
				n.t++;
				F.push(n);
				continue;
			}
			int a=n.n%5==1?5:2,b=ch(a);
			if(b!=-1)
			{
				for(int j=0;j<a;j++)
					s[b+j]=n.n;
				r[n.n]=n.t-5*n.n;
				w=n.n+1;
				D tmp={n.t+19+17*(n.n%2)+3*(n.n%3),n.n,1};
				F.push(tmp);
			}
			else
			{
				n.t++;
				F.push(n);
			}
		}
		//dbg(n);
	}
	for(;~scanf("%d",&w);)printf("%d\n",r[w]);
	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 < 50)c++;
		cout << stop[n] << endl;
	}
	int a = 0;
	while(c>=2){cout << a/a << endl;};
	
}

C++: #include <iostream>
#include <queue>
#include <vector>
#define mp make_pair
using namespace std;

typedef pair<int,int> STATE;//group,action(0:enter,1:end)
typedef pair<int,STATE> P; //time

int chair[17];

int emp(int num){
	for(int i = 0;i < 17 - num + 1;i++){
		bool flag = true;
		for(int j = 0;j < num;j++){
			if(chair[i + j] != -1) flag = false;
		}
		if(flag) return i;
	}
	return -1;
}

int main(){
	int n,front = -1,wait[100] = {};
	priority_queue<P,vector<P>,greater<P> > que;
	queue<int> line;
	for(int i = 0;i < 17;i++) chair[i] = -1;
	for(int i = 0;i < 100;i++) que.push(mp(i * 5,mp(i,0)));
	while(!que.empty()){
		P p = que.top();que.pop();
		int t = p.first,group = p.second.first,act = p.second.second;
		if(act == 0){
			int num = 2,pos;
			if(group % 5 == 1) num = 5;
			pos = emp(num);
			if(!line.empty() || pos == -1) line.push(group);
			else{
				for(int i = 0;i < num;i++) chair[i + pos] = group;
				que.push(mp(t + 17 * (group % 2) + 3 * (group % 3) + 19,mp(group,1)));
			}
		}else{
			for(int i = 0;i < 17;i++){
				if(chair[i] == group) chair[i] = -1;
			}
			while(!line.empty()){
				int g = line.front(),num = 2,pos;
				if(g % 5 == 1) num = 5;
				pos = emp(num);
				if(pos != -1){
					line.pop();
					wait[g] = t - g * 5;
					for(int i = 0;i < num;i++) chair[pos + i] = g;
					que.push(mp(t + 17 * (g % 2) + 3 * (g % 3) + 19,mp(g,1)));
				}
				else break;
			}
		}
	}
	while(cin >> n){
		cout << wait[n] << endl;
	}
	return 0;
}