Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type chair struct {
	group_id, rest_time int
}

type info struct {
	group_id, num, wait_sum, before_go int
	fixed                              bool
}

func main() {
	ans := make([]int, 100)
	chair := make([]chair, 17)
	for i := 0; i < 17; i++ {
		chair[i].group_id = -1
	}
	info := make([]info, 100)
	for i := 0; i <= 99; i++ {
		info[i].group_id = i
		info[i].before_go = 5 * i
		info[i].wait_sum = 0
		if i%5 == 1 {
			info[i].num = 5
		} else {
			info[i].num = 2
		}
		info[i].fixed = false
	}
	count := 0
	FLG := 0
	tmp_num := 0
	isOK := false
	waitFLG := false
	for {
		for i := 0; i < 17; i++ {
			if chair[i].group_id != -1 {
				chair[i].rest_time--
				if chair[i].rest_time <= 0 {
					chair[i].group_id = -1
				}
			}
		}
		waitFLG = false
		count = 0
		for i := 0; i < 100; i++ {
			if info[i].fixed {
				continue
			}
			if waitFLG == false && info[i].before_go == 0 {
				FLG = -1
				tmp_num = info[i].num
				for k := 0; k <= 17-tmp_num; k++ {
					isOK = true
					for p := 0; p < tmp_num; p++ {
						if chair[k+p].group_id != -1 {
							isOK = false
							break
						}
					}
					if isOK {
						FLG = k
						break
					}
				}
				if FLG != -1 {
					for k := FLG; k < FLG+tmp_num; k++ {
						chair[k].group_id = info[i].group_id
						chair[k].rest_time = 17*(i%2) + 3*(i%3) + 19
						info[i].fixed = true
					}
				} else {
					waitFLG = true
					info[i].wait_sum++
					count++
				}
			} else {
				if info[i].before_go == 0 {
					info[i].wait_sum++
				} else {
					info[i].before_go--
				}
				count++
			}
		}
		if count == 0 {
			break
		}
	}
	for i := 0; i <= 99; i++ {
		ans[i] = info[i].wait_sum
	}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		fmt.Println(ans[n])
	}
}

C++: #include <cstdio>
#include <queue>
enum{W=17,Z=100};
main(){
	std::queue<int>q;
	std::vector<int>r,sheet(W);
	int t=0,i,j,l;
	for(;r.size()<Z;t++){
		if(t%5==0)q.push(t/5);
		for(i=0;i<W;i++)if(sheet[i])sheet[i]--;
		for(;!q.empty();q.pop()){
			l=q.front()%5==1 ? 5 : 2;
			for(i=0;i<=W-l;i++){
				for(j=0;j<l;j++)if(sheet[i+j])break;
				if(j==l)break;
			}
			if(i>W-l)break;
			for(j=0;j<l;j++)sheet[i+j]=17*(q.front()%2)+3*(q.front()%3)+19;
			r.push_back(t-q.front()*5);

		}
	}
	for(;~scanf("%d",&l);)printf("%d\n",r[l]);
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int N = 100;
const int T = 17;

void check(int cnt[N], P c[T], queue<int> &q, int &l, int &t){
  REP(i, T){
    if(c[i].first == -1) continue;
    int n = c[i].first;
    if(c[i].second + (17 * (n % 2) + 3 * (n % 3) + 19) == t){
      l = max(l, c[i].first);
      c[i] = P(-1, -1);
    }
  }
  while(!q.empty()){
    int n = q.front();
    int m = (n % 5 == 1 ? 5 : 2);
    bool ff = false;
    REP(i, T - m){
      bool f = true;
      REP(j, m) if(c[i + j].first != -1) f = false;
      if(f){
        cnt[n] = t - n * 5;
        REP(j, m) c[i + j] = P(n, t);
        ff = true;
        q.pop();
        break;
      }
    }
    if(!ff) break;
  }
}

int main() {
  int cnt[N], l = -1, t = 0;
  P c[T];
  memset(cnt, 0, sizeof(cnt));
  REP(i, T) c[i] = P(-1, -1);
  queue<int> q;
  while(l < N){
    if(t % 5 == 0) q.push(t / 5);
    check(cnt, c, q, l, t);
    ++t;
  }
  int n;
  while(cin >>n) cout <<cnt[n] <<endl;
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

const int N = 17;
int seat[N+1];
int ans[100];

void sim(){
	int t = 0;
	rep(i, 100){
		int num = i%5==1?5:2;
		if(t < 5*i){
			rep(j, N) seat[j] -= min(seat[j], 5*i-t);
			t = 5*i;
		}
		bool ok = false;
		while(1){
			int cnt = 0;
			rep(j, num) cnt += !!seat[j];
			rep(j, N+1-num){
				if(cnt == 0){
					FOR(k, j, j+num) seat[k] = 17*(i%2)+3*(i%3)+19;
					ans[i] = t-5*i;
					ok = true;
					break;
				}
				if(seat[j+num]) ++cnt;
				if(seat[j]) --cnt;
			}
			if(ok) break;
			int mint = 1<<29;
			rep(j, N) if(seat[j]) mint = min(mint, seat[j]);
			rep(j, N) if(seat[j]) seat[j] -= mint;
			t += mint;
		}
		//printf("\ntime:%d\nseat:", t);
		//rep(j, N) printf("%3d", seat[j]);
	}
}

int main(){
	sim();
	int n;
	while(cin >> n) cout << ans[n] << endl;

	return 0;
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int t[110];
int now[20];
int p[110];
int q[110];
int r[110];
int main(){
	for(int i=0;i<100;i++){
		p[i]=i*5;
		if(i%5==1)q[i]=5;
		else q[i]=2;
		r[i]=17*(i%2)+3*(i%3)+19;
	}
	int at=0;
	for(int i=0;i<17;i++)now[i]=-1;
	for(int i=0;i<5000;i++){
		for(int j=0;j<at;j++){
			if(i==t[j]+r[j])for(int k=0;k<17;k++)if(now[k]==j)now[k]=-1;
		}
		while(at<=min(99,i/5)){
			int len=0;
			bool ok=false;
			for(int j=0;j<17;j++){
				if(!~now[j])len++;
				else len=0;
				if(len==q[at]){
					for(int k=j-q[at]+1;k<=j;k++)now[k]=at;
					ok=true;break;
				}
			}
			if(ok)t[at++]=i;
			else break;
		}
	}int a;
	while(~scanf("%d",&a)){
		printf("%d\n",t[a]-a*5);
	}
}