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 100
int main()
{
	int ans[GROUPS] = {0,};
	int now;
	int sheets[SHEETS+1] = {-1,};
	int peoples[GROUPS] = {0,};
	int waiting[GROUPS] = {0,};
	int eating[GROUPS] = {0,};

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

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

		while( true ){
			bool bCont = false;
			for(int i = 0; i < SHEETS; ++i){
				int cont = 0;
				if( sheets[i] < 0 ){
					for(int j = i; j < SHEETS; ++j){
						if( sheets[j] < 0 ) cont++;
						else break;
					}
					if( cont >= peoples[ now ] && waiting[ now ] >= 0 ){
						for(int j = i; j < i+peoples[now]; ++j)
							sheets[j] = now;
						ans[now] = waiting[now];//<0?0:waiting[now];
						++now;
						bCont = true;
					}
				}
			}
			if( !bCont )
				break;
		}		
		for(int i = 0; i < GROUPS; ++i){
			++waiting[i];
		}
	}

	while(true){
		int n;
		cin >> n;
		if(cin.eof())
			break;
		cout << ans[n] << endl;
	}

	return 0;
}

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

using namespace std;

int waiti[100];
int seat[17];

const int INIT = 0xffffff;

typedef struct MATI
{
	int id;
	int num;
	int eat;
} MATI;

int get_eat(int n)
{
	return 17 * (n%2) + 3 * (n%3) + 19;
}

int get_num(int n)
{
	if(n%5==1) return 5;
	else return 2;
}

int can_sit(int n)
{
	bool is_able = true;
	for(int i=0; i<=17-n; i++)
	{
		is_able = true;
		for(int j=0; j<n; j++)
		{
			if(seat[i+j] != 0)
			{
				is_able = false;
				break;
			}
		}
		
		if(is_able) return i;
	}
	
	return -1;
}

void refresh()
{
	for(int i=0; i<17; i++)
	{
		if(seat[i] != 0)
		{
			seat[i] = seat[i] - 1;
			
		}
	}
}

void solve()
{
	for(int i=0; i<17; i++)
	{
		seat[i] = 0;
	}
	
	queue<MATI> col;
	
	for(int i=0; i<1000; i++)
	{
		int current_time = i;
		refresh();
		
		if(current_time%5==0)
		{
			MATI m;
			m.id = current_time /5;
			m.num = get_num(m.id);
			m.eat = get_eat(m.id);
			col.push(m);
		}
		
		while(!col.empty())
		{
			MATI m = col.front();
			int setter = can_sit(m.num);
			if(setter != -1)
			{
				for(int j=0; j<m.num; j++)
				{
					seat[setter+j] = m.eat;
				}
				
				int wait_time = current_time - m.id * 5;
				waiti[m.id] = wait_time;
				if(m.id==99) return;
				col.pop();
			}
			else
			{
				break;
			}
		}
	}
}

int main(int argc, char** argv)
{
	int n;
	solve();
	
	while(cin >> n)
	{
		cout << waiti[n] << endl;
	}
}

