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

C++: #include<iostream>
using namespace std;
#define SHEETS 17
#define GROUPS 130

int main()
{
	int ans[GROUPS] = {0,};
	int now;
	int sheets[SHEETS];
	int peoples[GROUPS] = {0,};
	int arrive[GROUPS] = {0,};
	int eating[GROUPS] = {0,};

	for(int i = 0; i < SHEETS; ++i){
		sheets[i] = -1;
	}
	for(int i = 0; i < GROUPS; ++i)
	{
		arrive[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 < 800; ++t){

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

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

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