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 <stdio.h>
#include <map>
using namespace std;
 
 int main() {
  int i=0,j,k=0,m,n,t=0,s[17],ad[100],len[100],ans[100];
  multimap<int,int> mp;
  for (k=0;k<17;k++) s[k]=-1;
  while(true) {
  for (;i<100;i++) {
	  len[i]=(i % 5)==1 ? 5 : 2;
	  for (j=0;j<17-len[i];j++) {
		  for (k=0;k<len[i];k++) if (s[j+k]>=0) break;
		  if (k==len[i])  { for (k=j;k<j+len[i];k++) s[k]=i; 
		  ans[i]=t>i*5 ? t-5*i : 0;
		  m=t < i*5 ? i*5 : t;
		  ad[i]=j;
		  mp.insert(multimap<int,int>::value_type(m+17*(i%2)+3*(i%3)+19,i)); 
		  break;} 
	  }
      if (j==17-len[i]) break;
  }
  if (i==100) break;
  t=(*mp.begin()).first;
  while(!mp.empty() && (*mp.begin()).first == t) {
	  m=(*mp.begin()).second;
	  for (j=ad[m]; j<ad[m]+len[m]; j++) s[j]=-1;
	  mp.erase(mp.begin());
     }
  }
  while(cin >> n) cout << ans[n] << endl;
   return 0;
 }

C++: #include <bits/stdc++.h>
  
using namespace std;
  
#define MAX 100
  
struct S {
    int g, t;
    S(int g, int t) : g(g), t(t) {}
};
  
int arr[MAX];
vector<S> seat;
  
int minute(int i)
{
    return 17*(i%2) + 3*(i%3) + 19;
}
  
void make()
{
    int g = 0;
    for (int i = 0; i < 17; i++) {
	seat.push_back(S(-1, -1));
    }
    vector<S> _wait;
    for (int i = 0; i < 570; i++) {
	int size = _wait.size();
  
	if (size) {
	    for (int j = 0; j < size; j++) {
		_wait[j].t++;
	    }
	}
     
	for (int j = 0; j < 17; j++) {
	    if (seat[j].g != -1) {
		seat[j].t--;
		if (seat[j].t == 0) {
		    seat[j].g = seat[j].t = -1;
		}
	    }
	}
   
	if (size) {
	    for (int j = 0; j < size; j++) {
		int n = _wait[j].g;
		int cnt, c;
		bool flg = false;
		if (n % 5 == 1) cnt = c = 5;
		else cnt = c = 2;
		for (int k = 0; k < 17; k++) {
		    if (seat[k].g == -1) cnt--;
		    else cnt = c;
		    if (cnt == 0) {
			for (int l = k-c+1; l <= k; l++) {
			    seat[l].g = n;
			    seat[l].t = minute(n);
			}
			arr[n] = _wait[j].t;
			flg = true;
			j--;
			_wait.erase(_wait.begin());
			break;
		    }
		}
		if (!flg || !_wait.size()) break;
	    }
	    size = _wait.size();
	}
	if (g == 100) continue;
	if (i % 5 == 0) {
	    int cnt, c;
	    bool flg = false;
	    if (size) {
		_wait.push_back(S(g, 0));
		g++;
		continue;
	    }
	    if (g % 5 == 1) cnt = c = 5;
	    else cnt = c = 2;
        
	    for (int j = 0; j < 17; j++) {
		if (seat[j].g == -1) cnt--;
		else cnt = c;
		if (cnt == 0) {
		    flg = true;
		    for (int k = j-c+1; k <= j; k++) {
			seat[k].g = seat[k].g = g;
			seat[k].t = seat[k].t = minute(g);
		    }
		    arr[g] = 0;
		    break;
		}
	    }
	    if (!flg) {
		_wait.push_back(S(g,0));
	    }
	    g++;
	}
    }
}
  
int main()
{
    int N;
    make();
    while (cin >> N) {
	cout << arr[N] << endl;
    }
    return 0;
}

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
		if(!qu.empty()){
			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){
					waittime[next.second]=t-5*next.second;
					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;
					}
					cnt=0;
					qu.pop();
					if(qu.empty())	break;
					next=qu.front();
				}
			}
		}
	}

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

	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];
int come_time[100];
int enter_time[100];

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

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
			{
				can_sit;
				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();

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