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

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)
	{
		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:;
		
	}
}