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 <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int Brank(vint v, int num)
{
	rep(i, v.size() - num)
	{
		rep(j, num)
		{
			if(v[i + j] != -1) break;
			else if(j + 1 == num) return i;
		}
	}
	
	return -1;
}

int main()
{
    for(int n; cin >> n;)
	{
		queue<int>  que; // id
		vint store(16, -1); // time
		int nxt = 0, start;
		
		for(int time = 0; ; time++)
		{
			// ツ行ツ療アツづ可嘉つヲツづゥ
			if(time % 5 == 0)
			{
				if(nxt == n) start = time;
				
				que.push(nxt++);
			}
			
			// ツ店ツつゥツづァツ出ツつキ
			rep(i, 16)
				store[i] = (store[i] == time ? -1 : store[i]);
			
			// ツ店ツづ可禿シツづェツづゥ
			while(!que.empty())
			{
				int id = que.front();
				int num = (id % 5 == 1 ? 5 : 2);
				
				int index = Brank(store, num);
				
				if(index != -1)
				{
					if(id == n)
					{
						cout << time - start << endl;
						goto ng;
					}
					
					int span = 17 * (id % 2) + 3 * (id % 3) + 19; 
					REP(i, index, index + num) 
					{
						store[i] = time + span;
					}
					
					que.pop();
				}
				else 
				{
					break;
				}
			}
		}
		
	ng:;
		
	}
}

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;
}