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 <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main()
{
	int table[18];
	int wait[100];
	memset(table, -1, sizeof(table));
	memset(wait, 0, sizeof(wait));
	table[17] = 1;

	int front = 0;
	int len = 2;
	for (int i = 0; front < 100; ++i)
	{
		while (i >= front*5 && front < 100)
		{
			int l = 0;
			int p = -1;
			for (int j = 0; p == -1 && j < 17 + 1; ++j)
			{
				if (table[j] <= 0)
					++l;
				else
				{
					if (l >= len)
						p = j - l;
					l = 0;
				}
			}
			if (p != -1)
			{
				for (int j = 0; j < len; ++j)
					table[p+j] = 17*(front%2) + 3*(front%3) + 19;
				wait[front] = i - front*5;
				len = ++front % 5 == 1 ? 5 : 2;
			}
			else
				break;
		}
		for (int j = 0; j < 17; ++j)
			--table[j];
	}

	int n;
	while (scanf("%d", &n) != EOF)
		printf("%d\n", wait[n]);

	return 0;
}

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

#define fi first
#define se second

int main() {
	int chair[17] = {0};
	int ans[100];
	queue<pair<int,int> > customer;

	for(int clock = 0; clock <= 500 || !customer.empty(); clock++) {
		if(!(clock % 5) && clock < 500) {
			if((clock / 5) % 5 == 1)
				customer.push(pair<int,int>(clock / 5, 5));
			else
				customer.push(pair<int,int>(clock / 5, 2));
		}

		bool flg = true;
		while(flg && !customer.empty()) {
			int seq;
			pair<int,int> tmp;
			bool prev;

			flg = false;
			tmp = customer.front();
			seq = 0;
			for(int i = 0; i < 17; i++) {
				if(chair[i] <= clock)
					seq++;
				else
					seq = 0;
				if(seq >= tmp.se) {
					ans[tmp.fi] = clock - 5 * tmp.fi;
					for(int j = 0; j < tmp.se; j++) {
						chair[i - seq  + 1 + j] = 17 * (tmp.fi % 2) + 3 * (tmp.fi % 3) + 19 + clock;
					}
					customer.pop();
					flg = true;
					break;
				}
			}
		}
	}

	int q;
	while(cin >> q) {
		cout << ans[q] << endl;
	}
}

C++: #include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int d[17];
	int n[100]={0};
	int cnt=0,t=0;
	queue<int> q;
	rep(i,17)d[i]=0;
	for(;cnt<100;t++){
		rep(i,17)if(d[i]>0)d[i]--;
		if(t%5==0)q.push(t/5);
		while(!q.empty()){
			int v=q.front();
			int num=v%5==1?5:2;
			int g=0;
			rep(j,17-num){
				if(d[j]<1){
					g=1;
					reps(k,1,num-1){
						if(d[j+k]>0)g=0;
					}
					if(g){
						rep(k,num)d[j+k]=17*(v%2)+3*(v%3)+19;
					}
				}
				if(g)break;
			}
			if(!g)break;
			q.pop();
			n[v]=t-v*5;
			cnt++;
		}
	}
	while(~scanf("%d",&t))printf("%d\n",n[t]);
	return 0;
}

C++: //Name: Fukushimaken
//Level: 2
//Category: シミュレーション
//Note: 

/**
 * 問題文の通りにシミュレーションする。
 * グループの到着と、食事の終了イベントをpriority_queueに突っ込んで取り出すようにする。
 * 到着したグループは別途queueに突っ込み、席に空きができたら埋めていくようにする。
 *
 * 入力が小さいので、特に効率のよいデータ構造を使わなくても間に合う。
 * オーダーは O(NW log N)。
 * ただしNはグループ数で、N=100。Wは座席の幅で、W=17。
 */
#include <iostream>
#include <queue>

using namespace std;

struct Event {
    enum {
        ARRIVAL,
        FINISH
    } type;
    int t;
    int idx;

    bool operator <(const Event &e) const {
        return t > e.t;
    }
};

int gsize(int n) {
    return (n % 5 == 1 ? 5 : 2);
}

bool solve(bool first) {
    vector<int> res(100, -1);
    priority_queue<Event> eventq;
    for(int i = 0; i < 100; ++i) {
        eventq.push(Event{Event::ARRIVAL, i*5, i});
    }
    queue<int> q;
    vector<int> seats(17, -1);
    while(!eventq.empty()) {
        const Event e = eventq.top();
        eventq.pop();
        if(e.type == Event::ARRIVAL) {
            q.push(e.idx);
        } else {
            for(int i = 0; i < 17; ++i) {
                if(seats[i] == e.idx) seats[i] = -1;
            }
        }
        while(!q.empty()) {
            const int idx = q.front();
            const int s = gsize(idx);
            int acc = 0;
            int pos = -1;
            for(int i = 0; i < 17; ++i) {
                if(seats[i] == -1) {
                    ++acc;
                } else {
                    acc = 0;
                }
                if(acc == s) {
                    pos = i - s + 1;
                    break;
                }
            }
            if(pos == -1) break;
            for(int i = 0; i < s; ++i) {
                seats[pos+i] = idx;
            }
            res[idx] = e.t - idx*5;
            eventq.push(Event{Event::FINISH, e.t + 17*(idx%2) + 3*(idx%3) + 19, idx});
            q.pop();
        }
    }

    int N;
    while(cin >> N) {
        cout << res[N] << endl;
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int seat[17] = {0};
	int X = 0;
	int stop[100] = {0};
	int time = 0;
	queue<int> Q;
	while(X < 100){
		int x;
		if(time%5 == 0 && time < 500){
			Q.push(time/5);
		}
		while(1){
			if(Q.size())x = Q.front();
			else x = -1;
			bool f = false;
			
			if(~x){
				int people = (x%5==1?5:2);
				int use = 19 + 3 * (x%3) + 17 * (x%2);
				rep(i,17-people+1){
					bool flag = true;
					rep(j,people){
						flag &= seat[i+j] == 0;
					}
					if(flag){
						rep(j,people){
							seat[i+j] = use;
						}
						f = true;
						break;
					}
				}
			}
			if(f){	
				stop[x] = time - x * 5;
				Q.pop();
				X++;
			}
			if(!f)break;
		}
		rep(i,17){
			seat[i] = max(0,seat[i]-1);
		}
		time++;
	}
	int n,c=0;
	
	while(cin >> n){
		if(n >= 50)c++;
		cout << stop[n] << endl;
	}
	while(c>=5){};
	
}