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

using namespace std;

int r[101];
struct Gr{
	int n;
	int tm;
	int pn;
	int vis;
};

int check(int a[17], int p)
{
	int t = 0;
	
	for(int i = 0; i < 17; i++){
		if(a[i] == 0){
			t++;
			if(t == p){
				return i-p+1;
			}
		} else {
			t = 0;
		}
	}
	
	return -1;
}

void func(void)
{
	int a[17], u, v;
	queue<Gr> que;
	Gr s;
	fill(a, a+17, 0);
	for(int i = 0; i < 100; i++){
		s.n = i;
		s.vis = i*5;
		s.pn = (i%5 == 1)? 5 : 2;
		s.tm = 17*(i%2) + 3*(i%3) + 19;
		que.push(s);
	}
	
	v = 0;
	while(!que.empty()){
		s = que.front();
		que.pop();
		for(;; v++){
			if(s.vis <= v){
				u = check(a, s.pn);
				if(u == -1){
					for(int i = 0; i < 17; i++){
						if(a[i] > 0){
							a[i]--;
						}
					}
					continue;
				}
				for(int i = 0; i < s.pn; i++){
					a[i+u] = s.tm;
				}
				r[s.n] = v-s.vis;
				break;
			} else {
				for(int i = 0; i < 17; i++){
					if(a[i] > 0){
						a[i]--;
					}
				}
			}
		}
	}
	
	return ;
}

int main()
{
	int n;
	fill(r, r+101, 0);
	func();
	
	while(cin>>n){
		cout << r[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 < 17; j++){
      if(chair[j] > 0) chair[j]--;
    }

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

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, LEAVE };
int now; bool fiveempty, twoempty;
int ans[100], seats[17];
map<int, queue<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(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(MP(i, (int)INQ));
  queue<int> waitingQ;
  fiveempty = twoempty = 1;
  memset(seats, -1, sizeof seats);
  while(!mp.empty()) {
    now = mp.begin()->F;
    queue<pair<int, int> >& Q = mp.begin()->S;
    int id = Q.front().F;
    int act = Q.front().S; Q.pop();
    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); }
    }
    if(act == LEAVE) {
      leave(id);
      while( !waitingQ.empty()
             && ( (num(waitingQ.front()) == 5 && fiveempty)
                  || (num(waitingQ.front()) == 2 && twoempty) )
      ) { sit(waitingQ.front()); waitingQ.pop(); }
    }
    if(mp.begin()->S.empty()) mp.erase(mp.begin());
  }
  for(int N; cin >> N;) cout << ans[N] << endl;
  
  return 0;
}

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

int a[17], c[100];
priority_queue<pair<int,int> > b;

int can_sit(int n) {
  int p = 0;
  for (int i=0; i<17; i++) {
    if (a[i] == -1) {
      ++p;
    } else {
      p = 0;
    }
    if (p == n) {
      return i-n+1;
    }
  }
  return -1;
}

int sit(int id, int stt, int n) {
  for (int i=0; i<n; i++) {
    a[i+stt] = id;
  }
}

int stand(int id) {
  for (int i=0; i<17; i++) {
    if (a[i] == id) {
      a[i] = -1;
    }
  }
}

int main() {
  int t, p, q, r;
  for (int i=0; i<17; i++) a[i] = -1;
  t = 0;
  p = 0;
  while (1) {
    while (t >= 5*p && p<100) {
      q = (p%5==1) ? 5 : 2;
      r = can_sit(q);
      if (r != -1) {
        c[p] = t - 5*p;
        sit(p, r, q);
        b.push(pair<int, int>(-(t + 17*(p%2) + 3*(p%3) + 19), p));
        p++;
      } else {
        break;
      }
    }
    if (-b.top().first <= ((t/5)+1)*5) {
      t = -b.top().first;
      stand(b.top().second);
      b.pop();
    } else {
      t = ((t/5)+1)*5;
    }
    if (p==100) {
      break;
    }
  }

  while (cin >> t) {
    cout << c[t] << endl;
  }

  return 0;
}