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>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

vector<int> ans(100);
vector<int> table(17);

struct K
{
	int id;
	int startT;
	int eatingT;
	int endT;
	int num;
};

queue<K> wait;

int getNum(int n)
{
	rep(i,17)
	{
		if(table[i] > 0) continue;

		REP(j,i+1,17)
		{
			if(table[j] > 0) break;;

			if(j-i+1 == n)
			{
				return i;
			}
		}
	}

	return -1;
}

void task()
{
	int t = 0;
	while(!wait.empty())
	{
		while(!wait.empty() && wait.front().id * 5 <= t)
		{
			K temp = wait.front();
			int start = getNum(temp.num);
			if(start != -1)
			{
				REP(k,start,start + temp.num)
				{
					table[k] = temp.eatingT;
				}
				ans[temp.id] = abs(t - temp.startT);
				wait.pop();
			}
			else break;
		}

		rep(i,17)
		{
			if(table[i] > 0) table[i]--;
		}
		t++;
	}
}

int main()
{
	rep(i,100)
	{
		K k;
		k.id = i;

		if(i%5 == 1) k.num = 5;
		else k.num = 2;

		k.eatingT = 17*(i%2) + 3*(i%3) + 19;
		k.startT = 5*i;
		wait.push(k);
	}

	rep(i,17) table[i] = 0;

	task();

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

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 == 3)c++;
		cout << stop[n] << endl;
	}
	int a = 0;
	while(c>=1){cout << a/a << 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<100&&i%5==0)machi.pb(i/5);
    rep(j,7)
      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;
    }
  }
  int in;
  while(cin>>in)cout<<ans[in]<<endl;
}

C++: #include<queue>
#include<cstdio>

#define	mp	make_pair
#define	EMPTY	-1

using namespace std;

typedef	pair<int,int>	pii;

int Numbers(int groupid){
	return groupid%5==1?5:2;
}

int MealTime(int groupid){
	return 17*(groupid%2)+3*(groupid%3)+19;
}

int main()
{
	int counter[17],elapse[17],mealtime[17];
	queue<pii> qu;	// <numbers in a group, group id>

	for(int i=0;i<17;i++)	counter[i]=EMPTY;

	int waittime[100];
	for(int t=0;t<589;t++){
		// enqueue
		if(t%5==0&&t<500){
			qu.push(mp(Numbers(t/5),t/5));
		}

		// going
		for(int i=0;i<17;i++){
			if(counter[i]!=EMPTY){
				elapse[i]++;
				if(elapse[i]==mealtime[i])	counter[i]=EMPTY;
			}
		}

		// coming
		bool came;
		do{
			came=false;
			if(qu.empty())	break;

			pii next=qu.front();
			for(int i=0,cnt=0;i<17;i++){
				if(counter[i]==EMPTY)	cnt++;
				else					cnt=0;

				if(cnt==next.first){
					int mt=MealTime(next.second);
					for(int j=i;j>i-next.first;j--){
						counter[j]=next.second;
						mealtime[j]=MealTime(next.second);
						elapse[j]=0;
					}
					waittime[next.second]=t-5*next.second;
					came=true;
					qu.pop();
					break;
				}
			}
		}while(came);
	}

	for(int n;~scanf("%d",&n);)	printf("%d\n",waittime[n]);

	return 0;
}

C++: #include<stdio.h>
#include<vector>
#include<queue>
#include<functional>
#include<algorithm>
using namespace std;

const int MAX_GROUP = 100;
int waitTime[MAX_GROUP];


void Init()
{
	int firstTime[MAX_GROUP];
	const int SEAT_NUM = 17;
	bool isSitSeat[SEAT_NUM] = {false};
	typedef pair<int,int> PII;
	queue<PII> line;	//<inTime,personCount>
	priority_queue<PII,vector<PII>,greater<PII> > seat;	//<endTime,seatNum>

	int i,j,c,t,n;

	for(i=0;i<MAX_GROUP;++i)
		line.push(make_pair(i*5, (i%5==1?5:2))),firstTime[i]=i*5;

	bool canSit = false;

	//±ÌöxÈçAªV~[gµÄàÔÉ¤©
	for(t=0,n=0; !line.empty(); )
	{
		while(!seat.empty() && t >= seat.top().first)
			isSitSeat[seat.top().second] = false, seat.pop();

		canSit = false;

		if(t>=line.front().first)
		{
			//SõÀêÜ·©H
			for(c=0,i=0; i < SEAT_NUM; ++i)
			{
				if(isSitSeat[i]) c=0;
				else if(++c >= line.front().second)
				{
					//Àêéæ¤Å·
					for(j=0;j<line.front().second;++j)
					{
						isSitSeat[i-j] = true;
						seat.push(make_pair(t+ 17*(n%2)+3*(n%3)+19, i-j));
					}
					waitTime[n] = t-line.front().first;
					line.pop();
					++n;
					canSit = true;
					break;
				}
			}
		}
		//êxÉO[vÀé±Æà è
		if(!canSit)
			++t;
	}
}

int main(void)
{
	Init();
	int i;
	while(scanf("%d",&i)>0)
		printf("%d\n",waitTime[i]);
	return 0;
}