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<deque>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
using namespace std;

int ans[200];
int seat[17];

int check(int n)
{
  int size = (n%5==1?5:2);
  int cnt = 0;
  rep(i,17)
    {
      if(seat[i] == 0)cnt++;
      else            cnt = 0;
      if(cnt >= size)
	return i-size+1;
    }
  return -1;
}

int main()
{
  rep(i,200)ans[i] = 0;
  int phase = 0;
  int group = 0;
  //17(i%2)+3(i%3)+19 
  deque<int> que;
  rep(i,17)seat[i] = 0;
  while(group < 11)
    {
      /*
      cout << phase << " --------- " << endl;
      if(!que.empty())
      cout << "top = " <<que.front() << endl;
      */
      if(phase%5 == 0)
	{
	  que.push_back(group++);
	}
      rep(i,17)if(seat[i] > 0)seat[i]--;
      int pos;

      while(!que.empty() && ((pos = check(que.front())) != -1) )
	{
	  int i = que.front();
	  int tm = 17 * (i % 2) + 3 * (i % 3) + 19;
	  REP(j,pos,pos+(i%5==1?5:2))
	    {
	      assert(seat[j] == 0);
	      seat[j] = tm;
	    }
	  que.pop_front();
	}

      for(deque<int>::iterator it = que.begin(); it != que.end();it++)
	{
	  ans[*it]++;
	}
      /*
      rep(i,16)cout << seat[i] << " ";
      cout << endl << endl;
      */
      phase++;
    }
  int n;
  while(cin >> n)cout << ans[n] << endl;
  return 0;
}

C++: #include <iostream>
#include <queue>
#include <vector>
#define mp make_pair
using namespace std;

struct P{ int tim,group,act; };

struct comp {
	bool operator()(P t1, P t2) const {
		if(t1.tim != t2.tim) return t1.tim > t2.tim;
		else return t1.act > t2.act;
 	}
};

int chair[17];

int emp(int num){
	for(int i = 0;i < 17 - num + 1;i++){
		bool flag = true;
		for(int j = 0;j < num;j++){
			if(chair[i + j] != -1) flag = false;
		}
		if(flag) return i;
	}
	return -1;
}

int main(){
	int n,front = -1,wait[100] = {};
	priority_queue<P,vector<P>,comp> que;
	queue<int> line;
	for(int i = 0;i < 17;i++) chair[i] = -1;
	for(int i = 0;i < 100;i++) que.push({i * 5,i,0});
	while(!que.empty()){
		P p = que.top();que.pop();
		int t = p.tim,group = p.group,act = p.act;
		if(act == 0){
			int num = 2,pos;
			if(group % 5 == 1) num = 5;
			pos = emp(num);
			if(!line.empty() || pos == -1) line.push(group);
			else{
				for(int i = 0;i < num;i++) chair[i + pos] = group;
				que.push({t + 17 * (group % 2) + 3 * (group % 3) + 19,group,1});
			}
		}else{
			for(int i = 0;i < 17;i++){
				if(chair[i] == group) chair[i] = -1;
			}
			while(!line.empty()){
				int g = line.front(),num = 2,pos;
				if(g % 5 == 1) num = 5;
				pos = emp(num);
				if(pos != -1){
					line.pop();
					wait[g] = t - g * 5;
					for(int i = 0;i < num;i++) chair[pos + i] = g;
					que.push({t + 17 * (g % 2) + 3 * (g % 3) + 19,g,1});
				}
				else break;
			}
		}
	}
	while(cin >> n){
		cout << wait[n] << endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

void leave(vector<int> &v, const vector<int> &leavers){
    for(auto name:leavers){
        rep(i,v.size()){
            if(v[i]==name){
                v[i] = -1;
            }
        }
    }
}

int IsThereSpace(const vector<int> &v, int num){
    assert(num<=v.size());
    rep(i,v.size()-num+1){
        bool space = true;
        for(int j=i;j<i+num;j++){
            if(v[j]!=-1){
                space = false;
            }
        }
        if(space) return i;
    }
    return -1;
}

int processing_que(vector<int> &v, queue<pii> &que){
    if(que.empty())return -1;
    int name, num;
    tie(name,num) = que.front();

    int res = IsThereSpace(v, num);
    if( res!=-1 ){
        for(int i=res;i<res+num;i++){
            assert(v[i]==-1);
            v[i] = name;
        }
        que.pop();
        return name;
    }else{
        return -1;
    }
}

int main(){
    int n;
    while(cin>>n){
        vector<int> eating_times(101,INF);
        vector<int> v(17,-1);
        queue<pii> que;
        map<int,vector<int>> mp;
        for(int t=0; t<=4200; t++){
            if(mp.count(t)!=0){
                leave(v, mp[t]);
                mp[t] = vector<int>();
            }
            if(t%5==0){
                int name = t/5;
                if(name>99)continue;
                int num;
                if(name%5==1)num = 5;
                else num = 2;

                int eating_time = 17*(name % 2) + 3*(name % 3) + 19;
                eating_times[name] = eating_time;
                que.push(pii(name, num));
            }
            bool n_entered = false;
            while(1){
                int res = processing_que(v, que);
                if(res==-1)break;
                else{
                    assert(eating_times[res]!=INF);
                    mp[t+eating_times[res]].pb(res);
                    if(res==n) n_entered = true;
                }
            }

            if(n_entered){
                cout<<t-n*5<<endl;
                break;
            }
            if(t==4200) assert(false);
        }
    }
}