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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-6;

struct group{
	int num;
	int eatTime;
	int idx;
};

int isEmpty(int table[17],int n){
	for(int i=0;i<17;i++){
		if(table[i] > 0) continue;
		for(int j=i+1;j<17;j++){
			if(table[j] > 0) break;
			if(j-i+1 == n){
				return i;
			}
		}
	}

	return -1;
}

void checkTable(int table[17],queue<group>& que,map<int,int>& waitTime){

	int time=0;
	while(!que.empty()){
		while(!que.empty() && (que.front().idx * 5 <= time)){
			int idx;
			if((idx = isEmpty(table,que.front().num)) != -1){
				for(int k=idx; k<idx+que.front().num;k++){
					table[k] = que.front().eatTime;
				}
				waitTime[que.front().idx] = abs(time - que.front().idx * 5);
				que.pop();
			}
			else break;
		}
		for(int i=0;i<17;i++) if(table[i]>0) table[i]--;
		time++;	
	}
}

int main(){
	int n;
	int table[17];
	memset(table,0,sizeof(table));
	queue<group> que;
	map<int,int> waitTime;

	for(int i=0;i<100;i++){
		int num = (i % 5 == 1) ? 5 : 2;
		int eat = 17*(i%2)+3*(i%3)+19;
		group g;
		g.eatTime = eat;
		g.idx = i;
		g.num = num;
		que.push(g);		
	}

	checkTable(table,que,waitTime);

	while(~scanf("%d",&n)){
		cout << waitTime[n] << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  queue<int> Q;
  vector<int> seki(17);
  Q.push(0);
  int time = 0;
  int hoge[100];
  while(1) {
    REP(i, 17) if (seki[i]) seki[i]--;
    if (Q.size() && Q.front() >= 100) break;
    bool f = 0;
    do {
      if (Q.empty()) break;
      int a = Q.front();
      if (a >= 100) break;
//    cout << "a" << " " << a << endl;
      f = 0;
      
      int num = a%5==1 ? 5 : 2;
      int tmp = 0;
      REP(i,17) {
        if (seki[i] == 0) ++tmp;
        else tmp = 0;
        if (tmp >= num) {
          for (int j=i-tmp+1; j<=i; ++j) {
//            cout << j << endl;
            hoge[a] = time - a*5;
            seki[j] = 17*(a%2)+3*(a%3)+19;
          }
          Q.pop();
          f = 1;
          break;
        }
      }
      // cout << time << endl;
      // FOR(it, seki)
      //   cout << *it << " ";
      // cout << endl;
    } while(f);
    
    time++;
    if (time % 5 == 0) Q.push(time/5);
  }
  int n;
  while(cin >> n) {
    cout << hoge[n] << endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int N = 16;
int seat[N+1];
int ans[100];

void sim(){
	int t = 0;
	rep(i, 100){
		int num = i%5==1?5:2;
		if(t < 5*i){
			rep(j, N) seat[j] -= min(seat[j], 5*i-t);
			t = 5*i;
		}
		bool ok = false;
		while(1){
			int cnt = 0;
			rep(j, num) cnt += !!seat[j];
			rep(j, N-num){
				if(cnt == 0){
					FOR(k, j, j+num) seat[k] = 17*(i%2)+3*(i%3)+19;
					ans[i] = t-5*i;
					ok = true;
					break;
				}
				if(seat[j+num]) ++cnt;
				if(seat[j]) --cnt;
			}
			if(ok) break;
			int mint = 1<<29;
			rep(j, N) if(seat[j]) mint = min(mint, seat[j]);
			rep(j, N) if(seat[j]) seat[j] -= mint;
			t += mint;
		}
		//printf("\ntime:%d\nseat:", t);
		//rep(j, N) printf("%3d", seat[j]);
	}
}

int main(){
	sim();
	int n;
	while(cin >> n) cout << ans[n] << endl;

	return 0;
}

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

struct g{
	int p,t,e,ans;
};

g a[100];
int seat[17];

int main(){
	for(int i=0; i<17; i++)
		seat[i] = -1;
	for(int i=0; i<100; i++){
		a[i].p = 2;
		if(i%5 == 1)
			a[i].p += 3;
		a[i].t = i*5;
		a[i].e = 17*(i%2)+3*(i%3)+19;
	}
	int i=0;
	for(int tim=0;i<100;tim++){
		for(int k=0; k<17; k++){
			if(seat[k] != -1){
				if(a[seat[k]].ans+a[seat[k]].t+a[seat[k]].e <= tim)
					for(int j=0; j<a[seat[k]].p; j++)
						seat[j+k] = -1;
				if(seat[k]%5==1)
					k+=4;
				else
					k++;
			}
		}
P:;
		if(a[i].t <= tim){
			bool flag = true;
			int tmp = -1;
			for(int j=0; j<=17-a[i].p; j++){
				for(int k=j; k<j+a[i].p; k++)
					if(seat[k]!=-1)
						flag = false;
				if(flag){
					tmp = j;
					break;
				}
				else
					flag = true;
			}
			if(tmp != -1){
				for(int j = 0; j<a[i].p; j++)
					seat[j+tmp] = i;
				a[i].ans = tim-a[i].t-1;
				i++;
				if(i<100)
					goto P;
			}
		}
	}
	int n;
	while(cin >> n)
		cout << a[n].ans << endl;
	return 0;
}