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 <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while (cin >> n)
	{
		vector<int> seat(17);
		queue<P> que;
		int time = 0;
		int num = 0;
		while (true)
		{
			if (time % 5 == 0)
			{
				que.push(P(num, time));
				++num;
			}
			for (int i = 0; i < 17; ++i)
			{
				if (seat[i] > 0)
				{
					--seat[i];
				}
			}
			bool update = true;
			while (!que.empty() && update)
			{
				update = false;
				if (que.front().first % 5 == 1)
				{
					for (int i = 0; i + 4 < 17; ++i)
					{
						if (seat[i] == 0 && seat[i + 1] == 0 && seat[i + 2] == 0 && seat[i + 3] == 0 && seat[i + 4] == 0)
						{
							seat[i] = seat[i + 1] = seat[i + 2] = seat[i + 3] = seat[i + 4] = 17 * (que.front().first % 2) + 3 * (que.front().first % 3) + 19;
							if (que.front().first == n)
							{
								cout << time - que.front().second << endl;
								goto END;
							}
							que.pop();
							update = true;
							break;
						}
					}
				}
				else
				{
					for (int i = 0; i + 1 < 17; ++i)
					{
						if (seat[i] == 0 && seat[i + 1] == 0)
						{
							seat[i] = seat[i + 1] = 17 * (que.front().first % 2) + 3 * (que.front().first % 3) + 19;
							if (que.front().first == n)
							{
								cout << time - que.front().second << endl;
								goto END;
							}
							que.pop();
							update = true;
							break;
						}
					}
				}
			}
			++time;
		}
	END:
		;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); 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()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int Time[10] = {  0,  5, 10, 15, 20, 25, 30, 35, 40, 45};
int peop[10] = {  2,  5,  2,  2,  2,  2,  5,  2,  2,  2};
int eats[10] = { 19, 39, 25, 36, 22, 42, 19, 39, 25, 36};
int star[10];
int tabl[17];
int ans[10];

int main(){
  int next = 0;
  REP(i,17) tabl[i] = -1;
  for(int i=0; ; i++){
    REP(j,17) if(tabl[j] != -1){
      int t = tabl[j];
      if(star[t] + eats[t] == i){
        tabl[j] = -1;
        if(t == 9) goto end;
      }
    }

  loop:
    if(Time[next] <= i){
      int cnt = 0;
      int st  = -1;
      REP(j,17){
        if(tabl[j] == -1){
          if(cnt == 0) st = j;
          cnt++;
          if(cnt == peop[next])
            break;
        }else cnt = 0;
      }
      if(cnt == peop[next]){
        ans[next] = i - Time[next];
        star[next] = i;
        REP(j,peop[next])
          tabl[st + j] = next;
        next++;
        goto loop;
      }
    }

    /*
    printf("%d: ",i);
    REP(j,17){printf("%3d ",tabl[j]);} puts("");
    getchar();
    */
  }

 end:
  int n;
  while(~scanf("%d",&n))
    print(ans[n]);

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