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<stdio.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int, P > PP;
int n,ans[100];
PP t[500];
PP u[500];
int ts,te,us,ue;
int state[17];

void t_in(PP x){
  t[te]=x;
  te++;
}
void u_in(PP x){
  u[ue]=x;
  ue++;
}
PP t_out(){
  ts++;
  return t[ts-1];
}
PP u_out(){
  us++;
  return u[us-1];
}


int u_check(){
  int a = u[us].second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	return 1;
      }
    }else{
      cnt=0;
    }
  }
  return 0;
}

int u_ins(){
  int a = u[us].second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	for(int j=i;j>i-b;j--){
	  state[j]=a;
	}
	break;
      }
    }else{
      cnt=0;
    }
  }

  
  u_out();
  return a;
}
int u_check2(PP x){
  int a = x.second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	return 1;
      }
    }else{
      cnt=0;
    }
  }
  return 0;
}
void u_ins2(PP x){
  int a = x.second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	for(int j=i;j>i-b;j--){
	  state[j]=a;
	}
	break;
      }
    }else{
      cnt=0;
    }
  }
}

int main(){
  ts=us=te=ue=0;

  for(int i=0;i<100;i++)ans[i]=0;
  for(int i=0;i<17;i++)state[i]=-1;

  for(int i=0;i<100;i++){
    t_in(PP(5*i,P(1,i)));
  }

  sort(t+ts,t+te);

  PP x,y;
  int flg,z;
  while(!(ts==te)){

    /*
    for(int i=0;i<17;i++)printf("%3d ",state[i]);
    cout<<endl;

    for(int i=us;i<ue;i++)printf("%3d ",u[i].second.second);
    cout<<endl;
    */
    
    sort(t+ts,t+te);
    y=x;
    x=t_out();

    //cout<<x.first<<' '<<x.second.first<<' '<<x.second.second<<endl;
    for(int i=us;i<ue;i++)ans[u[i].second.second]+=(x.first-y.first);

    if(x.second.first==0){
      for(int i=0;i<17;i++)if(state[i]==x.second.second)state[i]=-1;
      while(1){
	if(us==ue)break;
	flg=u_check();
	if(flg==0)break;
	z=u_ins();
	
	t_in(PP(x.first+(17*(z%2)+3*(z%3)+19),P(0,z)));
      }
            
    }else if(x.second.first==1){
      flg=u_check2(x);

      if(flg==0||us!=ue){
	u_in(x);
      }else{
	u_ins2(x);

	z=x.second.second;
	t_in(PP(x.first+(17*(z%2)+3*(z%3)+19),P(0,z)));
      }
    }//if
  }

  
  //cout<<te<<endl;
  while(cin>>n){
    for(int i=n;i<=n;i++)cout<<ans[i]<<' ';
    cout<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
struct cus
{
	int a,b,c,d;
};

int main()
{
	cus a[100];
	for(int i=0;i<100;i++)
	{
		a[i].a=5*i;
		a[i].b=(i%5==1?5:2);
		a[i].c=17*(i%2)+3*(i%3)+19;
		a[i].d=0;
	}
	int t[20]={};
	for(int i=0;i<100;i++)
	{
		//for(int j=0;j<17;j++)printf("%3d",t[j]);
		//cout<<endl;
		int k=max(a[max(0,i-1)].d,a[i].a);
		for(;;k++)for(int j=0;j<17-a[i].b;j++)
		{
			bool x=true;
			for(int l=j;l<j+a[i].b;l++)
			{
				if(t[l]>k)x=false;
			}
			if(x)
			{
				for(int l=j;l<j+a[i].b;l++)
				{
					t[l]=k+a[i].c;
				}
				a[i].c=k-a[i].a;
				a[i].d=k;
				goto end;
			}
		}
		;end:;
	}
	int n;
	while(cin>>n)
	{
		cout<<a[n].c<<endl;
	}
}

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

const int MAX_SIZE = 100;
const int SEATS = 17;

int* calc() {
  queue<int> q;
  int *a = new int[MAX_SIZE]();
  int g, n, s[SEATS] = {};
  for (int t = 0; ; ++t) {
    for (int i = 0; i < SEATS; ++i) {
      if (s[i]) s[i]--;
    }
    if (t % 5 == 0) q.push(t / 5);
    while (!q.empty()) {
      bool c = false;
      g = q.front();
      n = g % 5 == 1 ? 5 : 2;
      for (int i = 0; i < SEATS - n; ++i) {
        if (n == 2 && !(s[i] || s[i + 1])) {
          s[i] = s[i + 1] = 17 * (g % 2) + 3 * (g % 3) + 19;
          c = true;
          break;
        }
        if (n == 5 && !(s[i] || s[i + 1] || s[i + 2] || s[i + 3] || s[i + 4])) {
          s[i] = s[i + 1] = s[i + 2] = s[i + 3] = s[i + 4] = 17 * (g % 2) + 3 * (g % 3) + 19;
          c = true;
          break;
        }
      }
      if (c) {
        a[g] = t - g * 5;
        if (g == MAX_SIZE - 1) return a;
        q.pop();
      } else {
        break;
      }
    }
  }
  return a;
}

int main() {
  int n;
  int *a = calc();
  while (true) {
    cin >> n;
    if (cin.eof()) break;
    cout << a[n] << endl;
  }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define N 100
typedef long long ll;
typedef pair<int,int>P;
typedef struct D{int t,n,e;bool operator <(const D &a)const{ return t>a.t;}};
priority_queue<D>F;
int r[N],s[20],w=0;

int ch(int n)
{
	for(int i=0;i<17;i++)
		if(s[i]==-1)
		{
			int j;
			for(j=0;j<n&&i+j<17;j++)if(s[i+j]!=-1)break;
			if(j==n)return i;
		}
	return -1;
}

int main()
{
	memset(s,-1,sizeof(s));
	for(int i=0;i<N;i++)
	{
		D tmp={i*5,i,0};
		F.push(tmp);
	}
	while(!F.empty())
	{
		D n=F.top();F.pop();
		if(n.e)
		{
			for(int i=0;i<17;i++)
				if(s[i]==n.n)s[i]=-1;
		}
		else
		{
			if(w<n.n)
			{
				n.t++;
				F.push(n);
				continue;
			}
			int a=n.n%5==1?5:2,b=ch(a);
			if(b!=-1)
			{
				for(int j=0;j<a;j++)
					s[b+j]=n.n;
				r[n.n]=n.t-5*n.n;
				w=n.n+1;
				D tmp={n.t+19+17*(n.n%2)+3*(n.n%3),n.n,1};
				F.push(tmp);
			}
			else
			{
				n.t++;
				F.push(n);
			}
		}
	}
	for(;~scanf("%d",&w);)printf("%d\n",r[w]);
	return 0;
}

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

main(){
  int data[100][2], ans[101];
  int seki[17], q=0;
  for(int i=0;i<100;i++){
    if(i%5==1){
      data[i][0]=5;
    }
    else{
      data[i][0]=2;
    }
    data[i][1]=17*(i%2)+3*(i%3)+19;
  }
  for(int i=0;i<17;i++){
    seki[i]=0;
  }
  
  for(int i=0;i<1000;i++){
    // printf("!%d! ", i);
    for(int j=0;j<17;j++){
      //printf("%2d ", seki[j]);
    }
    //printf("\n");
    for(int j=0;j<17;j++){
      if(seki[j]>0){
	seki[j]--;
      }
    }

    while(q<=i/5){
      int tmp=q;
      if(data[q][0]==2){
	for(int j=0;j<16;j++){
	  if(seki[j]==0 && seki[j+1]==0){
	    seki[j]=seki[j+1]=data[q][1];
	    ans[q]=i-q*5;
	    q++;
	    break;
	  }
	}
      }
      else{
	for(int j=0;j<13;j++){
	  if(seki[j]==0 && seki[j+1]==0 && seki[j+2]==0 && seki[j+3]==0 && seki[j+4]==0){
	    seki[j]=seki[j+1]=seki[j+2]=seki[j+3]=seki[j+4]=data[q][1];
	    ans[q]=i-q*5;
	    q++;
	    break;
	  }
	}
      }
      if(tmp==q) break;
    }
  }
  
  int n;
  while(cin >> n){
    cout << ans[n] << endl;
  }
  
  return 0;
}