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>

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