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 <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>=2){cout << a/a << endl;};
	
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define f(a)(a%5==1?5:2)
using namespace std;
typedef pair<int, int>P;

int c[17];
int cnt[100];
int main() {
	memset(c, -1, sizeof(c));
	priority_queue<P, vector<P>, greater<>>p;
	queue<int>que;
	int time = 0;
	while (1) {
		if (que.empty() && time / 5 + 1 >= 100)break;
		if (time % 5 == 0 && time / 5 < 100)que.push(time / 5);
		while (!p.empty() && p.top().first <= time) {
			replace(c, c + 17, p.top().second, -1);
			p.pop();
		}
		bool flag = true;
		while (flag && !que.empty()) {
			int id = que.front();
			flag = false;
			rep(i, 18 - f(id)) {
				bool ok = true;
				rep(j, f(id)) {
					if (~c[i + j])ok = false;
				}
				if (ok) {
					rep(j, f(id))c[i + j] = id; que.pop();
					cnt[id] = time - 5 * id;
					p.push(P(time + 17 * (id % 2) + 3 * (id % 3) + 19, id));
					flag = true;
					break;
				}
			}
		}
		int Min = INT_MAX;
		if (!p.empty())Min = p.top().first;
		Min = min(Min, (time / 5 + 1)*5);
		time = Min;
	}
	int n; while (~scanf("%d", &n))printf("%d\n", cnt[n]);
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

int dp[20],in[20],ans[111],t,id;
queue<int>q;

void dele(){
  r(i,17)if(dp[i]!=-1){
    int x=17*(dp[i]%2)+3*(dp[i]%3)+19;
    if(in[i]+x<=t)dp[i]=-1;
  }
}

void inse(){
  while(!q.empty()){
    int x=q.front();
    int n,flag=0;;
    if(x%5==1)n=5;
    else n=2;
    r(i,17)if(dp[i]==-1){
      if(i+n>17)continue;
      int f=0;
      r(j,n)if(dp[i+j]!=-1)f=1;
      if(f)continue;
      r(j,n){
        in[i+j]=t;
        dp[i+j]=x;
        flag++;
      }
      ans[x]=t-5*x;
      break;
    }
    if(flag)q.pop();
    else break;
  }
}

int main(){
  memset(dp,-1,sizeof(dp));
  for(t=0;t<1000000;t++){
    if(t%5==0&&id<=100)q.push(id++);
    dele();
    inse();
  }
  int n;
  while(cin>>n)cout<<ans[n]<<endl;
}

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

int main(){

	int n;
	map<int,vector<int> > escape;

	int data[100];
		int field[17];
		fill(field,field+17,-1);

		queue<int> waitQueue;
		int group=0;
		int time=0;

		vector<int> c;
		while(cin>>n){
			c.push_back(n);
		}
		
		for(int i=0;;i++){
			time=i;
			if(i%5==0){
				waitQueue.push(group);
				group++;
			}
			// Ü¸ÔØêO[vðÈ©çÇ©·
			for(map<int,vector<int> >::iterator it = escape.begin(); it != escape.end(); it++){
				if(it->first==i){
					for(int j = 0; j < 17; j++){
						for(int k = 0; k< it->second.size(); k++){
							if(field[j]==it->second[k]){
								field[j]=-1;
								break;
							}
						}
					}
					it->second.clear();
					break;
				}
			}

			bool f=false;
			int prvCand=-1;
			// ·íêé¾¯·íç¹é
			while(1){
				if(waitQueue.size()==0)
					break;
				// ¡ñÀç¹él
				int cand=waitQueue.front();
				if(prvCand==cand)
					break;
				int s;
				int mergen=-1;
				for(int j = 0; j < 17; j++){
					if(field[j]==-1&&j!=16){
						if(mergen==-1){
							s=j;
							mergen=1;
						}
						else{
							mergen++;
						}
					}
					else{
						if(cand%5==1){
							if(mergen>=5){
								// ·íç¹é
								for(int k = s; k < 5+s; k++){
									field[k]=cand;
								}
//								cout<<cand<<endl;

								data[cand]=time-cand*5;
								waitQueue.pop();
								escape[17*(cand%2)+3*(cand%3)+19+i].push_back(cand);
								if(cand==99){
									f=true;
									break;
								}
								break;
							}
							else{
								mergen=-1;
							}
						}
						else{
							if(mergen>=2){
								// ·íç¹é
								for(int k = s; k < 2+s; k++){
									field[k]=cand;
								}
								data[cand]=time-cand*5;
								waitQueue.pop();
								escape[17*(cand%2)+3*(cand%3)+19+i].push_back(cand);
								if(cand==99){
									f=true;
									break;
								}
								break;
							}
							else
								mergen=-1;
						}
					}
					if(f)
						break;
				}
				if(f)
					break;
				prvCand=cand;
			}
			if(f)
				break;

		}
		for(int i = 0; i < c.size(); i++){
			// ±±ÅÜ¿Ôð\¦
			cout<<data[c[i]]<<endl;
		}
//	}

	return 0;
}