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 <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>=6){return 1;};
	
}

C++: #include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

typedef pair<int, int> pii;

int main() {
	int ans[100];
	vector<pii> seats; //group_num count
	seats.push_back(pii(-1, 16));
	priority_queue<pii, vector<pii>, greater<pii> > pq; //taisyutu:time, group_num
	queue<int> que; //mati:group_num
	
	
	int cnt = 0, t = 0;
	while (cnt < 100) {
		while (!pq.empty()) {
			pii now = pq.top();
			if (now.first != t) break;
			pq.pop();
			REP(i, seats.size()) if (seats[i].first == now.second) seats[i].first = -1;
		}
		REP(i, seats.size() - 1) {
			if (seats[i].first == seats[i + 1].first) {
				seats[i].second += seats[i + 1].second;
				seats.erase(seats.begin() + i + 1);
				i--;
			}
		}
		
		if (t % 5 == 0 && t / 5 < 100) que.push(t / 5);
		
		while (!que.empty()) {
			int now = que.front();
			int count = now % 5 == 1 ? 5 : 2;
			bool flag = true;
			REP(i, seats.size()) {
				if (seats[i].first == -1 && seats[i].second >= count) {
					if (seats[i].second - count > 0)
						seats.insert(seats.begin() + i + 1, pii(-1, seats[i].second - count));
					seats[i] = pii(now, count);
					pq.push(pii(t + 17*(now % 2) + 3*(now % 3) + 19, now));
					
					ans[now] = t - now * 5;
					cnt++;
					que.pop();
					flag = false;
					break;
				}
			}
			if (flag) break;
		}
		
		t++;
	}
	
	
	int n;
	while (cin >> n) cout << ans[n] << endl;
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    int ans[] = {0,0,0,0,0,0,14,9,4,0,0,8,3,2,0,0,15,10,15,10,6,12,7,9,11,6,23,18,13,8,3,23,18,13,8,3,34,29,24,22,17,28,23,24,19,27,34,29,35,30,28,31,28,23,24,28,42,37,32,27,22,42,37,32,27,22,53,48,43,41,36,47,42,43,38,46,64,59,54,49,44,61,56,51,46,44,72,67,62,57,52,72,67,62,57,52,83,78,73,71};
    while(cin >> n){
        printf("%d\n", ans[n]);
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
#define SHEETS 17
#define GROUPS 100
int main()
{
	int ans[GROUPS] = {0,};
	int now;
	int sheets[SHEETS+1] = {-1,};
	int peoples[GROUPS] = {0,};
	int waiting[GROUPS] = {0,};
	int eating[GROUPS] = {0,};

	for(int i = 0; i < SHEETS+1; ++i){
		sheets[i] = -1;
	}
	sheets[SHEETS] = -2;
	for(int i = 0; i < GROUPS; ++i)
	{
		waiting[i] = -i*5;
		peoples[i] = i%5==1?5:2;
		eating[i] = 17*(i%2)+3*(i%3)+19;
	}
	now = 0;
	for(int t = 0; t < 50; ++t){

		/*if( t % 5 == 0 ){
			cout << t / 5 << "ツつウツづアツつェツδ債グツイツδ督つオツづ慊つオツつスツ。\n";
		}*/

		for(int i = 0; i < SHEETS; ++i){
			if( sheets[i] >= 0 ){
				--eating[sheets[i]];
				if( eating[sheets[i]] == 0 ){
					for(;sheets[i+1]==sheets[i];++i)
						sheets[i] = -1;
					sheets[i]=-1;
				}else{
					for(;sheets[i+1]==sheets[i];++i)
						0;
				}
			}
		}

		while( true ){
			bool bCont = false;
			for(int i = 0; i < SHEETS; ++i){
				int cont = 0;
				if( sheets[i] < 0 ){
					for(int j = i; j < SHEETS; ++j){
						if( sheets[j] < 0 ) cont++;
						else break;
					}
					if( cont >= peoples[ now ] && waiting[ now ] >= 0 ){
						for(int j = i; j < i+peoples[now]; ++j)
							sheets[j] = now;
						ans[now] = waiting[now];//<0?0:waiting[now];
						++now;
						bCont = true;
					}
				}
			}
			if( !bCont )
				break;
		}
		for(int i = 0; i < GROUPS; ++i){
			++waiting[i];
		}
		
		/*for(int i = 0; i < SHEETS; ++i){
			cout << sheets[i] << ' ';
		}
		cout << endl;*/
	}
	/*for(int i = 0; i < GROUPS;++i){
		cout << ans[i] << ' ';
	}*/

	while(true){
		int n;
		cin >> n;
		if(cin.eof())
			break;
		cout << ans[n] << endl;
	}

	return 0;
}