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