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 <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;

typedef pair<int, int> P;

int ans[110];
P seat[20];
queue<int> waiting;
int Cnt = 0;

void outputSeat(){
  for(int i = 0 ; i < 17 ; i++){
    printf("%3d ", seat[i].first);
  }
  cout << endl;
  
  for(int i = 0 ; i < 17 ; i++){
    printf("%3d ", seat[i].second);
  }
  cout << endl << endl;
}

bool come(int n, int t){
  int group = n % 5 == 1 ? 5 : 2;
  int cnt = 0, s = 0;
  bool f = false;
  for(int i = 0 ; i < 17 ; i++){
    if(seat[i].first == -1 && !f){
      s = i;
      f = true;
    }
    
    if(seat[i].first == -1){
      cnt++;
    }
    
    else cnt = 0, s = i+1, f = false;
  
    if(cnt == group){
      //cout << "OK"<<endl;
      for(int j = s ; j < s+group ; j++){
	seat[j].first = n;
	seat[j].second = 17*(n%2) + 3*(n%3) + 19 + t;
      }
      return true;
    }
  }
  return false;
}
  
void off(int n){
  for(int i = 0 ; i < 17 ; i++){
    if(seat[i].first == n) seat[i].first = -1, seat[i].second = -1;
  }
}

void solve(){
  for(int t = 0 ; t <= 610 ; t++){
    //outputSeat();
    //cout << "time = " << t << endl;
    for(int i = 0 ; i < 17 ; i++){
      if(seat[i].second == t){
	off(seat[i].first);
	if(waiting.size() > 0){
	  int num = waiting.front();
	  while(1){
	    bool f = come(num, t);
	    if(f){
	      ans[num] = t - ans[num];
	      waiting.pop();
	      num = waiting.front();
	      if(num == 0) break;
	    }
	    else break;
	  }
	}
      }
    }
    
    //cout << "front = " << waiting.front() << endl;
    
    if(t % 5 == 0 && Cnt < 100){
      Cnt++;
      int number = t / 5;
      if(waiting.size() > 0){
	ans[number] = t;
	waiting.push(number);
	continue;
      }
      bool f = come(number, t);
      if(f) ans[number] = 0;
      else{
	waiting.push(number);
	ans[number] = t;
      }
    }    
    
  }
  
}

void init(){
  memset(seat, -1 , sizeof(seat));  
  memset(ans, 0, sizeof(ans));
}

int main(){
  init();
  solve();
  int n;

  while(cin >> n) cout << ans[n] << endl;
  return 0;
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>

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 : 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];
	queue<int> que;
	while(!Q.empty()){
		Event e = Q.top();
		Q.pop();
		
		bool search = true;
		if(e.isarrival){
			search = que.empty();
			que.push(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 = -1;
			int cont = 0;
			rep(i, 17){
				if(seat[i] == -1){
					++cont;
					if(cont == n){
						pos = i;
						break;
					}
				}
				else
					cont = 0;
			}

			if(pos == -1)
				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();
			}
		}
	}
	
	int n;
	while(scanf("%d", &n) != EOF){
		printf("%d\n", answer[n]);
	}

	return 0;
}

C++: //Name: Fukushimaken
//Level: 2
//Category: シミュレーション
//Note: 

/**
 * 問題文の通りにシミュレーションする。
 * グループの到着と、食事の終了イベントをpriority_queueに突っ込んで取り出すようにする。
 * 到着したグループは別途queueに突っ込み、席に空きができたら埋めていくようにする。
 *
 * 入力が小さいので、特に効率のよいデータ構造を使わなくても間に合う。
 * オーダーは O(NW log N)。
 * ただしNはグループ数で、N=100。Wは座席の幅で、W=17。
 */
#include <iostream>
#include <queue>

using namespace std;

struct Event {
    enum {
        FINISH,
        ARRIVAL
    } type;
    int t;
    int idx;

    bool operator <(const Event &e) const {
        if(t != e.t) return t > e.t;
        return type > e.type;
    }
};

int gsize(int n) {
    return (n % 5 == 1 ? 5 : 2);
}

bool solve(bool first) {
    vector<int> res(100, -1);
    priority_queue<Event> eventq;
    for(int i = 0; i < 100; ++i) {
        eventq.push(Event{Event::ARRIVAL, i*5, i});
    }
    queue<int> q;
    vector<int> seats(17, -1);
    while(!eventq.empty()) {
        const Event e = eventq.top();
        eventq.pop();
        if(e.type == Event::ARRIVAL) {
            q.push(e.idx);
        } else {
            for(int i = 0; i < 17; ++i) {
                if(seats[i] == e.idx) seats[i] = -1;
            }
        }
        while(!q.empty()) {
            const int idx = q.front();
            const int s = gsize(idx);
            int acc = 0;
            int pos = -1;
            for(int i = 0; i < 17; ++i) {
                if(seats[i] == -1) {
                    ++acc;
                } else {
                    acc = 0;
                }
                if(acc == s) {
                    pos = i - s + 1;
                    break;
                }
            }
            if(pos == -1) break;
            for(int i = 0; i < s; ++i) {
                seats[pos+i] = idx;
            }
            res[idx] = e.t - idx*5;
            eventq.push(Event{Event::FINISH, e.t + 17*(idx%2) + 3*(idx%3) + 19, idx});
            q.pop();
        }
    }

    int N;
    while(cin >> N) {
        cout << res[N] << endl;
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}

C++: //52
#include<iostream>
#include<queue>
#include<utility>
#include<algorithm>

using namespace std;

int main(){
  int a[100];
  int cg[17]={};
  int cr[17];
  queue<pair<int,int> > que;
  for(int t=0;t<600;t++){
    if(t%5==0&&t/5<100){
      que.push(make_pair(t/5,t));
    }
    for(int i=0;i<17;i++){
      cr[i]--;
      if(cr[i]==0){
	cg[i]=false;
      }
    }
    int fc=0;
    for(int i=0;i<17;i++){
      if(cg[i]==false){
	fc++;
	if(!que.empty()){
	  int gn=que.front().first;
	  int ng=(gn%5==1)?5:2;
	  if(fc==ng){
	    for(int j=0;j<ng;j++){
	      cg[i-j]=true;
	      cr[i-j]=17*(gn%2)+3*(gn%3)+19;
	    }
	    a[gn]=t-que.front().second;
	    que.pop();
	    i=0;
	  }
	}
      }else{
	fc=0;
      }
    }
  }
  for(int n;cin>>n;){
    cout<<a[n]<<endl;
  }
  return 0;
}