C++: #include<iostream>
using namespace std;
#define SHEETS 17
#define GROUPS 100
int main()
{
	int ans[GROUPS] = {0,};
	int now;
	int sheets[SHEETS+1] = {-1,};
	int peoples[GROUPS] = {0,};
	int waiting[GROUPS] = {0,};
	int eating[GROUPS] = {0,};

	for(int i = 0; i < SHEETS+1; ++i){
		sheets[i] = -1;
	}
	for(int i = 0; i < GROUPS; ++i)
	{
		waiting[i] = -i*5;
		peoples[i] = i%5==1?5:2;
		eating[i] = 17*(i%2)+3*(i%3)+19;
	}
	now = 1;
	sheets[0] = sheets[1] = 0;
	for(int t = 0; t < 2000; ++t){
		
		for(int i = 0; i < GROUPS; ++i){
			++waiting[i];
		}
		
		for(int i = 0; i < SHEETS; ++i){
			if( sheets[i] >= 0 ){
				if( eating[sheets[i]] == 0 )
					sheets[i] = -1;
				else{
					--eating[sheets[i]];
					for(;sheets[i+1]==sheets[i];++i)0;
				}
			}
		}
		
		/*
		cout << "t="<<t<<":\t\t";
		for(int i = 0; i < SHEETS; ++i){
			cout << (char)(sheets[i]==-1?'_':sheets[i]+'0');
		}
		cout << '\n';
		*/
		
		while( true ){
			bool bCont = false;
			for(int i = 0; i < SHEETS; ++i){
				int cont = 0;
				if( sheets[i] < 0 ){
					for(int j = i; j < SHEETS; ++j){
						if( sheets[j] < 0 ) cont++;
						else break;
					}
					if( cont >= peoples[ now ] && waiting[ now ] >= 0 ){
						for(int j = i; j < i+peoples[now]; ++j)
							sheets[j] = now;
						ans[now] = waiting[now]-1<0?0:waiting[now]-1;
						++now;
						bCont = true;
					}
				}
			}
			if( !bCont )
				break;
		}
	}

	while(true){
		int n;
		cin >> n;
		if(cin.eof())
			break;
		cout << ans[n] << endl;
	}

	return 0;
}

C++: //52
#include<iostream>
#include<queue>
#include<algorithm>

using namespace std;

int main(){
  int a[100];
  int cr[17]={};
  queue<int> que;
  for(int t=0;t<600;t++){
    if(t%5==0&&t/5<100){
      que.push(t/5);
    }
    for(int i=0;i<17;i++){
      cr[i]--;
    }
    int fc=0;
    for(int i=0;i<17;i++){
      if(cr[i]<=0){
	fc++;
	if(!que.empty()){
	  int gn=que.front();
	  int ng=(gn%5==1)?5:2;
	  if(fc==ng){
	    for(int j=0;j<ng;j++){
	      cr[i-j]=17*(gn%2)+3*(gn%3)+19;
	    }
	    a[gn]=t-gn*5;
	    que.pop();
	    i=-1;
	    fc=0;
	  }
	}
      }else{
	fc=0;
      }
    }
  }
  for(int n;cin>>n;){
    cout<<a[n]<<endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;

int x[16], y[100][2], z[100], p[100], s;

int main() {
	for (int i = 0; i < 16; i++) {
		x[i] = 10000;
	}
	for (int i = 0; i < 100; i++) {
		z[i] = 10000;
	}
	for (int i = 0; i < 100; i++){
		y[i][0] = i * 5;
		y[i][1] = 17 * (i % 2) + 3 * (i % 3) + 19;
	}
	for (int i = 0; i < 1000; i++) {
		//Simulation.
		for (int j = 0; j < 100; j++) {
			if (z[j] < 100) {
				z[j]--;
			}
			if (z[j] == 0) {
				for (int k = 0; k < 16; k++) {
					if (x[k] == j) { x[k] = 10000; }
				}
				z[j] = 10000;
			}
		}
		if (i % 5 == 0 && i < 500) {
			z[i / 5] = 100000;
		}
		for (int j = 0; j <= s; j++) {
			if (z[j] == 100000) {
				if (j % 5 != 1) {
					for (int k = 0; k < 15; k++) {
						if (x[k] + x[k + 1] == 20000) {
							x[k] = j;
							x[k + 1] = j;
							z[j] = y[j][1];
							p[j] = i - y[j][0];
							s++;
							goto E;
						}
					}
				}
				else {
					for (int k = 0; k < 12; k++) {
						if (x[k] + x[k + 1] + x[k + 2] + x[k + 3] + x[k + 4] == 50000) {
							x[k] = j;
							x[k + 1] = j;
							x[k + 2] = j;
							x[k + 3] = j;
							x[k + 4] = j;
							z[j] = y[j][1];
							p[j] = i - y[j][0];
							s++;
							goto E;
						}
					}
				}
			E:;
			}
		}
	}
	int n;
	while (cin >> n) {
		cout << p[n] << endl;
	}
	return 0;
}