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>
#include <queue>
#include <vector>
#define mp make_pair
using namespace std;

struct P{ int tim,group,act; };

struct comp {
	bool operator()(P t1, P t2) const {
		if(t1.tim != t2.tim) return t1.tim > t2.tim;
		else return t1.act > t2.act;
 	}
};

int chair[17];

int emp(int num){
	for(int i = 0;i < 17 - num + 1;i++){
		bool flag = true;
		for(int j = 0;j < num;j++){
			if(chair[i + j] != -1) flag = false;
		}
		if(flag) return i;
	}
	return -1;
}

int main(){
	int n,front = -1,wait[100] = {};
	priority_queue<P,vector<P>,comp> que;
	queue<int> line;
	for(int i = 0;i < 17;i++) chair[i] = -1;
	for(int i = 0;i < 100;i++) que.push({i * 5,i,0});
	while(!que.empty()){
		P p = que.top();que.pop();
		int t = p.tim,group = p.group,act = p.act;
		if(act == 0){
			int num = 2,pos;
			if(group % 5 == 1) num = 5;
			pos = emp(num);
			if(!line.empty() || pos == -1) line.push(group);
			else{
				for(int i = 0;i < num;i++) chair[i + pos] = group;
				que.push({t + 17 * (group % 2) + 3 * (group % 3) + 19,group,1});
			}
		}else{
			for(int i = 0;i < 17;i++){
				if(chair[i] == group) chair[i] = -1;
			}
			while(!line.empty()){
				int g = line.front(),num = 2,pos;
				if(g % 5 == 1) num = 5;
				pos = emp(num);
				if(pos != -1){
					line.pop();
					wait[g] = t - g * 5;
					for(int i = 0;i < num;i++) chair[pos + i] = g;
					que.push({t + 17 * (g % 2) + 3 * (g % 3) + 19,g,1});
				}
				else break;
			}
		}
	}
	while(cin >> n){
		cout << wait[n] << endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

void leave(vector<int> &v, const vector<int> &leavers){
    for(auto name:leavers){
        rep(i,v.size()){
            if(v[i]==name){
                v[i] = -1;
            }
        }
    }
}

int IsThereSpace(const vector<int> &v, int num){
    assert(num<=v.size());
    rep(i,v.size()-num+1){
        bool space = true;
        for(int j=i;j<i+num;j++){
            if(v[j]!=-1){
                space = false;
            }
        }
        if(space) return i;
    }
    return -1;
}

int processing_que(vector<int> &v, queue<pii> &que){
    if(que.empty())return -1;
    int name, num;
    tie(name,num) = que.front();

    int res = IsThereSpace(v, num);
    if( res!=-1 ){
        for(int i=res;i<res+num;i++){
            assert(v[i]==-1);
            v[i] = name;
        }
        que.pop();
        return name;
    }else{
        return -1;
    }
}

int main(){
    int n;
    while(cin>>n){
        vector<int> eating_times(101,INF);
        vector<int> v(17,-1);
        queue<pii> que;
        map<int,vector<int>> mp;
        for(int t=0; t<=4200; t++){
            if(mp.count(t)!=0){
                leave(v, mp[t]);
                mp[t] = vector<int>();
            }
            if(t%5==0){
                int name = t/5;
                if(name>99)continue;
                int num;
                if(name%5==1)num = 5;
                else num = 2;

                int eating_time = 17*(name % 2) + 3*(name % 3) + 19;
                eating_times[name] = eating_time;
                que.push(pii(name, num));
            }
            bool n_entered = false;
            while(1){
                int res = processing_que(v, que);
                if(res==-1)break;
                else{
                    assert(eating_times[res]!=INF);
                    mp[t+eating_times[res]].pb(res);
                    if(res==n) n_entered = true;
                }
            }

            if(n_entered){
                cout<<t-n*5<<endl;
                break;
            }
            if(t==4200) assert(false);
        }
    }
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

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 && !e.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];
	deque<int> que;
	while(!Q.empty()){
		Event e = Q.top();
		Q.pop();
		
		bool search = true;
		if(e.isarrival){
			search = que.empty();
			que.push_back(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 = search_n(seat, seat+17, n, -1) - seat;
			
			if(pos == 17)
				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_front();
			}
		}
		
		// prinTf("time: %3d, ", e.time);
		// rep(i, 17)
		// 	printf(seat[i]==-1?"[__]":"[%2d]",seat[i]);
		// puts("");
		// copy(que.begin(), que.end(), ostream_iterator<int>(cout, ","));
		// puts("");
	}
	
	int n;
	while(scanf("%d", &n) != EOF){
		printf("%d\n", answer[n]);
	}

	return 0;
}