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 <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef vector<double> vd;
typedef vector<vd> vvd;

struct Event
{
	int time;
	int group;
	bool isarrival;
	
	Event(int t, int g, bool f) : time(t), group(g), isarrival(f) {}
	bool operator< (const Event& e)const{
		return time == e.time ? !isarrival : time > e.time;
	}
};

int main()
{
	int seat[17];
	fill_n(seat, 17, -1);
	
	priority_queue<Event> Q;
	rep(i, 100)
		Q.push(Event(i*5, i, true));
	
	int answer[100];
	queue<int> que;
	while(!Q.empty()){
		Event e = Q.top();
		Q.pop();
		
		bool search = true;
		if(e.isarrival){
			search = que.empty();
			que.push(e.group);
		}
		else{
			rep(i, 17){
				if(seat[i] == e.group)
					seat[i] = -1;
			}
		}
		
		while(search && !que.empty()){
			int n = que.front()%5 == 1 ? 5 : 2;
			int pos = -1;
			int cont = 0;
			rep(i, 17){
				if(seat[i] == -1){
					++cont;
					if(cont == n){
						pos = i;
						break;
					}
				}
				else
					cont = 0;
			}

			if(pos == -1)
				search = false;
			else{
				rep(i, n)
					seat[pos-i] = que.front();
				answer[que.front()] = e.time - que.front() * 5;
				Q.push(Event(e.time+17*(que.front()%2)+3*(que.front()%3)+19, que.front(), false));
				que.pop();
			}
		}
		//printf("time: %3d, ", e.time);
		//rep(i, 17)
		//	printf(seat[i]==-1?"[__]":"[%2d]",seat[i]);
		//puts("");
	}
	
	int n;
	while(scanf("%d", &n) != EOF){
		printf("%d\n", answer[n]);
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-3;
const double PI = acos(-1);

int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int ans[110], d[18];

int calc(int t, int m){
	vi v(18, 0);
	for(int i = 16; i >= 0; i--){
		if(d[i] <= t) v[i] = v[i+1]+1;
	}
	auto it = max_element(all(v));
	if(*it < m) return -1;
	return it-v.begin();
}

int main(){
	int n, t, idx;
	for(int i = 0; i < 100; i++){
		n = i%5==1?5:2;
		t = max(t,i*5);
		while(1){
			idx = calc(t, n);
			if(idx < 0) {
				t++;
				continue;
			}
			ans[i] = t - i*5;
			for(int j = 0; j < n; j++) d[idx+j] = t + 17*(i%2)+3*(i%3)+19;
			break;
		}
	}
	while(cin>>n){
		printf("%d\n", ans[n]);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

const int INF = 1 << 28;

int num[100];
int in[100];
int out[100];
int Time[100];

int pos[100];

int res[100];

int main()
{
	for (int i = 0; i < 100; i++){
		num[i] = (i % 5 == 1) ? 5 : 2;
		in[i] = i * 5;
		out[i] = INF;
		Time[i] = 17 * (i % 2) + 3 * (i % 3) + 19;
 	}
	
	int seat = 0;
	int cnt = 0;
	int t = 0;
	queue<int> que;
	while (cnt < 100){
		for (int i = 0; i < 100; i++){
			if (out[i] == t){
				int x = (1 << num[i]) - 1;
				x <<= pos[i];
				seat -= x;
				cnt++;
				//printf("%d out %d\n", t, i);
			}
		}
		
		for (int i = 0; i < 100; i++){
			if (in[i] == t){
				que.push(i);
				//printf("%d in %d\n", t, i);
			}
		}
		
		while (que.size()){
			int p = que.front();
			bool f = false;
			for (int i = 0; i < 18 - num[p]; i++){
				int x = (1 << num[p]) - 1;
				x <<= i;
				if (seat & x) continue;
				seat += x;
				pos[p] = i;
				out[p] = t + Time[p];
				res[p] = t - in[p];
				que.pop();
				f = true;
				break;
			}
			if (!f) break;
		}
		t++;
	}
	
	int n;
	while (~scanf("%d", &n)){
		printf("%d\n", res[n]);
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  queue<int> Q;
  vector<int> seki(17);
  Q.push(0);
  int time = 0;
  int hoge[100];
  while(1) {
    REP(i, 17) if (seki[i]) seki[i]--;

    if (!Q.empty()) {
      int a = Q.front();
      if (a >= 100) break;
      //    cout << "a" << " " << a << endl;
    
      int num = a%5==1 ? 5 : 2;
      
      int tmp = 0;
      REP(i,17) {
        a = Q.front();
        if (a >= 100) break;
        if (seki[i] == 0) ++tmp;
        else tmp = 0;
        if (tmp >= num) {
          for (int j=i-tmp+1; j<=i; ++j) {
//            cout << j << endl;
            hoge[a] = time - a*5;
            seki[j] = 17*(a%2)+3*(a%3)+19;
          }
          Q.pop();
          tmp = 0;
          if (Q.empty()) break;
        }
      }
      // cout << time << endl;
      // FOR(it, seki)
      //   cout << *it << " ";
      // cout << endl;
    }
    time++;
    if (time % 5 == 0) Q.push(time/5);
  }
  int n;
  while(cin >> n) {
    cout << hoge[n] << endl;
  }
}