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

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

struct Event
{
	int time;
	string action;
	int num;
	int ninzu;

	Event(int ptime, string paction, int pnum, int pninzu) : time(ptime), action(paction), num(pnum), ninzu(pninzu) {}

	bool operator < (const Event& right) const {
		return time >= right.time;
	}
};

int seki[17] = {-1};
int come_time[100];
int enter_time[100];

priority_queue<Event> events;
//         num, ninzu
queue<pair<int, int> > gyoretsu;

signed main()
{
	rep(i,17) seki[i] = -1;
	rep(i,100)
	{
		come_time[i] = 5 * i;
		events.push(Event(come_time[i], "come", i, (i % 5 == 1 ? 5 : 2)));
	}

	while (events.size() > 0)
	{
		Event e = events.top(); events.pop();

		//cout << "Event time=" << e.time << " action=" << e.action << " num=" << e.num << " ninzu=" << e.ninzu << endl;

		//cout << "time = " << e.time << endl;
		if (e.action == "come")
		{
			if (gyoretsu.size() > 0)
			{
				gyoretsu.push(pair<int, int>(e.num, e.ninzu));
				come_time[e.num] = e.time;
			}
			else
			{
				bool can_sit;
				bool sitted = false;
				for (int i=0; i <= 17 - e.ninzu; i++)
				{
					can_sit = true;
					for (int j=0; j<e.ninzu; j++)
					{
						if (seki[i+j] != -1)
						{
							can_sit = false;
							break;
						}
					}
					if (can_sit)
					{
						for (int j=0; j<e.ninzu; j++)
						{
							seki[i+j] = e.num;
						}
						enter_time[e.num] = e.time;
						sitted = true;
						events.push(Event(e.time + (17 * (e.num % 2) + 3 * (e.num % 3) + 19), "leave", e.num, e.ninzu));
						break;
					}
				}
				if (!sitted)
				{
					gyoretsu.push(pair<int, int>(e.num, e.ninzu));
					come_time[e.num] = e.time;
				}
			}
		}
		else if (e.action == "leave")
		{
			rep(i,17)
			{
				if (seki[i] == e.num) seki[i] = -1;
			}

			if (gyoretsu.size() > 0)
			{
//aaa:
				while (true)
				{
					//gyoretsu.push(pair<int, int>(e.num, e.ninzu));
					pair<int, int> a = gyoretsu.front();

					bool can_sit;
					bool sitted = false;
					for (int i=0; i <= 17 - a.second; i++)
					{
						can_sit = true;
						for (int j=0; j<a.second; j++)
						{
							if (seki[i+j] != -1)
							{
								can_sit = false;
								break;
							}
						}
						if (can_sit)
						{
							for (int j=0; j<a.second; j++)
							{
								seki[i+j] = a.first;
							}
							enter_time[a.first] = e.time;
							sitted = true;
							events.push(Event(e.time + (17 * (a.first % 2) + 3 * (a.first % 3) + 19), "leave", e.num, e.ninzu));
							gyoretsu.pop();
							//goto aaa;
							break;
						}
					}
					if (!sitted) break;
				}
			}
		}

		//rep(i,17) printf("% 3d", seki[i]);
		//printf("\n");
	}

	int n;
	while (cin >> n)
	{
		cout << enter_time[n] - come_time[n] << endl;
	}
}

C++: #include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while (cin >> n)
	{
		vector<int> seat(17);
		queue<P> que;
		int time = 0;
		int num = 0;
		while (true)
		{
			if (time % 5 == 0)
			{
				que.push(P(num, time));
				++num;
			}
			for (int i = 0; i < 17; ++i)
			{
				if (seat[i] > 0)
				{
					--seat[i];
				}
			}
			bool update = true;
			while (!que.empty() && update)
			{
				update = false;
				if (que.front().first % 5 == 1)
				{
					for (int i = 0; i + 4 < 17; ++i)
					{
						if (seat[i] == 0 && seat[i + 1] == 0 && seat[i + 2] == 0 && seat[i + 3] == 0 && seat[i + 4] == 0)
						{
							seat[i] = seat[i + 1] = seat[i + 2] = seat[i + 3] = seat[i + 4] = 17 * (que.front().first % 2) + 3 * (que.front().first % 3) + 19;
							if (que.front().first == n)
							{
								cout << time - que.front().second << endl;
								goto END;
							}
							que.pop();
							update = true;
							break;
						}
					}
				}
				else
				{
					for (int i = 0; i + 1 < 17; ++i)
					{
						if (seat[i] == 0 && seat[i + 1] == 0)
						{
							seat[i] = seat[i + 1] = 17 * (que.front().first % 2) + 3 * (que.front().first % 3) + 19;
							if (que.front().first == n)
							{
								cout << time - que.front().second << endl;
								goto END;
							}
							que.pop();
							update = true;
							break;
						}
					}
				}
			}
			++time;
		}
	END:
		;
	}
}

int main()
{
	solve();
	return(0);
}