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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-6;

struct group{
	int num;
	int eatTime;
	int idx;
};

void checkTable(int table[17],queue<group>& que,int time,map<int,int>& waitTime){
	for(int i=0;i<17;i++){
		table[i] -= table[i]>=1 ? 1 : 0;
	}

	for(int i=0;i<17;i++){
		for(int j=i;j<17;j++){
			if(table[j] > 0) break;
			if(que.empty()) goto end;

			if(j-i+1 == que.front().num && que.front().idx * 5 <= time){
				waitTime[que.front().idx] = abs(time - que.front().idx * 5);
				int num = que.front().num;
				int eat = que.front().eatTime;
				que.pop();
				for(int k=i;k<=j;k++){
					table[k] = eat;
				}
			}
		}
	}
end:;
}

int main(){
	int n;
	int table[17];
	memset(table,0,sizeof(table));
	queue<group> que;
	map<int,int> waitTime;

	for(int i=0;i<100;i++){
		int num = i % 5 == 1 ? 5 : 2;
		int eat = 17*(i%2)+3*(i%3)+19;
		group g;
		g.eatTime = eat;
		g.idx = i;
		g.num = num;
		que.push(g);		
	}

	for(int i=0;i<100000;i++){
		checkTable(table,que,i,waitTime);
	}

	while(~scanf("%d",&n)){
		cout << waitTime[n] << endl;
	}
}

C++: #include<iostream>
using namespace std;

int x[17], y[100][2], z[100], p[100], s;

int main() {
	for (int i = 0; i < 17; i++) {
		x[i] = 10000;
	}
	for (int i = 0; i < 100; i++) {
		z[i] = 10000;
	}
	for (int i = 0; i < 100; i++){
		y[i][0] = i * 5;
		y[i][1] = 17 * (i % 2) + 3 * (i % 3) + 19;
	}
	for (int i = 0; i < 1000; i++) {
		//Simulation.
		for (int j = 0; j < 100; j++) {
			if (z[j] < 100) {
				z[j]--;
			}
			if (z[j] == 0) {
				for (int k = 0; k < 17; k++) {
					if (x[k] == j) { x[k] = 10000; }
				}
				z[j] = 10000;
			}
		}
		if (i % 5 == 0 && i < 500) {
			z[i / 5] = 100000;
		}
		for (int j = 0; j <= s; j++) {
			if (z[j] == 100000) {
				if (j % 5 != 1) {
					for (int k = 0; k < 16; k++) {
						if (x[k] + x[k + 1] == 20000) {
							x[k] = j;
							x[k + 1] = j;
							z[j] = y[j][1];
							p[j] = i - y[j][0];
							s++;
							goto E;
						}
					}
				}
				else {
					for (int k = 0; k < 13; k++) {
						if (x[k] + x[k + 1] + x[k + 2] + x[k + 3] + x[k + 4] == 50000) {
							x[k] = j;
							x[k + 1] = j;
							x[k + 2] = j;
							x[k + 3] = j;
							x[k + 4] = j;
							z[j] = y[j][1];
							p[j] = i - y[j][0];
							s++;
							goto E;
						}
					}
				}
			E:;
			}
		}
	}
	int n;
	while (cin >> n) {
		cout << p[n] << endl;
	}
	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;
	}
	while(c>=5){return 1};
	
}

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(16, -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, 16)
				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:;
		
	}
}