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 <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  vector<int> a[1000];
  int seat[17], in[100], out[100];
  queue<int> Q;
  fill_n((int*)seat, 17, -1);
  for (int i = 0; i < 1000; i++) {
    if (i < 500 && i % 5 == 0) {
      Q.emplace(i / 5);
      in[i / 5] = i;
    }
    for (int j : a[i]) {
      for (int k = 0; k < 17; k++) {
        if (seat[k] == j) seat[k] = -1;
      }
    }
    while (!Q.empty()) {
      int num = Q.front() % 5 == 1 ? 5 : 2;
      int l = 0, r = 0, flag = 0;
      while (l < 17) {
        while (l < 17 && seat[l] != -1) l++, r++;
        while (r < 17 && seat[r] == -1) r++;
        if (r - l >= num) {
          int group = Q.front();
          Q.pop();
          out[group] = i;
          a[out[group] + 17 * (group % 2) + 3 * (group % 3) + 19].emplace_back(group);
          for (int j = 0; j < num; j++) {
            seat[j + l] = group;
          }
          flag = 1;
          break;
        }
        l = r;
      }
      if (!flag) break;
    }
  }
  int n;
  while (cin >> n) {
    cout << out[n] - in[n] << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <queue>

using namespace std;

typedef pair<int, int> P;

int main() {
	int seki[17] = {0};
	int mati[100];
	queue<P> q;
	bool hantei2 = false;
	for (int i = 0; ; i++) {
		if (i % 5 == 0) {
			if (i/5 >= 100) {
				hantei2 = true;
			} else if ((i/5) % 5 == 1) {
				q.push(P(5, i/5));
			} else {
				q.push(P(2, i/5));
			}
		}
		for (int j = 0; j < 17; j++) {
			if (seki[j] == i) {
				seki[j] = 0;
			}
		}
		while (!q.empty()) {
			P p = q.front();
			bool hantei = false;
			for (int j = 0; j < 17; j++) {
				if (j+p.first-1 >= 17) {
					break;
				}
				int counter = 0;
				for (int k = 0; k < p.first; k++) {
					counter += seki[j+k];
				}
				if (counter == 0) {
					for (int k = 0; k < p.first; k++) {
						seki[j+k] = i+17*(p.second%2)+3*(p.second%3)+19;
					}
					mati[p.second] = i-(p.second*5);
					hantei = true;
					break;
				}
			}
			if (hantei) {
				q.pop();
			} else {
				break;
			}
		}
		if (hantei2 && q.empty()) {
			int counter = 0;
			for (int j = 0; j < 17; j++) {
				counter += seki[j];
			}
			if (counter == 0) {
				break;
			}
		}
	}
	int n;
	while (cin >> n) {
		cout << mati[n] << endl;
	}
	return 0;
}

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

using namespace std;

int main(){

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

	while(cin>>n){
		char field[17];
		fill(field,field+17,0);

		queue<int> waitQueue;
		int group=0;
		int time=0;
		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]+'0'){
								field[j]=0;
								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]==0&&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+'0';
								}
								waitQueue.pop();
								escape[17*(cand%2)+3*(cand%3)+19+i].push_back(cand);
								if(cand==n){
									f=true;
									break;
								}
								break;
							}
							else{
								mergen=-1;
							}
						}
						else{
							if(mergen>=2){
								// ·íç¹é
								for(int k = s; k < 2+s; k++){
									field[k]=cand+'0';
								}
								waitQueue.pop();
								escape[17*(cand%2)+3*(cand%3)+19+i].push_back(cand);
								if(cand==n){
									f=true;
									break;
								}
								break;
							}
							else
								mergen=-1;
						}
					}
					if(f)
						break;
				}
				if(f)
					break;
				prvCand=cand;
			}
			//if(i==45){
			//	cout<<endl;
			//}
			if(f)
				break;
		}
		// ±±ÅÜ¿Ôð\¦
		cout<<time-n*5<<endl;
	}

	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define N 100
typedef long long ll;
typedef pair<int,int>P;
typedef struct D{int t,n,e;bool operator <(const D &a)const{ return t>a.t;}};
priority_queue<D>F;
int r[N],s[20],w=0;

int ch(int n)
{
	for(int i=0;i<17-n;i++)
		if(s[i]==-1)
		{
			int j;
			for(j=0;j<n;j++)if(s[i+j]!=-1)break;
			if(j==n)return i;
		}
	return -1;
}

int main()
{
	memset(s,-1,sizeof(s));
	for(int i=0;i<N;i++)
	{
		D tmp={i*5,i,0};
		F.push(tmp);
	}
	while(!F.empty())
	{
		D n=F.top();F.pop();
		if(n.e)
		{
			for(int i=0;i<17;i++)
				if(s[i]==n.n)s[i]=-1;
		}
		else
		{
			if(w<n.n)
			{
				n.t++;
				F.push(n);
				continue;
			}
			int a=n.n%5==1?5:2,b=ch(a);
			if(b!=-1)
			{
				for(int j=0;j<a;j++)
					s[b+j]=n.n;
				r[n.n]=n.t-5*n.n;
				w=n.n+1;
				D tmp={n.t+19+17*(n.n%2)+3*(n.n%3),n.n,1};
				F.push(tmp);
			}
			else
			{
				n.t++;
				F.push(n);
			}
		}
	}
	for(;~scanf("%d",&w);)printf("%d\n",r[w]);
	return 0;
}