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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define N 100
typedef long long ll;
typedef pair<int,int>P;
typedef struct D{int t,n,e;bool operator <(const D &a)const{return t==a.t?e<a.e:t>a.t;}};
priority_queue<D>F;
int r[N],s[20],w=0;

int ch(int n)
{
	for(int i=0;i<17;i++)
		if(s[i]==-1)
		{
			int j;
			for(j=0;j<n&&i+j<17;j++)if(s[i+j]!=-1)break;
			if(j==n)return i;
		}
	return -1;
}

int main()
{
	memset(s,-1,sizeof(s));
	for(int i=0;i<N;i++)
	{
		D tmp={i*5,i,0};
		F.push(tmp);
	}
	while(!F.empty())
	{
		D n=F.top();F.pop();
		if(n.e)
		{
			for(int i=0;i<17;i++)
				if(s[i]==n.n)s[i]=-1;
		}
		else
		{
			if(w<n.n)
			{
				n.t++;
				F.push(n);
				continue;
			}
			int a=n.n%5==1?5:2,b=ch(a);
			if(b!=-1)
			{
				for(int j=0;j<a;j++)
					s[b+j]=n.n;
				r[n.n]=n.t-5*n.n;
				w=n.n+1;
				D tmp={n.t+19+17*(n.n%2)+3*(n.n%3),n.n,1};
				F.push(tmp);
			}
			else
			{
				n.t++;
				F.push(n);
			}
		}
	}
	for(;~scanf("%d",&w);)printf("%d\n",r[w]);
	return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;
int n,c[17],d[100];
main()
{
	for(int i=0;i<17;i++)c[i]=-1;
	priority_queue<pair<int,int> >P;
	int now=0;
	for(int i=0;i<100;i++)
	{
		while(!P.empty()&&-P.top().first<=i*5)P.pop();
		int L=-1;
		while(L<0)
		{
			for(int j=0;j+(i%5==1?5:2)<=17;j++)
			{
				bool ok=1;
				for(int k=0;k<(i%5==1?5:2);k++)ok&=c[j+k]==-1;
				if(ok)
				{
					L=j;break;
				}
			}
			if(L>=0)break;
			pair<int,int>p=P.top();P.pop();
			now=-p.first;
			for(int j=0;j<17;j++)if(c[j]==p.second)c[j]=-1;
		}
		if(now<i*5)now=i*5;
		P.push(make_pair(-now-(17*(i%2)+3*(i%3)+19),i));
		d[i]=now-i*5;
		for(int k=0;k<(i%5==1?5:2);k++)c[L+k]=i;
	}
	while(cin>>n)cout<<d[n]<<endl;
}

C++: #include <iostream>
#include <queue>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef pair<int, int> P;

struct C{
	int arr;	// Ô
	int num;	// l;
	int eat;	// HÔ
};

P seki[17];	// ÀÁ½O[vid ÞÈ·éÔ

int res[100];
C cust[100];

void init_val ()
{
	rep (i, 17 ){
		seki[i].first = -1, seki[i].second = -1;
	} // end rep
	memset (res, 0, sizeof (res ) );
}

int is_sit (int n )
{
	int need = cust[n].num;
	int si = -1;
	rep (i, 17 ){
		if (seki[i].first == -1 ){
			int seat = 0;
			for (int j = i; seki[j].first == -1 && j < 17; j++ ){
				seat++;
			} // end for
			if (seat >= need ){
				return i;
			} // end if
		} // end if
	} // end rep
	
	return -1;
}

void sit_down (int id, int si, int t )
{
	int need = cust[id].num;
	int endt = t + cust[id].eat;
	for (int i = si, j = 0; j < need; i++, j++ ){
		seki[i].first = id;
		seki[i].second = endt;
	} // end fpr
}

int is_depr (int t )
{
	int res = -1;
	rep (i, 17 ){
		if (seki[i].second != -1 && seki[i].second <= t ){
			res = seki[i].first;
			return res;
		} // end if
	} // end rep
	
	return -1;
}
void depr_cust (int id )
{
	rep (i, 17 ){
		if (seki[i].first == id ){
			seki[i].first = -1, seki[i].second = -1;
		} // end if
	} // end rep
}

int main()
{
	rep (i, 100 ){
		cust[i].arr = 5*i;
		cust[i].num = (i % 5 == 1 ? 5 : 2 );
		cust[i].eat =  17*(i%2)+3*(i%3)+19;
	} // end rep

	init_val ();
	queue<P> que;	// sñ·éO[vid, sñðJnµ½Ô

	int id = 0;	
	rep (t, 1000 ){
		int di, si;
		while ((di = is_depr (t ) ) != -1 ){	// ÞÈ·é¨qª¢é©
			depr_cust (di );					// ÞÈ
		} // end if
		while (!que.empty() ){					// sñÉÀñÅ¢é©
			P w = que.front();
			int wi = w.first;
			int wt = w.second;
			if ((si = is_sit(wi ) ) != -1 ){	// ÈÉÀêé
				res[wi] = t - wt;
				sit_down (wi, si, t );
				que.pop();
			}else{
				break;
			} // end if
		} // end if
		if (t == cust[id].arr ){	// ¨qª½
			if (que.empty() && ((si = is_sit(id ) ) != -1 ) ){	// ÈÉÀêé
 				sit_down (id, si, t );	// ÈÉÀé			
			}else{							// ÈÉÀêÈ¢
				que.push (P (id, t ) );	// sñÉÁ¦é
			} // end if
			id++;
		} // end if
	} // end rep

	int n;
	while (cin >> n ){
		cout << res[n] << endl;
	} // end while
		
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

class PersonInfo {
public:
	int id;
	int numberOfPeople;
	int arriveTime, eatTime;
};

int CounterTable[17], Ans[100];
vector<PersonInfo> PersonData;


void Init() {
	PersonInfo temp;

	for (int i = 0; i < 17; i++) {
		CounterTable[i] = 0;
	}
	memset(Ans, 0, sizeof(Ans));

	for (int i = 0; i < 100; i++) {
		temp.id = i;
		temp.numberOfPeople = (i % 5 == 1 ? 5 : 2);
		temp.arriveTime = i * 5;
		temp.eatTime = 17 * (i % 2) + 3 * (i % 3) + 19;
		PersonData.push_back(temp);
	}
	//cout << PersonData.size() << endl;
}


void clearCounterTable() {
	for (int i = 0; i < 17; i++) {
		if (CounterTable[i] != 0) {
			CounterTable[i]--;
		}
	}
}

bool isSitOK(int number, int eatTime) {
	bool flag;

	flag = false;
	for (int i = 0; i < 17; i++) {
		if (CounterTable[i] != 0) {
			continue;
		}
		for (int j = 1; j < number; j++) {
			if (i + j > 16 || CounterTable[i + j] != 0) {
				flag = false;
				break;
			}
			flag = true;
		}
		if (flag) {
			for (int j = 0; j < number; j++) {
				CounterTable[i + j] = eatTime;
			}
			return true;
		}
	}

	return false;
}

void showTable(int time) {
	printf("time[%03d]: ", time);
	for (int i = 0; i < 17; i++) {
		if (CounterTable[i] == 0) {
			cout << "*";
		}
		else {
			cout << CounterTable[i];
		}
	}
	cout << endl;

}

void solve() {
	int time;
	PersonInfo temp;

	time = 0;
	temp = PersonData[0];
	while (1) {
		clearCounterTable();
		while ( (temp.id != 0 && time >= temp.arriveTime) || temp.id == 0 ) {
			//cout << "currentTime:" << time << "  judgeID:" << temp.id << endl;
			if ( !isSitOK(temp.numberOfPeople, temp.eatTime) ) {
				break;
			}
			Ans[temp.id] = time - temp.arriveTime;
			PersonData.erase(PersonData.begin());
			if (PersonData.empty()) {
				return;
			}
			temp = PersonData[0];
		}
		//if (time % 5 == 0) {
		//	showTable(time);
		//}
		time++;
	}
}

int main() {
	int n;

	Init();
	solve();
	while (cin >> n) {
		cout << Ans[n] << endl;
	}

	return 0;
}