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 <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


const int INF = INT_MAX;

void solve( int n ) {
    int A[n+1], K[n+1], T[n+1];
    int BG[n+1];
    for ( int i = 0; i <= n; ++ i ) {
        A[i] = 5 * i;
    }
    for ( int i = 0; i <= n; ++ i ) {
        K[i] = ( i % 5 == 1 ) ? 5 : 2;
    }
    for ( int i = 0; i <= n; ++ i ) {
        T[i] = 17 * ( i % 2 ) + 3 * ( i % 3 ) + 19;
    }
    int U[17]; 
    fill( U, U+17, -1 );
    queue <int> Q;
    int cnt = 0;
    bool used[n+1];
    fill( used, used+n+1, false );
    for ( int t = 0; cnt <= n; ++ t ) {
        for ( int i = 0; i <= n; ++ i ) {
            if ( A[i] <= t ) {
                Q.push( i );
                A[i] = INF;
                BG[i] = t;
            }
        }
        for ( int i = 0; i < 17; ++ i ) {
            if ( U[i] == -1 ) continue;
            int id = U[i];
            if ( T[id] <= t ) {
                U[i] = -1;
                if ( ! used[id] ) {
                    cnt ++;
                    used[id] = true;
                }
            }
        }
        while ( ! Q.empty() ) {
            int id = Q.front();
            int k = K[id];
            bool flag2 = false;
            for ( int i = 0; i + k - 1 < 17; ++ i ) {
                bool flag = true;
                for ( int j = 0; j < k; ++ j ) {
                    if ( U[i+j] != -1 ) flag = false;
                }
                if ( flag ) {
                    for ( int j = 0; j < k; ++ j ) {
                        U[i+j] = id;
                    }
                    if ( n == id ) {
                        cout << t - BG[id] << endl;
                        return;
                    }
                    T[id] += t;
                    Q.pop();
                    flag2 = true;
                    break;
                }
            }
            if ( ! flag2 ) break;
        }
    }
    cout << endl;
}

int main() {
    int n;
    while ( cin >> n ) solve( n );
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

const int MAXN = 101;
const int W = 17;
int wait[MAXN];
int u[W];

void make() {
  fill(u, u+W, 0);
  queue<pair<int,int> > que;
  for(int t = 0, i = 0; i < 100 || que.size(); ++t) {
    if(i < 100 && t == 5*i) que.push(make_pair(i++, t));
    while(que.size()) {
      int k = que.front().first;
      int s = que.front().second;
      int x = k%5 == 1 ? 5 : 2;
      int d = 17 * (k%2) + 3*(k%3) + 19;

      int pos = -1;
      for(int j = 0; j+x <= W; ++j) {
        bool flag = true;
        for(int a = 0; a < x; ++a) {
          if(u[j+a] > t) {
            flag = false;
            break;
          }
        }
        if(flag) {
          pos = j;
          break;
        }
      }
      if(pos == -1) break;
      wait[k] = t - s;
      que.pop();
      for(int a = 0; a < x; ++a) u[pos+a] = t + d;
    }
  }
}

int main() {
  make();
  int n;
  while(cin >> n) {
    cout << wait[n] << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int d[17];
	int n[100]={0};
	int cnt=0,t=0,g;
	queue<int> q;
	vector<int> l;
	rep(i,17)d[i]=0;
	for(;t<30000;t++){
		rep(i,17)if(d[i]>0)d[i]--;
		if(t%5==0 && cnt < 100){
			l.push_back(cnt);
			q.push(cnt++);
		}
		g=1;
		while(!q.empty() && g){
			int v=q.front();
			int num=v%5==1?5:2;
			g=0;
			int f=1;
			rep(j,17-num){
				if(d[j]<1){
					reps(k,1,num-1)if(d[j+k]>0)f=0;
					if(f){
						q.pop();
						rep(k,num)d[j+k]=17*(v%2)+3*(v%3)+19;
						g=1;
					}
				}
				if(g)break;
			}
		}
		rep(i,l.size())if(!q.empty() && l[i]>=q.front())n[l[i]]++;
	}
	while(~scanf("%d",&t))printf("%d\n",n[t]);
	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();
			}
		}
		//printf("time: %3d, ", e.time);
		//rep(i, 17)
		//	printf(seat[i]==-1?"[__]":"[%2d]",seat[i]);
		//puts("");
	}
	
	int n;
	while(scanf("%d", &n) != EOF){
		printf("%d\n", answer[n]);
	}

	return 0;
}