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<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int MS=17;
int mem[101],wait[101],eatingtime[101],seat[MS],hantei[6];

int main(){
  for(int i=0;i<100;i++){
    mem[i]=2;
    if(i%5==1){
      mem[i]=5;
    }
  }
  for(int i=0;i<100;i++){
    eatingtime[i]=17*(i%2)+3*(i%3)+19;
  }
  int time=0,n=0;
  while(n<100){
    for(int j=0;j<MS;j++){
      if(seat[j]>0){seat[j]--;}
    }
    /*    if(time<100){
      cout<<time;
      for(int gi=0;gi<MS;gi++)
	{
	  printf(" %d",seat[gi]);
	  if(gi==MS-1){cout<<endl;
	  }
	}
	}*/
      while((time+1)>(n*5))
	{
	for(int j=0;j<MS-1;j++)
	  {
	    for(int seki=0;seki<2;seki++){
	      if(seat[j+seki]!=0){break;}
	      if(seki==1){hantei[2]=1;hantei[0]=j;j=MS;}
	    }
	  }
	for(int j=0;j<MS-4;j++)
	  {
	    for(int seki=0;seki<5;seki++){
	      if(seat[j+seki]!=0){break;}
	      if(seki==4){hantei[5]=1;hantei[3]=j;j=MS;}
	    }
	  }
	if(hantei[mem[n]]==1){
	  wait[n]=time-(n*5);
	  for(int ji=0;ji<mem[n];ji++){
	    seat[hantei[mem[n]-2]+ji]=eatingtime[n];
	  }
	  n++;
	}
	if(hantei[mem[n]]==0){break;}
	hantei[2]=0;
	hantei[5]=0;

	}
      time++;
  }
  int t;
  while(~scanf("%d",&t)){
    printf("%d\n",wait[t]);
  }
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-3;
const double PI = acos(-1);

int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int ans[110], d[18];

int calc(int t, int m){
	vi v(18, 0);
	for(int i = 16; i >= 0; i--){
		if(d[i] <= t) v[i] = v[i+1]+1;
	}
	auto it = max_element(all(v));
	if(*it < m) return -1;
	return it-v.begin();
}

int main(){
	int n, t, idx;
	for(int i = 0; i < 100; i++){
		n = i%5==1?5:2;
		t = max(t,i*5);
		while(1){
			idx = calc(t, n);
			if(idx < 0) {
				t++;
				continue;
			}
			ans[i] = t - i*5;
			for(int j = 0; j < n; j++) d[idx+j] = t + 17*(i%2)+3*(i%3)+19;
			break;
		}
	}
	while(cin>>n){
		printf("%d\n", ans[n]);
	}
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

int main(){
  int wtime[100] ={};
  deque<int> deq;  
  int seat[17]={};
  int members[17];
  for(int t = 0; t <= 99*5 || !deq.empty(); t++){
    REP(i,17)if(seat[i] > 0)seat[i]--;
    if(t%5 == 0 && t <= 99*5) deq.push_back(t/5);
    while(!deq.empty()){
      int mem = deq.front();
      int nop = (mem%5==1)?5:2;
      int sitable = -1;
      for(int i = 0, con = 0; i < 17; i++){
        if(seat[i]==0)con++;
        else con = 0;
        if(con == nop){
          sitable = i + 1 - nop;
          break;
        }
      }
      if(sitable >= 0){
        deq.pop_front();
        REP(i,nop){
          seat[sitable+i] = 17*(mem%2)+3*(mem%3)+19;
          members[sitable+i] = mem;
        }
      }else{
        break;
      }
    }
    REP(i,deq.size())wtime[deq[i]]++;
    /*
    printf("%d:",t);
    REP(i,17)cout<< ((seat[i])?members[i]:0) <<" ";
    cout<<endl;
    */
  }
  int n;
  while(cin>>n)cout<<wtime[n]<<endl;
  return 0;
}

C++: #include<stdio.h>
int main(){
  int m[17]={0};
  int mathi[100]={0};
  int i,j,t,n,k,l,mt,s=0;
  for(t=0;1;t++){
    for(i=0;i<17;i++)m[i]--;
    while(s*5<=t){
      n=2;
      if(s%5==1)n=5;
      for(i=0;i<17;i++){
	if(m[i]<1){
	  for(j=0;j<n;j++){
	    if(m[i+j]>0)break;
	  }
	  if(j==n)break;
	}
      }
      if(j==n){
	mt=17*(s%2)+3*(s%3)+19;
	for(j=0;j<n;j++)m[i+j]=mt;
	mathi[s]=t-5*s;
	s++;
	j=-1;
      }
      else break;
      if(s==100)break;
    }
    if(s==100)break;
  }
  while(scanf("%d",&k)!=EOF){
    //for(k=0;k<100;k++){
    printf("%d\n",mathi[k]);
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int seat[17] = {0};
	int X = 0;
	int stop[100] = {0};
	int time = 0;
	queue<int> Q;
	while(X < 100){
		int x;
		if(time%5 == 0 && time < 500){
			Q.push(time/5);
		}
		while(1){
			if(Q.size())x = Q.front();
			else x = -1;
			bool f = false;
			
			if(~x){
				int people = (x%5==1?5:2);
				int use = 19 + 3 * (x%3) + 17 * (x%2);
				rep(i,17-people+1){
					bool flag = true;
					rep(j,people){
						flag &= seat[i+j] == 0;
					}
					if(flag){
						rep(j,people){
							seat[i+j] = use;
						}
						f = true;
						break;
					}
				}
			}
			if(f){	
				stop[x] = time - x * 5;
				Q.pop();
				X++;
			}
			if(!f)break;
		}
		rep(i,17){
			seat[i] = max(0,seat[i]-1);
		}
		time++;
	}
	int n,c=0;
	while(cin >> n){
		cout << stop[n] << endl;
		c++;
	}
	while(c>=7){};
	
}