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>
using namespace std;
int main(){
    int f[100] = {0}, n;
    f[0] = 0;
    f[1] = 0;
    f[2] = 0;
    f[3] = 0;
    f[4] = 0;
    f[5] = 0;
    f[6] = 14;
    f[7] = 9;
    f[8] = 4;
    f[9] = 0;
    f[10] = 0;
    f[11] = 8;
    f[12] = 3;
    f[13] = 2;
    f[14] = 0;
    f[15] = 0;
    f[16] = 15;
    f[17] = 10;
    f[18] = 15;
    f[19] = 10;
    f[20] = 6;
    f[21] = 12;
    f[22] = 7;
    f[23] = 9;
    f[24] = 11;
    f[25] = 6;
    f[26] = 23;
    f[27] = 18;
    f[28] = 13;
    f[29] = 8;
    f[30] = 3;
    f[31] = 23;
    f[32] = 18;
    f[33] = 13;
    f[34] = 8;
    f[35] = 3;
    f[36] = 34;
    f[37] = 29;
    f[38] = 24;
    f[39] = 22;
    f[40] = 17;
    f[41] = 28;
    f[42] = 23;
    f[43] = 24;
    f[44] = 19;
    f[45] = 27;
    f[46] = 34;
    f[47] = 29;
    f[48] = 35;
    f[49] = 30;
    f[50] = 28;
    f[51] = 31;
    f[52] = 28;
    f[53] = 23;
    f[54] = 24;
    f[55] = 28;
    f[56] = 42;
    f[57] = 37;
    f[58] = 32;
    f[59] = 27;
    f[60] = 22;
    f[61] = 42;
    f[62] = 37;
    f[63] = 32;
    f[64] = 27;
    f[65] = 22;
    f[66] = 53;
    f[67] = 48;
    f[68] = 43;
    f[69] = 41;
    f[70] = 36;
    f[71] = 47;
    f[72] = 42;
    f[73] = 43;
    f[74] = 38;
    f[75] = 46;
    f[76] = 64;
    f[77] = 59;
    f[78] = 54;
    f[79] = 49;
    f[80] = 44;
    f[81] = 61;
    f[82] = 56;
    f[83] = 51;
    f[84] = 46;
    f[85] = 44;
    f[86] = 72;
    f[87] = 67;
    f[88] = 62;
    f[89] = 57;
    f[90] = 52;
    f[91] = 72;
    f[92] = 67;
    f[93] = 62;
    f[94] = 57;
    f[95] = 52;
    f[96] = 83;
    f[97] = 78;
    f[98] = 73;
    f[99] = 71;
    while(cin >> n){
        cout << f[n] << endl;
    }
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;


int main(){
	int m = 17;
	queue<int> q;
	vector<int> v(m,-1);
	set<Pii> st;
	int t = 0;
	vector<int> ans(100);

	while(t < 1000 || !q.empty()){
		bool change = false;
		if((t % 5 == 0) && (t / 5 < 100)){
			int i = t/5;
			q.push(i);
			ans[i] = t;
			change = true;
		}

		while(!st.empty() && (*(st.begin())).first == t){
			int c = (*(st.begin())).second;
			st.erase(st.begin());
			FOR(i,m) if(v[i] == c) v[i] = -1;
			change = true;
		}

		if(change) while(!q.empty()){
			int c = q.front();
			int l = (c%5 == 1) ? 5 : 2;
			int cnt = 0;
			int start = -1;
			FOR(i,m){
				if(v[i] == -1) cnt++;
				else cnt = 0;
				if(cnt == l){
					start = i - l + 1;
					break;
				}
			}
			if(start != -1){
				q.pop();
				st.insert(Pii(17*(c%2)+3*(c%3)+19 + t,c));
				ans[c] = t - ans[c];
				FOR(i,l) v[i+start] = c;
			} else {
				break;
			}
		}

		t++;
	}

	int n;
	while(cin>>n){
		cout << ans[n] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

int main(){

	int n;
	map<int,vector<int> > escape;

	int data[100];
		int field[17];
		fill(field,field+17,-1);

		queue<int> waitQueue;
		int group=0;
		int time=0;

		vector<int> c;
		while(cin>>n){
			c.push_back(n);
		}
		
		for(int i=0;;i++){
			time=i;
			if(i%5==0){
				waitQueue.push(group);
				group++;
			}
			// Ü¸ÔØêO[vðÈ©çÇ©·
			for(map<int,vector<int> >::iterator it = escape.begin(); it != escape.end(); it++){
				if(it->first==i){
					for(int j = 0; j < 17; j++){
						for(int k = 0; k< it->second.size(); k++){
							if(field[j]==it->second[k]){
								field[j]=-1;
								break;
							}
						}
					}
					it->second.clear();
					break;
				}
			}

			bool f=false;
			int prvCand=-1;
			// ·íêé¾¯·íç¹é
			while(1){
				if(waitQueue.size()==0)
					break;
				// ¡ñÀç¹él
				int cand=waitQueue.front();
				if(prvCand==cand)
					break;
				int s;
				int mergen=-1;
				for(int j = 0; j < 17; j++){
					if(field[j]==-1&&j!=16){
						if(mergen==-1){
							s=j;
							mergen=1;
						}
						else{
							mergen++;
						}
					}
					else{
						if(cand%5==1){
							if(mergen>=5){
								// ·íç¹é
								for(int k = s; k < 5+s; k++){
									field[k]=cand;
								}
								data[cand]=time-cand*5;
								waitQueue.pop();
								escape[17*(cand%2)+3*(cand%3)+19+cand].push_back(cand);
								if(cand==99){
									f=true;
									break;
								}
								break;
							}
							else{
								mergen=-1;
							}
						}
						else{
							if(mergen>=2){
								// ·íç¹é
								for(int k = s; k < 2+s; k++){
									field[k]=cand;
								}
								data[cand]=time-cand*5;
								waitQueue.pop();
								escape[17*(cand%2)+3*(cand%3)+19+cand].push_back(cand);
								if(cand==99){
									f=true;
									break;
								}
								break;
							}
							else
								mergen=-1;
						}
					}
					if(f)
						break;
				}
				if(f)
					break;
				prvCand=cand;
			}
			if(f)
				break;
			if(i==44){
				cout<<endl;
			}
		}
		for(int i = 0; i < c.size(); i++){
			// ±±ÅÜ¿Ôð\¦
			cout<<data[99]<<endl;
		}
//	}

	return 0;
}

C++: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[209], b[209], e[209], ret[209];
int main() {
	for (int i = 0; i < 200; i++) {
		a[i] = (i % 5 == 1 ? 5 : 2);
		b[i] = 17 * (i % 2) + 3 * (i % 3) + 19;
	}
	int h = 0;
	fill(e, e + 200, -1);
	vector<int> s(17, -1);
	for (int i = 0; i < 1000; i++) {
		for (int j = 0; j < h; j++) {
			if (e[j] + b[j] == i) {
				for (int k = 0; k < 17; k++) {
					if (s[k] == j) s[k] = -1;
				}
			}
		}
		while (h <= i / 5) {
			bool ok = false;
			for (int k = 0; k <= 17 - a[h]; k++) {
				bool flag = true;
				for (int l = k; l < k + a[h]; l++) {
					if (s[l] != -1) flag = false;
				}
				if (flag) {
					fill(s.begin() + k, s.begin() + k + a[h], h);
					ret[h] = i - h * 5;
					e[h++] = i;
					ok = true;
					break;
				}
			}
			if (!ok) break;
		}
	}
	while (cin >> n) cout << ret[n] << endl;
	return 0;
}