Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)
const INF = 0x7fffffff
func main() {
	S := 17
	seat := make([][]int, 27)
	for i :=range seat {
		seat[i] = make([]int, 27)
	}
	ans := make([]int, 105)
	id := 0
	Q := make([][]int, 0)
	for i := 0; i < S; i++ {
		seat[i][0] = -1
	}
	t := -1
	for ans[99] == 0 {
		t++
		if  t%5 == 0 && id <= 99 {
			if id % 5 == 1 {
				n := 5
				tmp := []int{id, n, t}
				Q = append(Q, tmp)
				id++
			} else {
				n := 2
				tmp := []int{id, n, t}
				Q = append(Q, tmp)
				id++
			}
		}
		for i := 0; i < 5; i++ {
			if seat[i][1] == 0 {
				continue
			}
			seat[i][1]--
			if seat[i][1] == 0 {
				seat[i][0] = -1
			}
		}
		f := len(Q)
		for f > 0 {
			i, n := Q[0][0], Q[0][1]
			f = 0
			for j := 0; j < S; j++ {
				g := 0
				for k := 0; k < n; k++ {
					if seat[j+k][0] >= 0 {
						g = 1
						break
					}
				}
				if g != 0 {
					continue
				}
				ans[i] = t-Q[0][2]
				Q = Q[1:]
				f = len(Q)
				for k := 0; k < n; k++ {
					seat[j+k][0] = i
					seat[j+k][1] = 17*(i&1) + 3*(i%3) + 19
				}
				break
			}
		}
	}
	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;
}