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<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); 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()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int Time[100];// = {  0,  5, 10, 15, 20, 25, 30, 35, 40, 45};
int peop[100];// = {  2,  5,  2,  2,  2,  2,  5,  2,  2,  2};
int eats[100];// = { 19, 39, 25, 36, 22, 42, 19, 39, 25, 36};
int star[100];
int tabl[17];
int ans[100];

int main(){
  int next = 0;
  REP(i,100){
    Time[i] = 5 * i;
    peop[i] = (i%5 == 1 ? 5 : 2);
    eats[i] = 17*(i%2) + 3*(i%3) + 19;
  }

  REP(i,17) tabl[i] = -1;
  for(int i=0; ; i++){
    REP(j,17) if(tabl[j] != -1){
      int t = tabl[j];
      if(star[t] + eats[t] == i){
        tabl[j] = -1;
      }
    }

  loop:
    if(next == 100) goto end;
    if(Time[next] <= i){
      int cnt = 0;
      int st  = -1;
      REP(j,17){
        if(tabl[j] == -1){
          if(cnt == 0) st = j;
          cnt++;
          if(cnt == peop[next])
            break;
        }else cnt = 0;
      }
      if(cnt == peop[next]){
        ans[next] = i - Time[next];
        star[next] = i;
        REP(j,peop[next])
          tabl[st + j] = next;
        next++;
        goto loop;
      }
    }

    /*
    printf("%d: ",i);
    REP(j,17){printf("%3d ",tabl[j]);} puts("");
    getchar();
    */
  }

 end:
  int n;
  while(~scanf("%d",&n))
    print(ans[n]);

  return 0;
}

C++: #include<vector>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int seat[17];
vector<int> rm[5000];
queue<int> q;
int result[100];

int ck(int c){
	c=c%5==1?5:2;
	int suc=0;
	rep(i,17){
		if(seat[i]==-1){
			suc++;
			if(suc==c)return i-suc+1;
		}
		else suc=0;
	}
	return -1;
}
void in(int c,int p,int t){
	int n=c%5==1?5:2;
	rep(i,n)seat[i+p]=c;
	rm[5*c+17*(c%2)+3*(c%3)+19].push_back(c);
	result[c]=t-5*c;
	q.pop();
}
void remove(int c){
	rep(i,17)if(seat[i]==c)seat[i]=-1;
}
int main(){
	rep(i,17)seat[i]=-1;
	
	for(int t=0;t<=45||!q.empty();t++){
		if(t%5==0)q.push(t/5);
		rep(i,rm[t].size())remove(rm[t][i]);
		if(q.empty())continue;
		for(int p=ck(q.front());p>=0&&!q.empty();p=ck(q.front()))in(q.front(),p,t);
	}
	
	int n;
	while(cin>>n)cout<<result[n]<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define MAX 100

struct info{
  int g, t;
  info(int g, int t) : g(g), t(t) {}
};

int arr[MAX];
vector<info> seat;

int minite(int i){
  return 17*(i%2) + 3*(i%3) + 19;
}

void make(){
  int g = 0;
  for(int i = 0 ; i < 17 ; i++){
    seat.push_back(info(-1,-1));
  }
  vector<info> _wait;
  for(int i = 0 ; i < 570 ; i++){
    int size = _wait.size();

    if(size){
      for(int j = 0 ; j < size ; j++){
        _wait[j].t++;
      }
    }
   
    for(int j = 0 ; j < 17 ; j++){
      if(seat[j].g != -1){
        seat[j].t--;
        if(seat[j].t == 0){
          seat[j].g = seat[j].t = -1;
        }
      }
    }
 
    if(size){
      for(int j = 0 ; j < size ; j++){
        int n = _wait[j].g;
        int cnt, c;
        bool flg = false;
        if(n % 5 == 1) cnt = c = 5;
        else cnt = c = 2;
        for(int k = 0 ; k < 17 ; k++){
          if(seat[k].g == -1) cnt--;
          else cnt = c;
          if(cnt == 0){
            for(int l = k-c+1 ; l <= k ; l++){
              seat[l].g = n;
              seat[l].t = minite(n);
            }
            arr[n] = _wait[j].t;
            flg = true;
            j--;
            _wait.erase(_wait.begin());
            break;
          }
        }
        if(!flg || !_wait.size()) break;
      }
      size = _wait.size();
    }
    if(g == 100) continue;
    if(i % 5 == 0){
      int cnt = 0;
      bool flg = false;
      if(size){
        _wait.push_back(info(g,0));
        g++;
        continue;
      }
      if(g % 5 != 1){
        for(int j = 0 ; j < 17 ; j++){
          if(seat[j].g == -1) cnt++;
          else cnt = 0;
          if(cnt == 2){
            flg = true;
            for(int k = j-1 ; k <= j ; k++){
              seat[k].g = seat[k].g = g;
              seat[k].t = seat[k].t = minite(g);
            }
            arr[g] = 0;
            break;
          }
        }
      }else{
        for(int j = 0 ; j < 17 ; j++){
          if(seat[j].g == -1) cnt++;
          else cnt = 0;
          if(cnt == 5){
            flg = true;
            for(int k = j-4 ;  k <= j ; k++){
              seat[k].g = seat[k].g = g;
              seat[k].t = seat[k].t = minite(g);
            }
            arr[g] = 0;
            break;
          }
        }
      }
 
      if(!flg){
        _wait.push_back(info(g,0));
      }
      g++;
    }
  }
}

int main(){
  int N;

  make();
  while(cin >> N){
    cout << arr[N] << endl;
  }

  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
  int i,j,k,n,ans,x,a[17],st[100],sst[100],gt[100];
  while(cin >> n){
    ans = 0;
    for(i=0;i<17;i++) a[i] = -1;
    sst[0] = st[0] = 0;
    gt[0] = 0;
    for(i=1;i<100;i++){
      sst[i] = st[i] = i * 5;
      gt[i] = 0;
    }

    x = 0;
    for(i=0;i<=sst[n];i++){

      //for(j=0;j<17;j++) printf("%2d ",a[j]);
      //cout << endl;

      for(j=0;j<100;j++){
	if(gt[j] > 0 && gt[j] == i){
	  for(k=0;k<17;k++){
	    if(a[k] == j) a[k] = -1;
	  }
	}
      }
      
      while(i == sst[x]){
	int c=0;
	
	for(j=0;j<17;j++){
	  if(a[j] == -1) c++;
	  else c = 0;
	  if(x % 5 == 1 && c == 5 || x % 5 != 1 && c == 2) break;
	}
	
	if(j == 17) break;

	for(k=j;k>j-c;k--) a[k] = x;
	gt[x] = sst[x] + 17*(x%2) + 3*(x%3) + 19;
	x++;
      }
      for(j=x;j<100;j++){
	if(st[j] <= i) sst[j]++;
	else break;
      }
    }

    cout << sst[n] - st[n] << endl;
    
  }
  return 0;
}