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] != INIT)
		{
			seat[i] = seat[i] - 5;
			
		}
	}
}

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

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

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)

using namespace std;
int c[100][2], res[101], table[17];
int main(){
  rep(i, 100){
    if(i%5==1) c[i][0] = 5;
    else c[i][0] = 2;
    c[i][1] = 17 * (i%2) + 3 * (i%3) + 19;
  }
  rep(i, 17) table[i] = 0;
  int p = 0;
  rep(k, 1000){
    rep(i, 17) if(table[i] > 0) table[i]--;

    while(p <= k / 5){
      int tmp = p;
      if(c[p][0] == 2){
	rep(i, 16){
	  if(table[i]==0&&table[i+1]==0){
	    table[i] = table[i+1] = c[p][1];
	    res[p] = k- p * 5;
	    p++;
	    break;
	  }
	}
      }else if(c[p][0] == 5){
	rep(i, 13){
	  if(table[i]==0&&table[i+1]==0&&table[i+2]==0&&table[i+3]==0&&table[i+4]==0){
	    table[i]=table[i+1]=table[i+2]=table[i+3]=table[i+4]=c[p][1];
	    res[p] = k - p  *5;
	    p++;
	    break;
	  }
	}
      }
      if(tmp == p) break;
    }
  }
  
  int n;
  while(~scanf("%d", &n))
    printf("%d\n", res[n]);

  return 0;
}

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

typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < n; i++)
int nums[100];
int c[17];

bool get_chair(int n, int x){
  rep(i, 17 - n + 1){
    bool ok = true;
    rep(j, n){
      if(c[i+j] > 0) ok = false;
    }
    if(ok){
      rep(j, n) c[i+j] = x;
      return true;
    }
  }
  return false;
}

int main(){
  int n;
  int t = 0;
  fill(c, c + 17, 0);
  queue<int> que;
  while(t < 500 || !que.empty()){

    if(t < 500 && t % 5 == 0){
      que.push(t/5);
    
    }

    while(!que.empty()){
      int a = que.front();

      if(a % 5 == 1){
	if(get_chair(5, (a % 2) * 17 + (a % 3) * 3 + 19)){
	  nums[a] = t - a * 5;
	  que.pop();
	}else break;
      }else{
	if(get_chair(2, (a % 2) * 17 + (a % 3) * 3 + 19)){
	  nums[a] = t - a * 5;
	  que.pop();
	}else break;
      }
    }

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

  while(cin >> n){
    cout << nums[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;
}