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 <bits/stdc++.h>
using namespace std;


int d[100][5]={0};//来店時刻/人数/食事時間/着席時間/待ち時間/
int wait=0;//待っている客の番号
int Min=0;//現在時間

int isu[17]={0};
int isu_chk(int num){
	int tmp=0;
	for(int i=0;i<17;i++){
		if(isu[i]==-1)tmp++;
		else tmp=0;
		if(tmp>=num)return i-num+1;
	}
	return -1;
}
void tyaku(int pos,int name){
	for(int i=0;i<d[name][1];i++){
		isu[pos+i]=name;
	}
}
void update(){
	for(int i=0;i<17;i++){
		if(isu[i]<0)continue;
		if(Min>=d[isu[i]][2]+d[isu[i]][3]){
			isu[i]=-1;
		}
	}
}


void init(){
	for(int i=0;i<17;i++)isu[i]=-1;
	for(int i=0;i<100;i++){
		d[i][0]=5*i;
		d[i][1]=(i%5==1?5:2);
		d[i][2]=17*(i%2)+3*(i%3)+19;
		d[i][3]=-1;
		d[i][4]=-1;
		//cout<<i<<"\t"<<d[i][0]<<"\t"<<d[i][1]<<"\t"<<d[i][2]<<"\n";
	}
	
	for(;wait<100;Min++){
		update();
		while(true){
			if(Min<d[wait][0])break;
			if(isu_chk(d[wait][1])==-1)break;
			d[wait][3]=Min;
			d[wait][4]=Min-d[wait][0];
			tyaku(isu_chk(d[wait][1]),wait);
			wait++;
			if(wait>=100)break;
		}
	}
}

int main(){
	init();
	
	for(int n;cin>>n;)cout<<d[n][4]<<endl;
	
	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>=10){};
	
}

C++: #include <iostream>
#include <queue>

using namespace std;

struct C {
    int n;
    C() {}
    C(int n) : n(n) {}
    int x() {
        return (n % 5 == 1 ? 5 : 2);
    }
    int time() {
        return 17 * (n % 2) + 3 * (n % 3) + 19;
    }
    int arrival() {
        return n * 5;
    }
};

#define INF (1000000)

int T[100];
int S[17];

bool isEmpty(int t, int x) { // is there x consecutive empty seat after t minutes later
    for (int i = 0; i < 17 - x + 1; i++) {
        bool xEmpty = true;
        for (int j = 0; j < x; j++) {
            if (S[i+j] > t) {
                xEmpty = false;
                break;
            }
        }
        if (xEmpty) {
            return true;
        }
    }
    return false;
}

void fillSeat(int t, C c) {
    int x = c.x();
    for (int i = 0; i < 17 - x + 1; i++) {
        bool xEmpty = true;
        for (int j = 0; j < x; j++) {
            if (S[i+j] > t) {
                xEmpty = false;
                break;
            }
        }
        if (xEmpty) {
            for (int j = 0; j < x; j++) {
                S[i+j] = t + c.time();
            }
            return;
        }
    }
    cerr << "Something wrong." << endl;
}

int seat(C c) {
    int lb = -1, ub = INF;
    while (lb + 1 != ub) {
        int mid = (lb + ub) / 2;
        if (isEmpty(mid, c.x())) {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    //cout << c.n << " " << ub << endl;
    //for (int i = 0; i < 17; i++) cout << S[i] << ' '; cout << endl;
    int t = max(c.arrival(), ub);
    fillSeat(t, c);
    return t;
}

void init() {
    queue<C> q;
    for (int i = 0; i < 100; i++) {
        q.push(C(i));
    }
    while (!q.empty()) {
        C c = q.front(); q.pop();
        T[c.n] = seat(c);
        if (c.x() == 5) {
            // dirty hack
            for (int i = 0; i < 17; i++) {
                S[i] = max(S[i], T[c.n]);
            }
        }
    }
}

int main() {
    int n;
    init();
    while (cin >> n) {
        cout << T[n] - C(n).arrival() << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <map>
#include <queue>
using namespace std;
 
 int main() {
  int i=0,j,k=0,m,n,t=0,s[17],ad[200],len[200],ans[200];
  multimap<int,int> mp;
  queue<int> qu; ans[99]=-1;
  for (k=0;k<17;k++) s[k]=0;
  while(true) {
  if (!mp.empty()) {  
      if ((*mp.begin()).first==t) {
         while(!mp.empty() && (*mp.begin()).first == t) {
	     m=(*mp.begin()).second;
	     for (j=ad[m]; j<ad[m]+len[m]; j++) s[j]=0;
		 mp.erase(mp.begin()); }
	    }
  }
  if (t % 5==0) { i=t/5; qu.push(i); len[i]=i % 5==1 ? 5 : 2;}
  while(!qu.empty()) {
	  i=qu.front(); 
	  for (j=0;j<18-len[i];j++) {
		  for (k=0;k<len[i];k++) if (s[j+k]>0) break;
		  if (k==len[i]) {for (k=0;k<len[i];k++) s[j+k]=i+1;
		                 ans[i]=t-5*i; ad[i]=j;
						 qu.pop(); mp.insert(multimap<int,int>::value_type(t+17*(i % 2)+3*(i % 3)+19,i)); break;}
	  }
      if (j==18-len[i]) break;
  }
  t++;
  if (ans[99]>=0) break;
  }
  while(cin >> n) cout << ans[n] << endl;
  return 0;
 }

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    vector<int> seat(17, -1);
    multimap<int, int> leave;

    vector<int> waitTime(100);
    int time = 0;
    for(int i=0; i<100; ++i){
        while(leave.size() > 0 && leave.begin()->first <= 5*i){
            replace(seat.begin(), seat.end(), leave.begin()->second, -1);
            leave.erase(leave.begin());
        }

        time = max(time, 5*i);
        int num = (i%5==1? 5:2);
        vector<int> tmp(num, -1);
        for(;;){
            int j = search(seat.begin(), seat.end(), tmp.begin(), tmp.end()) - seat.begin();
            if(j == 17){
                time = leave.begin()->first;
                replace(seat.begin(), seat.end(), leave.begin()->second, -1);
                leave.erase(leave.begin());
            }else{
                for(int k=0; k<num; ++k)
                    seat[j+k] = i;
                break;
            }
        }

        waitTime[i] = time - 5*i;
        leave.insert(make_pair(time + 17*(i%2) + 3*(i%3) + 19, i));
    }

    for(;;){
        int n;
        if(!(cin >> n))
            return 0;
        cout << waitTime[n] << endl;
    }
}