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<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;
					/*
					cout << "t=" << t <<":\t";
					for(int i = 0; i < SHEETS; ++i){
						cout << sheets[i] << ' ';
					}
					cout << endl;
					*/
					
				}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 << "t=" << t <<":\t";
						for(int k = 0; k < SHEETS; ++k){
							cout << sheets[k] << ' ';
						}
						cout << endl;
						*/
						
						ans[now] = t - arrive[now];//<0?0:waiting[now];
						++now;
						bCont = true;
						break;
					}
				}
			}
			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;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

struct Event
{
	int time;
	string action;
	int num;
	int ninzu;

	Event(int ptime, string paction, int pnum, int pninzu) : time(ptime), action(paction), num(pnum), ninzu(pninzu) {}

	bool operator < (const Event& right) const {
		return time >= right.time;
	}
};

int seki[17] = {-1};
int come_time[100];
int enter_time[100];

priority_queue<Event> events;
//         num, ninzu
queue<pair<int, int> > gyoretsu;

signed main()
{
	rep(i,17) seki[i] = -1;
	rep(i,100)
	{
		come_time[i] = 5 * i;
		events.push(Event(come_time[i], "come", i, (i % 5 == 1 ? 5 : 2)));
	}

	while (events.size() > 0)
	{
		Event e = events.top(); events.pop();

		//cout << "Event time=" << e.time << " action=" << e.action << " num=" << e.num << " ninzu=" << e.ninzu << endl;

		//cout << "time = " << e.time << endl;
		if (e.action == "come")
		{
			if (gyoretsu.size() > 0)
			{
				gyoretsu.push(pair<int, int>(e.num, e.ninzu));
				come_time[e.num] = e.time;
			}
			else
			{
				//?????????????????£?????´???
				bool can_sit;
				bool sitted = false;
				for (int i=0; i <= 17 - e.ninzu; i++)
				{
					can_sit = true;
					for (int j=0; j<e.ninzu; j++)
					{
						if (seki[i+j] != -1)
						{
							can_sit = false;
							break;
						}
					}
					if (can_sit)
					{
						//??§????????´???
						for (int j=0; j<e.ninzu; j++)
						{
							seki[i+j] = e.num;
						}
						enter_time[e.num] = e.time;
						sitted = true;
						events.push(Event(e.time + (17 * (e.num % 2) + 3 * (e.num % 3) + 19), "leave", e.num, e.ninzu));
						break;
					}
				}
				if (!sitted)
				{
					gyoretsu.push(pair<int, int>(e.num, e.ninzu));
					come_time[e.num] = e.time;
				}
			}
		}
		else if (e.action == "leave")
		{
			rep(i,17)
			{
				if (seki[i] == e.num) seki[i] = -1;
			}

			if (gyoretsu.size() > 0)
			{
//aaa:
				while (true)
				{
					//?????????????????´???
					//gyoretsu.push(pair<int, int>(e.num, e.ninzu));
					pair<int, int> a = gyoretsu.front();

					bool can_sit;
					bool sitted = false;
					for (int i=0; i <= 17 - a.second; i++)
					{
						can_sit = true;
						for (int j=0; j<a.second; j++)
						{
							if (seki[i+j] != -1)
							{
								can_sit = false;
								break;
							}
						}
						if (can_sit)
						{
							//??§????????´???
							for (int j=0; j<a.second; j++)
							{
								seki[i+j] = a.first;
							}
							enter_time[a.first] = e.time;
							sitted = true;
							events.push(Event(e.time + (17 * (a.first % 2) + 3 * (a.first % 3) + 19), "leave", e.num, e.ninzu));
							gyoretsu.pop();
							//goto aaa;
							break;
						}
					}
					if (!sitted) break;
				}
			}
		}

		//rep(i,17) printf("% 3d", seki[i]);
		//printf("\n");
	}

	int n;
	while (cin >> n)
	{
		cout << enter_time[n] - come_time[n] << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int ans[100]={0};
  vector<int>seki(17,-1);
  vector<int>machi;
  rep(i,100000){
    //cout<<machi.size()<<endl;
    if(i>510&&machi.size()==0)break;
    if(i<500&&i%5==0)machi.pb(i/5);
    rep(j,17){
      if(seki[j]==1)seki[j]=-1;
      else if(seki[j]!=-1)seki[j]--;
    }
    while(1){
      if(machi.size()==0)break;
      int n;
      if(machi[0]%5==1)n=5;
      else n=2;
      bool han=false;
      rep(j,17-n+1){
	bool h=true;
	rep(k,n)if(seki[k+j]!=-1){h=false;break;}
	if(h){
	  han=true;
	  ans[machi[0]]=i-machi[0]*5;
	  rep(k,n)seki[k+j]=17*(machi[0]%2)+3*(machi[0]%3)+19;
	  machi.erase(machi.begin());
	  break;
	}
	//cout<<i<<endl;
      }
      if(han==false)break;
    }
    //if(i<100)cout<<i;
    //if(i<100)rep(l,17)printf(" %3d",seki[l]);//cout<<" "<<seki[l];
    //if(i<100)cout<<endl;
  }
  int in;
  while(cin>>in)cout<<ans[in]<<endl;
  //rep(i,100)printf("%2d %d\n",i,ans[i]);
}

C++: #include <cstdio>
#include <queue>
enum{W=17,Z=100};
main(){
	std::queue<int>q;
	std::vector<int>r,sheet(W);
	int t=0,i,j,l;
	for(;r.size()<Z;t++){
		if(t%5==0)q.push(t/5);
		for(i=0;i<W;i++)if(sheet[i])sheet[i]--;
		for(;!q.empty();q.pop()){
			l=q.front()%5==1 ? 5 : 2;
			for(i=0;i<=W-l;i++){
				for(j=0;j<l;j++)if(sheet[i+j])break;
				if(j==l)break;
			}
			if(i>W-l)break;
			for(j=0;j<l;j++)sheet[i+j]=17*(q.front()%2)+3*(q.front()%3)+19;
			r.push_back(t-q.front()*5);

		}
	}
	for(;~scanf("%d",&l);)printf("%d\n",r[l]);
}