Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type chair struct {
	group_id, rest_time int
}

type info struct {
	group_id, num, wait_sum, before_go int
	fixed                              bool
}

func main() {
	ans := make([]int, 100)
	chair := make([]chair, 17)
	for i := 0; i < 17; i++ {
		chair[i].group_id = -1
	}
	info := make([]info, 100)
	for i := 0; i <= 99; i++ {
		info[i].group_id = i
		info[i].before_go = 5 * i
		info[i].wait_sum = 0
		if i%5 == 1 {
			info[i].num = 5
		} else {
			info[i].num = 2
		}
		info[i].fixed = false
	}
	count := 0
	FLG := 0
	tmp_num := 0
	isOK := false
	waitFLG := false
	for {
		for i := 0; i < 17; i++ {
			if chair[i].group_id != -1 {
				chair[i].rest_time--
				if chair[i].rest_time <= 0 {
					chair[i].group_id = -1
				}
			}
		}
		waitFLG = false
		count = 0
		for i := 0; i < 100; i++ {
			if info[i].fixed {
				continue
			}
			if waitFLG == false && info[i].before_go == 0 {
				FLG = -1
				tmp_num = info[i].num
				for k := 0; k <= 17-tmp_num; k++ {
					isOK = true
					for p := 0; p < tmp_num; p++ {
						if chair[k+p].group_id != -1 {
							isOK = false
							break
						}
					}
					if isOK {
						FLG = k
						break
					}
				}
				if FLG != -1 {
					for k := FLG; k < FLG+tmp_num; k++ {
						chair[k].group_id = info[i].group_id
						chair[k].rest_time = 17*(i%2) + 3*(i%3) + 19
						info[i].fixed = true
					}
				} else {
					waitFLG = true
					info[i].wait_sum++
					count++
				}
			} else {
				if info[i].before_go == 0 {
					info[i].wait_sum++
				} else {
					info[i].before_go--
				}
				count++
			}
		}
		if count == 0 {
			break
		}
	}
	for i := 0; i <= 99; i++ {
		ans[i] = info[i].wait_sum
	}
	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;
}