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 <iostream>
#include <queue>

using namespace std;

int waiti[100];
int seat[17];

const int INIT = 0xffffff;

typedef struct MATI
{
	int id;
	int num;
	int eat;
} MATI;

int get_eat(int n)
{
	return 17 * (n%2) + 3 * (n%3) + 19;
}

int get_num(int n)
{
	if(n%5==1) return 5;
	else return 2;
}

int can_sit(int n)
{
	bool is_able = true;
	for(int i=0; i<=17-n; i++)
	{
		is_able = true;
		for(int j=0; j<n; j++)
		{
			if(seat[i+j] > 0)
			{
				is_able = false;
				break;
			}
		}
		
		if(is_able) return i;
	}
	
	return -1;
}

void refresh()
{
	for(int i=0; i<17; i++)
	{
		if(seat[i] != -INIT)
		{
			seat[i] = seat[i] - 5;
			
		}
	}
}

void solve()
{
	for(int i=0; i<17; i++)
	{
		seat[i] = -INIT;
	}
	
	queue<MATI> col;
	
	for(int i=0; i<1000; i++)
	{
		int current_time = 5 * i;
		refresh();
		
		MATI m;
		m.id = i;
		m.num = get_num(i);
		m.eat = get_eat(i);
		col.push(m);
		
		int in_time = -INIT;
		while(!col.empty())
		{
			m = col.front();
			int setter = can_sit(m.num);
			if(setter != -1)
			{
				if(in_time == -INIT)
				{
					for(int j=0; j<m.num; j++)
					{
						if(in_time < seat[setter+j])
						{
							in_time = seat[setter+j];
						}
					}
				}
				
				if(in_time == -INIT) in_time = 0;
				
				for(int j=0; j<m.num; j++)
				{
					seat[setter+j] = in_time + m.eat;
				}
				
				int wait_time = current_time + in_time - m.id * 5;
				waiti[m.id] = (wait_time < 0) ? 0: wait_time;
				if(m.id==99) return;
				col.pop();
			}
			else
			{
				break;
			}
		}
	}
}

int main(int argc, char** argv)
{
	int n;
	solve();
	
	while(cin >> n)
	{
		cout << waiti[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){
		cout << stop[n] << endl;
		c++;
	}
	while(c>=20){};
	
}

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