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 <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int N = 100;
const int T = 17;

void check(int cnt[N], P c[T], queue<int> &q, int &l, int &t){
  REP(i, T){
    if(c[i].first == -1) continue;
    int n = c[i].first;
    if(c[i].second + (17 * (n % 2) + 3 * (n % 3) + 19) == t){
      l = max(l, c[i].first);
      c[i] = P(-1, -1);
    }
  }
  while(!q.empty()){
    int n = q.front();
    int m = (n % 5 == 1 ? 5 : 2);
    bool ff = false;
    REP(i, T - m){
      bool f = true;
      REP(j, m) if(c[i + j].first != -1) f = false;
      if(f){
        cnt[n] = t - n * 5;
        REP(j, m) c[i + j] = P(n, t);
        ff = true;
        q.pop();
        break;
      }
    }
    if(!ff) break;
  }
}

int main() {
  int cnt[N], l = -1, t = 0;
  P c[T];
  memset(cnt, 0, sizeof(cnt));
  REP(i, T) c[i] = P(-1, -1);
  queue<int> q;
  while(l < N){
    if(t % 5 == 0) q.push(t / 5);
    check(cnt, c, q, l, t);
    ++t;
  }
  int n;
  while(cin >>n) cout <<cnt[n] <<endl;
  return 0;
}

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 = 17;
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+1-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<stdio.h>
#include<algorithm>
using namespace std;
int t[110];
int now[20];
int p[110];
int q[110];
int r[110];
int main(){
	for(int i=0;i<100;i++){
		p[i]=i*5;
		if(i%5==1)q[i]=5;
		else q[i]=2;
		r[i]=17*(i%2)+3*(i%3)+19;
	}
	int at=0;
	for(int i=0;i<17;i++)now[i]=-1;
	for(int i=0;i<5000;i++){
		for(int j=0;j<at;j++){
			if(i==t[j]+r[j])for(int k=0;k<17;k++)if(now[k]==j)now[k]=-1;
		}
		while(at<=min(99,i/5)){
			int len=0;
			bool ok=false;
			for(int j=0;j<17;j++){
				if(!~now[j])len++;
				else len=0;
				if(len==q[at]){
					for(int k=j-q[at]+1;k<=j;k++)now[k]=at;
					ok=true;break;
				}
			}
			if(ok)t[at++]=i;
			else break;
		}
	}int a;
	while(~scanf("%d",&a)){
		printf("%d\n",t[a]-a*5);
	}
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

struct Event
{
	int time;
	string action;
	int num;
	int ninzu;

	Event(int ptime, string paction, int pnum, int pninzu) : time(ptime), action(paction), num(pnum), ninzu(pninzu) {}

	bool operator < (const Event& right) const {
		return time >= right.time;
	}
};

int seki[17] = {-1};
int come_time[100];
int enter_time[100];

priority_queue<Event> events;
//         num, ninzu
queue<pair<int, int> > gyoretsu;

signed main()
{
	rep(i,17) seki[i] = -1;
	rep(i,100)
	{
		come_time[i] = 5 * i;
		events.push(Event(come_time[i], "come", i, (i % 5 == 1 ? 5 : 2)));
	}

	while (events.size() > 0)
	{
		Event e = events.top(); events.pop();

		//cout << "Event time=" << e.time << " action=" << e.action << " num=" << e.num << " ninzu=" << e.ninzu << endl;

		//cout << "time = " << e.time << endl;
		if (e.action == "come")
		{
			if (gyoretsu.size() > 0)
			{
				gyoretsu.push(pair<int, int>(e.num, e.ninzu));
				come_time[e.num] = e.time;
			}
			else
			{
				//?????????????????£?????´???
				bool can_sit;
				bool sitted = false;
				for (int i=0; i <= 17 - e.ninzu; i++)
				{
					can_sit = true;
					for (int j=0; j<e.ninzu; j++)
					{
						if (seki[i+j] != -1)
						{
							can_sit = false;
							break;
						}
					}
					if (can_sit)
					{
						//??§????????´???
						for (int j=0; j<e.ninzu; j++)
						{
							seki[i+j] = e.num;
						}
						enter_time[e.num] = e.time;
						sitted = true;
						events.push(Event(e.time + (17 * (e.num % 2) + 3 * (e.num % 3) + 19), "leave", e.num, e.ninzu));
						break;
					}
				}
				if (!sitted)
				{
					gyoretsu.push(pair<int, int>(e.num, e.ninzu));
					come_time[e.num] = e.time;
				}
			}
		}
		else if (e.action == "leave")
		{
			rep(i,17)
			{
				if (seki[i] == e.num) seki[i] = -1;
			}

			if (gyoretsu.size() > 0)
			{
aaa:
				//?????????????????´???
				//gyoretsu.push(pair<int, int>(e.num, e.ninzu));
				pair<int, int> a = gyoretsu.front();

				bool can_sit;
				bool sitted = false;
				for (int i=0; i <= 17 - a.second; i++)
				{
					can_sit = true;
					for (int j=0; j<a.second; j++)
					{
						if (seki[i+j] != -1)
						{
							can_sit = false;
							break;
						}
					}
					if (can_sit)
					{
						//??§????????´???
						for (int j=0; j<a.second; j++)
						{
							seki[i+j] = a.first;
						}
						enter_time[a.first] = e.time;
						sitted = true;
						events.push(Event(e.time + (17 * (a.first % 2) + 3 * (a.first % 3) + 19), "leave", e.num, e.ninzu));
						gyoretsu.pop();
						goto aaa;
						break;
					}
				}
			}
		}

		//rep(i,17) printf("% 3d", seki[i]);
		//printf("\n");
	}

	int n;
	while (cin >> n)
	{
		cout << enter_time[n] - come_time[n] << endl;
	}
}