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++: //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});
    }
    queue<int> q;
    vector<int> seats(17, -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;
            }
        }
        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] = e.t - idx*5;
            eventq.push(Event{Event::FINISH, e.t + 17*(idx%2) + 3*(idx%3) + 19, idx});
            q.pop();
        }
    }

    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){
		if(n >= 50)c++;
		cout << stop[n] << endl;
	}
	while(c>=5){};
	
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;

int countdown[17];

int main() {
    memset(countdown, 0, sizeof countdown);
    vector<int> ans;
    queue<int> q;
    for (int m=0; (int)ans.size()<100; ++m) {
        if (m%5 == 0 && m/5 < 100) q.push(m/5);
        for (int i=0; i<17; ++i) {
            if (countdown[i]) --countdown[i];
        }
        while ( ! q.empty()) {
            bool change = false;
            int num = (q.front()%5 == 1 ? 5 : 2);
            for (int i=0; i+num-1<17; ++i) {
                bool ok = true;
                for (int j=i; j<=i+num-1; ++j) {
                    if (0 < countdown[j]) ok = false;
                }
                if (ok) {
                    change = true;
                    for (int j=i; j<=i+num-1; ++j) {
                        countdown[j] = 17*(q.front()%2) + 3*(q.front()%3) + 19;
                    }
                    ans.push_back(m - (5 * q.front()));
                    q.pop();
                    break;
                }
            }
            if ( ! change) break;
        }
    }
    int n;
    while (cin >> n) {
        cout << ans[n] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <queue>
using namespace std;

const int MAX_SIZE = 100;
const int SEATS = 17;

int* calc() {
  queue<int> q;
  int *a = new int[MAX_SIZE]();
  int g, n, s[SEATS] = {};
  for (int t = 0; ; ++t) {
    for (int i = 0; i < SEATS; ++i) {
      if (s[i]) s[i]--;
    }
    if (t % 5 == 0) q.push(t / 5);
    while (!q.empty()) {
      bool c = false;
      g = q.front();
      n = g % 5 == 1 ? 5 : 2;
      for (int i = 0; i < SEATS - n + 1; ++i) {
        if (n == 2 && !(s[i] || s[i + 1])) {
          s[i] = s[i + 1] = 17 * (g % 2) + 3 * (g % 3) + 19;
          c = true;
          break;
        }
        if (n == 5 && !(s[i] || s[i + 1] || s[i + 2] || s[i + 3] || s[i + 4])) {
          s[i] = s[i + 1] = s[i + 2] = s[i + 3] = s[i + 4] = 17 * (g % 2) + 3 * (g % 3) + 19;
          c = true;
          break;
        }
      }
      if (c) {
        a[g] = t - g * 5;
        if (g == MAX_SIZE - 1) return a;
        q.pop();
      } else {
        break;
      }
    }
  }
  return a;
}

int main() {
  int n;
  int *a = calc();
  while (true) {
    cin >> n;
    if (cin.eof()) break;
    cout << a[n] << endl;
  }
}