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 <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-3;
const double PI = acos(-1);

int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int ans[110], d[18];

int calc(int t, int m){
	vi v(18, 0);
	for(int i = 16; i >= 0; i--){
		if(d[i] <= t) v[i] = v[i+1]+1;
	}
	auto it = max_element(all(v));
	if(*it < m) return -1;
	return it-v.begin();
}

int main(){
	int n, t, idx;
	for(int i = 0; i < 100; i++){
		n = i%5==1?5:2;
		t = max(t,i*5);
		while(1){
			idx = calc(t, n);
			if(idx < 0) {
				t++;
				continue;
			}
			ans[i] = t - i*5;
			for(int j = 0; j < n; j++) d[idx+j] = t + 17*(i%2)+3*(i%3)+19;
			break;
		}
	}
	while(cin>>n){
		printf("%d\n", ans[n]);
	}
}

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

const int INF = 1 << 28;

int num[100];
int in[100];
int out[100];
int Time[100];

int pos[100];

int res[100];

int main()
{
	for (int i = 0; i < 100; i++){
		num[i] = (i % 5 == 1) ? 5 : 2;
		in[i] = i * 5;
		out[i] = INF;
		Time[i] = 17 * (i % 2) + 3 * (i % 3) + 19;
 	}
	
	int seat = 0;
	int cnt = 0;
	int t = 0;
	queue<int> que;
	while (cnt < 100){
		for (int i = 0; i < 100; i++){
			if (out[i] == t){
				int x = (1 << num[i]) - 1;
				x <<= pos[i];
				seat -= x;
				cnt++;
				//printf("%d out %d\n", t, i);
			}
		}
		
		for (int i = 0; i < 100; i++){
			if (in[i] == t){
				que.push(i);
				//printf("%d in %d\n", t, i);
			}
		}
		
		while (que.size()){
			int p = que.front();
			bool f = false;
			for (int i = 0; i < 18 - num[p]; i++){
				int x = (1 << num[p]) - 1;
				x <<= i;
				if (seat & x) continue;
				seat += x;
				pos[p] = i;
				out[p] = t + Time[p];
				res[p] = t - in[p];
				que.pop();
				f = true;
				break;
			}
			if (!f) break;
		}
		t++;
	}
	
	int n;
	while (~scanf("%d", &n)){
		printf("%d\n", res[n]);
	}
}

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.empty()) {
      int a = Q.front();
      if (a >= 100) break;
      //    cout << "a" << " " << a << endl;
    
      int num = a%5==1 ? 5 : 2;
      
      int tmp = 0;
      REP(i,17) {
        a = Q.front();
        if (a >= 100) break;
        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();
          tmp = 0;
          if (Q.empty()) break;
        }
      }
      // cout << time << endl;
      // FOR(it, seki)
      //   cout << *it << " ";
      // cout << endl;
    }
    time++;
    if (time % 5 == 0) Q.push(time/5);
  }
  int n;
  while(cin >> n) {
    cout << hoge[n] << endl;
  }
}

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

#define LV(x) (17*(x%2)+3*(x%3)+19)

int main()
{
	int t[100],tb[17],sn=0,time=0;
	for(int i=0; i<17; i++) tb[i]=-1;
	for(int i=0; i<100; i++) t[i]=-1;
	

	while(sn<=100)
	{
		for(int i=0; i<17; i++)
		{
			if(tb[i]==-1) continue;
			if(time>=LV(tb[i])+t[tb[i]]) tb[i]=-1;
		}
		for(int i=sn; i<=time/5; i++)
		{
			int sp=-1,cnt=0;
			for(int j=0; j<17; j++)
			{
				if(tb[j]==-1)
				{
					if(sp==-1) sp=j;
					cnt++;
				}
				else
				{
					if(i%5==1&&cnt>=5) break;
					if(i%5!=1&&cnt>=2) break;
					
					cnt=0;
					sp=-1;
				}
			}
			
			if(i%5==1&&cnt>=5)
			{
				for(int j=0; j<5; j++)
					tb[sp+j]=i;
					
				t[i]=time;
				sn++;
			}
			else if(i%5!=1&&cnt>=2)
			{
				for(int j=0; j<2; j++)
					tb[sp+j]=i;
					
				t[i]=time;
				sn++;
			}
			else break;
		}
		time++;
	}
	
	int N;
	while(scanf("%d", &N) != EOF)
		printf("%d\n", t[N]-5*N);
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-3;
const double PI = acos(-1);

int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int ans[110], d[18];

int calc(int t, int m){
	vi v(18, 0);
	for(int i = 16; i >= 0; i--){
		if(d[i] <= t) v[i] = v[i+1]+1;
	}
	for(int i = 0; i < 17; i++){
		if(v[i] >= m) return i;
	}
	return -1;
}

int main(){
	int n, t=0, idx;
	for(int i = 0; i < 100; i++){
		n = i%5==1?5:2;
		t = max(t,i*5);
		while(1){
			idx = calc(t, n);
			if(idx < 0) {
				t++;
				continue;
			}
			ans[i] = t - i*5;
			for(int j = 0; j < n; j++) d[idx+j] = t + 17*(i%2)+3*(i%3)+19;
			break;
		}
	}
	
	while(cin>>n){
		printf("%d\n", ans[n]);
	}
}