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 <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define MP make_pair
#define F first
#define S second

enum { INQ, SIT, LEAVE };
int now; bool fiveempty, twoempty;
int ans[100], seats[17];
map<int, deque<pair<int, int> > > mp;
inline int num(int i) {return i%5==1?5:2;}
inline int eattime(int i) {return 17*(i%2)+3*(i%3)+19;}

void update_emptyseats() {
  bool fe = 0, te = 0;
  rep(i, 13)
    if(seats[i]==-1 &&
       seats[i+1]==-1 &&
       seats[i+2]==-1 &&
       seats[i+3]==-1 &&
       seats[i+4]==-1) { fe = 1; }
  rep(i, 16)
    if(seats[i]==-1 && seats[i+1]==-1) { te = 1; }
  fiveempty = fe, twoempty = te;
}

void sit(int id) {
  ans[id] = now-5*id;
  mp[now+eattime(id)].push_front(MP(id, (int)LEAVE));
  
  if(num(id) == 5) rep(i, 13)
                     if(seats[i]==-1 &&
                        seats[i+1]==-1 &&
                        seats[i+2]==-1 &&
                        seats[i+3]==-1 &&
                        seats[i+4]==-1) {
                       rep(j, 5) seats[i+j] = id;
                       update_emptyseats(); return;
                     }
  
  if(num(id) == 2) rep(i, 16)
                     if(seats[i]==-1 && seats[i+1]==-1) {
                       rep(j, 2) seats[i+j] = id;
                       update_emptyseats(); return;
                     } 
}

void leave(int id) {
  rep(i, 17) {
    if(seats[i] == id) {
      rep(j, num(id)) { seats[i+j] = -1; }
      update_emptyseats();
      return;
    }
  }
}

int main() {
  
  rep(i, 100) mp[5*i].push_back(MP(i, (int)INQ));
  queue<int> waitingQ;
  fiveempty = twoempty = 1;
  memset(seats, -1, sizeof seats);
  while(!mp.empty()) {
    now = mp.begin()->F;
    deque<pair<int, int> >& Q = mp.begin()->S;
    int id = Q.front().F;
    int act = Q.front().S; Q.pop_front();
    if(act == SIT) {
      sit(id);
      if( !waitingQ.empty()
          && ( (num(waitingQ.front()) == 5 && fiveempty)
               || (num(waitingQ.front()) == 2 && twoempty) )
      ) {
        Q.push_front(MP(waitingQ.front(), (int)SIT));
        waitingQ.pop();
      }
    }
    else if(act == INQ) {
      if(!waitingQ.empty()) { waitingQ.push(id); }
      else if(num(id) == 5 && fiveempty) { sit(id); }
      else if(num(id) == 2 && twoempty) { sit(id); }
      else { waitingQ.push(id); }
    }
    else if(act == LEAVE) {
      leave(id);
      if( !waitingQ.empty()
          && ( (num(waitingQ.front()) == 5 && fiveempty)
               || (num(waitingQ.front()) == 2 && twoempty) )
      ) { Q.push_front(MP(waitingQ.front(), (int)SIT)); waitingQ.pop(); }
    }
    if(Q.empty()) mp.erase(mp.begin());
  }
  for(int N; cin >> N;) cout << ans[N] << endl;
  
  return 0;
}

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

struct G{
  int group, people, now, time;
};

int main(){
  int minutes[100];
  int chair[17]; //あーじゅうななせきあった！！
  fill_n( chair, 17, 0);

  queue< G > mati;

  for(int i = 0; i < 10000; i++){
   if(i % 5 == 0 && i / 5 < 100){ //group leave
      int group = i / 5;
      mati.push((G){ group, group % 5 == 1 ? 5 : 2, i, 17 * (group % 2) + 3 * (group % 3) + 19});
    }


    while(!mati.empty()){
      G& g = mati.front();
      int count = 0, pos = -1;
      for(int j = 0; j < 17; j++){
        if(!chair[j]){
          count++;
          if(count == g.people){
            pos = j - g.people + 1;
            break;
          }
        }else{
          count = 0;
        }
      }
      if(pos != -1){
        minutes[g.group] = i - g.now;
        for(int j = pos; j < pos + g.people; j++){
          chair[j] = g.time;
        }
        mati.pop();
      } else {
        break;
      }
    }

    for(int j = 0; j < 16; j++){
      if(chair[j] > 0) chair[j]--;
    }

  }
  int n;
  while(cin >> n){
    cout << minutes[n] << endl;
  }
}

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

int seat[17], countdown[17];
int arrival[100], sit[100];

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