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 <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  queue<int> Q;
  vector<int> seki(17);
  Q.push(0);
  int time = 0;
  int hoge[100];
  while(1) {
    REP(i, 17) if (seki[i]) seki[i]--;

    if (!Q.empty()) {
      int a = Q.front();
      if (a >= 100) break;
      //   cout << "a" << " " << a << endl;
    
      int num = a%5==1 ? 5 : 2;
      
      int tmp = 0;
      REP(i,17) {
        a = Q.front();
        if (a >= 100) break;
        if (seki[i] == 0) ++tmp;
        else tmp = 0;
        if (tmp >= num) {
          for (int j=i-tmp+1; j<=i; ++j) {
            //         cout << j << endl;
            hoge[a] = time - a*5;
            seki[j] = 17*(a%2)+3*(a%3)+19;
          }
          Q.pop();
          if (Q.empty()) break;
        }
      }
      // cout << time << endl;
      // FOR(it, seki)
      //   cout << *it << " ";
      // cout << endl;
    }
    time++;
    if (time % 5 == 0) Q.push(time/5);
  }
  int n;
  while(cin >> n) {
    cout << hoge[n] << endl;
  }
}

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

		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 && ans < 0; ++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( ans < 0 ){
				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;
							if( now == n ){
								ans = waiting[now] - 1;
								break;
							}
							++now;
							bCont = true;
						}
					}
				}
				if( !bCont )
					break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-6;

struct group{
	int num;
	int eatTime;
	int idx;
};

void checkTable(int table[17],queue<group>& que,int time,map<int,int>& waitTime){
	for(int i=0;i<17;i++){
		table[i] -= table[i]>=1 ? 1 : 0;
	}

	for(int i=0;i<17;i++){
		for(int j=i;j<17;j++){
			if(table[j] > 0) break;
			if(que.empty()) goto end;

			if(j-i+1 == que.front().num && que.front().idx * 5 <= time){
				waitTime[que.front().idx] = abs(time - que.front().idx * 5);
				int num = que.front().num;
				int eat = que.front().eatTime;
				que.pop();
				for(int k=i;k<=j;k++){
					table[k] = eat;
				}
			}
		}
	}
end:;
}

int main(){
	int n;
	int table[17];
	memset(table,0,sizeof(table));
	queue<group> que;
	map<int,int> waitTime;

	for(int i=0;i<100;i++){
		int num = i % 5 == 1 ? 5 : 2;
		int eat = 17*(i%2)+3*(i%3)+19;
		group g;
		g.eatTime = eat;
		g.idx = i;
		g.num = num;
		que.push(g);		
	}

	for(int i=0;i<1000000;i++){
		checkTable(table,que,i,waitTime);
	}

	while(~scanf("%d",&n)){
		cout << waitTime[n] << endl;
	}
}

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

const int INF = 1 << 30;

int main()
{
  int time = 0;
  vector<int> seat(17, INF), ans(100);
  for (int i = 0; i < 100; ++i) {
    time = max(time, i*5);
    int people = 2;
    if (i%5 == 1)
      people = 5;

    for ( ; ; ) {
      for (int j = 0; j < seat.size(); ++j) {
	if (seat[j] <= time)
	  seat[j] = INF;
      }

      int con = 0;
      bool in = false;
      for (int j = 0; j < seat.size(); ++j) {
	if (seat[j] == INF) {
	  ++con;
	  if (con == people) {
	    in = true;
	    for (int k = j; k > j-con; --k)
	      seat[k] = time + 17*(i%2) + 3*(i%3) + 19;
	    ans[i] = max(0, time - i*5);
	    break;
	  }
	} else {
	  con = 0;
	}
      }

      if (in)
	break;

      int min_time = INF;
      for (int j = 0; j < seat.size(); ++j)
	min_time = min(min_time, seat[j]);
      time = min_time;
    }
  }

  int n;
  while (cin >> n)
    cout << ans[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;
	queue<int> q;
	rep(i,17)d[i]=0;
	for(;cnt<100;t++){
		if(t%5==0 && t<500)q.push(t/5);
		while(!q.empty()){
			int v=q.front();
			int num=v%5==1?5:2;
			int g=0;
			rep(j,18-num){
				if(d[j]<1 && !g){
					g=1;
					reps(k,1,num-1){
						if(d[j+k]>0)g=0;
					}
					if(g){
						rep(k,num)d[j+k]=17*(v%2)+3*(v%3)+19;
					}
				}
			}
			if(!g)break;
			q.pop();
			n[v]=t-v*5;
			cnt++;
		}
		rep(i,17)if(d[i]>0)d[i]--;
	}
	while(~scanf("%d",&t))printf("%d\n",n[t]);
	return 0;
}