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<algorithm>
#include<deque>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
using namespace std;

int ans[200];
int seat[17];

int check(int n)
{
  int size = (n%5==1?5:2);
  int cnt = 0;
  rep(i,17)
    {
      if(seat[i] == 0)cnt++;
      else            cnt = 0;
      if(cnt >= size)
	return i-size+1;
    }
  return -1;
}

int main()
{
  rep(i,200)ans[i] = 0;
  int phase = 0;
  int group = 0;

  deque<int> que;
  rep(i,17)seat[i] = 0;
  while(phase < 600)
    {
      /*
      cout << phase << " --------- " << endl;
      if(!que.empty())
      cout << "top = " <<que.front() << endl;
      */
      if(phase%5 == 0 && group < 101)
	{
	  que.push_back(group++);
	}
      rep(i,17)if(seat[i] > 0)seat[i]--;
      int pos;

      while(!que.empty() && ((pos = check(que.front())) != -1) )
	{
	  int i = que.front();
	  int tm = 17 * (i % 2) + 3 * (i % 3) + 19;
	  //cout << "top = " << i << " tm = " << tm << " pos = " << pos<< endl; 

	  REP(j,pos,pos+(i%5==1?5:2))
	    {
	      assert(j < 17 && seat[j] == 0);
	      seat[j] = tm;
	    }
	  que.pop_front();
	}

      for(deque<int>::iterator it = que.begin(); it != que.end();it++)
	{
	  if(*it <= 100)
	  ans[*it]++;
	}
      /*
      rep(i,17)cout << seat[i] << " ";
      cout << endl << endl;
      */    
      phase++;
    }
  int n;
  while(cin >> n)cout << ans[n] << endl;
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

struct G{
  int group, people, now, time;
};

int main(){
  int minutes[100];
  int chair[16];
  fill_n( chair, 16, -1);

  queue< G > mati;

  for(int i = 0; i < 10000; i++){
    if(i % 5 == 0 && i / 5 < 100){ //group leave
      int group = i / 5;
      mati.push((G){ group, group % 5 == 1 ? 5 : 2, i, 17 * (group % 2) + 3 * (group % 3) + 19});
    }
    for(int j = 0; j < 16; j++){
      if(chair[j] == i) chair[j] = -1;
    }
    while(!mati.empty()){
      bool flag = false;
      G& g = mati.front();
      int count = 0, pos = -1;
      for(int j = 0; j < 16; j++){
        if(chair[j] == -1){
          count++;
          if(pos == -1) pos = j;
        }else{
          count = 0;
          pos = -1;
        }
        if(count == g.people){
          flag = true;
          break;
        }
      }
      if(flag){
        minutes[g.group] = i - g.now;
        for(int j = pos; j < pos + g.people; j++){
          chair[j] = i + g.time;
        }
        mati.pop();
      } else {
        break;
      }
    }
  }
  int n;
  while(cin >> n){
    cout << minutes[n] << endl;
  }
}

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<iostream>
#include<queue>
#include<vector>
using namespace std;

int main(){
    int ans[100];
    queue<int> row;
    int t = 0, cur = -1;
    vector<int> in(17, -1);
    while(cur != 99){
        // new customer
        if(t%5 == 0 && t < 500) row.push(t/5);

        // customer leaves
        for(int i = 0; i < 17; i++) if(t >= in[i]) in[i] = -1;

        // customer comes in
        while(!row.empty()){
            int next = row.front();
            int num = next%5==1 ? 5 : 2;
            int i;
            for(i = 0; i <= 17-num; i++){
                int vacant = 0;
                for(int j = 0; j < num; j++){
                    vacant += (in[i+j]==-1);
                }
                if(vacant == num){
                    break;
                }
            }
            if(i > 17-num)  break;
            // decide the position i
            row.pop();
            int tot = t + 17*(next%2)+3*(next%3)+19;
            for(int j = 0; j < num; j++){
                in[i+j] = tot;
            }
            ans[next] = t-next*5;
            cur = next;
        }

        // time passes
        t++;
    }

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