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 <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef vector<double> vd;
typedef vector<vd> vvd;

struct Event
{
	int time;
	int group;
	bool isarrival;
	
	Event(int t, int g, bool f) : time(t), group(g), isarrival(f) {}
	bool operator< (const Event& e)const{
		return time == e.time ? isarrival && !e.isarrival : time > e.time;
	}
};

int main()
{
	int seat[17];
	fill_n(seat, 17, -1);
	
	priority_queue<Event> Q;
	rep(i, 100)
		Q.push(Event(i*5, i, true));
	
	int answer[100];
	deque<int> que;
	while(!Q.empty()){
		Event e = Q.top();
		Q.pop();
		
		bool search = true;
		if(e.isarrival){
			search = que.empty();
			que.push_back(e.group);
		}
		else{
			rep(i, 17){
				if(seat[i] == e.group)
					seat[i] = -1;
			}
		}
		
		while(search && !que.empty()){
			int n = que.front()%5 == 1 ? 5 : 2;
			int pos = search_n(seat, seat+17, n, -1) - seat;
			
			if(pos == 17)
				search = false;
			else{
				rep(i, n)
					seat[pos+i] = que.front();
				answer[que.front()] = e.time - que.front() * 5;
				Q.push(Event(e.time+17*(que.front()%2)+3*(que.front()%3)+19, que.front(), false));
				que.pop_front();
			}
		}
		
		// prinTf("time: %3d, ", e.time);
		// rep(i, 17)
		// 	printf(seat[i]==-1?"[__]":"[%2d]",seat[i]);
		// puts("");
		// copy(que.begin(), que.end(), ostream_iterator<int>(cout, ","));
		// puts("");
	}
	
	int n;
	while(scanf("%d", &n) != EOF){
		printf("%d\n", answer[n]);
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
#define SHEETS 17
#define GROUPS 100
int main()
{
	int ans[GROUPS] = {0,};
	int now;
	int sheets[SHEETS+1] = {-1,};
	int peoples[GROUPS] = {0,};
	int waiting[GROUPS] = {0,};
	int eating[GROUPS] = {0,};

	for(int i = 0; i < SHEETS+1; ++i){
		sheets[i] = -1;
	}
	for(int i = 0; i < GROUPS; ++i)
	{
		waiting[i] = -i*5;
		peoples[i] = i%5==1?5:2;
		eating[i] = 17*(i%2)+3*(i%3)+19;
	}
	now = 1;
	sheets[0] = sheets[1] = 0;
	for(int t = 0; t < 2000; ++t){
		
		for(int i = 0; i < GROUPS; ++i){
			++waiting[i];
		}
		
		for(int i = 0; i < SHEETS; ++i){
			if( sheets[i] >= 0 ){
				if( eating[sheets[i]] == 0 )
					sheets[i] = -1;
				else{
					--eating[sheets[i]];
					for(;sheets[i+1]==sheets[i];++i)0;
				}
			}
		}
		
		/*
		cout << "t="<<t<<":\t\t";
		for(int i = 0; i < SHEETS; ++i){
			cout << (char)(sheets[i]==-1?'_':sheets[i]+'0');
		}
		cout << '\n';
		*/
		
		while( true ){
			bool bCont = false;
			for(int i = 0; i < SHEETS; ++i){
				int cont = 0;
				if( sheets[i] < 0 ){
					for(int j = i; j < SHEETS; ++j){
						if( sheets[j] < 0 ) cont++;
						else break;
					}
					if( cont >= peoples[ now ] && waiting[ now ] >= 0 ){
						for(int j = i; j < i+peoples[now]; ++j)
							sheets[j] = now;
						ans[now] = waiting[now]-1<0?0:waiting[now]-1;
						++now;
						bCont = true;
					}
				}
			}
			if( !bCont )
				break;
		}
	}

	while(true){
		int n;
		cin >> n;
		if(n == 0)
			break;
		cout << ans[n] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    vector<int> seat(17, -1);
    multimap<int, int> leave;

    vector<int> waitTime(100);
    int prevTime = 0;
    for(int i=0; i<100; ++i){
        int time = 5*i;
        while(leave.size() > 0 && leave.begin()->first <= time){
            replace(seat.begin(), seat.end(), leave.begin()->second, -1);
            leave.erase(leave.begin());
        }

        int num = 2 + (i%5==1? 3:0);
        for(;;){
            vector<int> tmp(num, -1);
            int j = search(seat.begin(), seat.end(), tmp.begin(), tmp.end()) - seat.begin();
            if(j == 17){
                time = leave.begin()->first;
                replace(seat.begin(), seat.end(), leave.begin()->second, -1);
                leave.erase(leave.begin());
            }else{
                for(int k=0; k<num; ++k)
                    seat[j+k] = i;
                break;
            }
        }

        prevTime = max(time, prevTime);
        waitTime[i] = prevTime - 5*i;

        time += 17*(i%2) + 3*(i%3) + 19;
        leave.insert(make_pair(time, i));
    }

    for(;;){
        int n;
        if(!(cin >> n))
            return 0;
        cout << waitTime[n] << endl;
    }
}

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

int search_sequence(vector<int> &a,int n){
	int cnt=0;
	for(int i=0;i<a.size();++i){
		if(a[i]==-1)++cnt;
		else cnt=0;
		if(cnt>=n)return i-cnt+1;
	}
	return -1;
}

int main(void){
    vector<int> seat(17,-1);
    int time[100],finish[100];
    queue<pair<int,int> > q;
    int x=0,y=0;
    for(int t=0;y<100;++t){
      if(t%5==0&&x<100) q.push(make_pair(x++,(x%5==1)?5:2));
      for(int i=0;i<17;++i){
        if(seat[i]!=-1&&finish[seat[i]]==t){
        	fill(&seat[i],&seat[i+((seat[i]%5==1)?5:2)],-1);
        	//cerr<<t<<":";for(int i=0;i<17;++i)cerr<<seat[i]<<((i!=16)?" ":"\n");
      	}
      }
      while(!q.empty()){
      	pair <int,int> p=q.front();
      	if(search_sequence(seat,p.second)==-1)break;
        fill(&seat[search_sequence(seat,p.second)],&seat[search_sequence(seat,p.second)+p.second],p.first);
        //cerr<<t<<":";for(int i=0;i<17;++i)cerr<<seat[i]<<((i!=16)?" ":"\n");
        finish[p.first]=t+17*(p.first%2)+3*(p.first%3)+19;
        time[p.first]=t-5*p.first;
        q.pop();++y;
      }
    }
  int n;
  while(cin>>n){
  	cout<<time[n]<<endl;
  }
  return 0;
}