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 <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int N = 100;
const int T = 17;

void check(int cnt[N], P c[T], queue<int> &q, int &l, int &t){
  REP(i, T){
    if(c[i].first == -1) continue;
    int n = c[i].first;
    if(c[i].second + (17 * (n % 2) + 3 * (n % 3) + 19) == t){
      l = max(l, c[i].first);
      c[i] = P(-1, -1);
    }
  }
  while(!q.empty()){
    int n = q.front();
    int m = (n % 5 == 1 ? 5 : 2);
    bool ff = false;
    REP(i, T - m + 1){
      bool f = true;
      REP(j, m) if(c[i + j].first != -1) f = false;
      if(f){
        cnt[n] = t - n * 5;
        REP(j, m) c[i + j] = P(n, t);
        ff = true;
        q.pop();
        break;
      }
    }
    if(!ff) break;
  }
}

int main() {
  int cnt[N], l = -1, t = 0;
  P c[T];
  memset(cnt, 0, sizeof(cnt));
  REP(i, T) c[i] = P(-1, -1);
  queue<int> q;
  while(l < N){
    if(t % 5 == 0) q.push(t / 5);
    check(cnt, c, q, l, t);
    ++t;
  }
  int n;
  while(cin >>n) cout <<cnt[n] <<endl;
  return 0;
}

C++: //Name: Fukushimaken
//Level: 2
//Category: シミュレーション
//Note: 

/**
 * 問題文の通りにシミュレーションする。
 * グループの到着と、食事の終了イベントをpriority_queueに突っ込んで取り出すようにする。
 * 到着したグループは別途queueに突っ込み、席に空きができたら埋めていくようにする。
 *
 * 入力が小さいので、特に効率のよいデータ構造を使わなくても間に合う。
 * オーダーは O(NW log N)。
 * ただしNはグループ数で、N=100。Wは座席の幅で、W=17。
 */
#include <iostream>
#include <queue>

using namespace std;

struct Event {
    enum {
        ARRIVAL,
        FINISH
    } type;
    int t;
    int idx;

    bool operator <(const Event &e) const {
        return t > e.t;
    }
};

int gsize(int n) {
    return (n % 5 == 1 ? 5 : 2);
}

bool solve(bool first) {
    vector<int> res(100, -1);
    priority_queue<Event> eventq;
    for(int i = 0; i < 100; ++i) {
        eventq.push(Event{Event::ARRIVAL, i*5, i});
    }
    eventq.push(Event{Event::FINISH, 500, -1}); // Sentinel
    queue<int> q;
    vector<int> seats(17, -1);
    int lastt = -1;
    while(!eventq.empty()) {
        const Event e = eventq.top();
        eventq.pop();
        if(e.type == Event::ARRIVAL) {
            q.push(e.idx);
        } else {
            for(int i = 0; i < 17; ++i) {
                if(seats[i] == e.idx) seats[i] = -1;
            }
        }
        if(e.t != lastt) {
            while(!q.empty()) {
                const int idx = q.front();
                const int s = gsize(idx);
                int acc = 0;
                int pos = -1;
                for(int i = 0; i < 17; ++i) {
                    if(seats[i] == -1) {
                        ++acc;
                    } else {
                        acc = 0;
                    }
                    if(acc == s) {
                        pos = i - s + 1;
                        break;
                    }
                }
                if(pos == -1) break;
                for(int i = 0; i < s; ++i) {
                    seats[pos+i] = idx;
                }
                res[idx] = lastt - idx*5;
                eventq.push(Event{Event::FINISH, lastt + 17*(idx%2) + 3*(idx%3) + 19, idx});
                q.pop();
                /*
                for(int i = 0; i < 17; ++i) {
                    if(seats[i] == -1) cout << '-';
                    else cout << seats[i]%10;
                }
                cout << endl;
                */
            }
        }
        lastt = e.t;
    }

    int N;
    while(cin >> N) {
        cout << res[N] << endl;
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int seat[17] = {0};
	int X = 0;
	int stop[100] = {0};
	int time = 0;
	queue<int> Q;
	while(X < 100){
		int x;
		if(time%5 == 0 && time < 500){
			Q.push(time/5);
		}
		while(1){
			if(Q.size())x = Q.front();
			else x = -1;
			bool f = false;
			
			if(~x){
				int people = (x%5==1?5:2);
				int use = 19 + 3 * (x%3) + 17 * (x%2);
				rep(i,17-people+1){
					bool flag = true;
					rep(j,people){
						flag &= seat[i+j] == 0;
					}
					if(flag){
						rep(j,people){
							seat[i+j] = use;
						}
						f = true;
						break;
					}
				}
			}
			if(f){	
				stop[x] = time - x * 5;
				Q.pop();
				X++;
			}
			if(!f)break;
		}
		rep(i,17){
			seat[i] = max(0,seat[i]-1);
		}
		time++;
	}
	int n,c=0;
	while(cin >> n){
		cout << stop[n] << endl;
		c++;
	}
	while(c>=5){};
	
}

C++: #include <cstdio>
#include <queue>
#include <cstring>

using namespace std;

class data{
public:
	int num,t;
	data(int n,int tt){
		num=n;
		t=tt;
	}
};

int n;
int fie[17];
int wait[100];

int enter(int x){
	int f=0,cnt=0;
	for(int i=0;i<17;i++){
		if(fie[i]==-1){
			if(cnt==0)f=i;
			cnt++;
			if(cnt==x)return f;
		}else cnt=0;
	}
	return -1;
}

int main(void){
	queue<data> que;
	memset(fie,-1,sizeof(fie));
	memset(wait,-1,sizeof(wait));
	int i=0;
	while(wait[99]==-1){
		if(i%5==0 && i<500){
			que.push(data(i/5,i));
		}
		for(int j=0;j<17;j++){
			if(fie[j]==i)fie[j]=-1;
		}
		while(1){
			if(que.empty())break;
			data next=que.front();
			int number;
			if(next.num%5==1)number=5;
			else number=2;
			int from=enter(number);
			if(from>=0){
				wait[next.num]=i-next.t;
				for(int j=0;j<number;j++){
					fie[from+j]=i+17*(next.num%2)+3*(next.num%3)+19;
				}
				que.pop();
			}else break;
		}
		i++;
	}
	while(~scanf("%d",&n)){
		printf("%d\n",wait[n]);
	}
	return 0;
}