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 <iostream>
#include <queue>
#include <vector>
#define mp make_pair
using namespace std;

struct P{ int tim,group,act; };

struct comp {
	bool operator()(P t1, P t2) const {
		if(t1.tim != t2.tim) return t1.tim > t2.tim;
		else return t1.act < t2.act;
 	}
};

int chair[17];

int emp(int num){
	for(int i = 0;i < 17 - num + 1;i++){
		bool flag = true;
		for(int j = 0;j < num;j++){
			if(chair[i + j] != -1) flag = false;
		}
		if(flag) return i;
	}
	return -1;
}

int main(){
	int n,front = -1,wait[100] = {};
	priority_queue<P,vector<P>,comp> que;
	queue<int> line;
	for(int i = 0;i < 17;i++) chair[i] = -1;
	for(int i = 0;i < 100;i++) que.push({i * 5,i,0});
	while(!que.empty()){
		P p = que.top();que.pop();
		int t = p.tim,group = p.group,act = p.act;
		if(act == 0){
			int num = 2,pos;
			if(group % 5 == 1) num = 5;
			pos = emp(num);
			if(!line.empty() || pos == -1) line.push(group);
			else{
				for(int i = 0;i < num;i++) chair[i + pos] = group;
				que.push({t + 17 * (group % 2) + 3 * (group % 3) + 19,group,1});
			}
		}else{
			for(int i = 0;i < 17;i++){
				if(chair[i] == group) chair[i] = -1;
			}
			while(!line.empty()){
				int g = line.front(),num = 2,pos;
				if(g % 5 == 1) num = 5;
				pos = emp(num);
				if(pos != -1){
					line.pop();
					wait[g] = t - g * 5;
					for(int i = 0;i < num;i++) chair[pos + i] = g;
					que.push({t + 17 * (g % 2) + 3 * (g % 3) + 19,g,1});
				}
				else break;
			}
		}
	}
	while(cin >> n){
		cout << wait[n] << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
#define SHEETS 17
#define GROUPS 130
int main()
{
	int ans[GROUPS] = {0,};
	int now;
	int sheets[SHEETS+1] = {-1,};
	int peoples[GROUPS] = {0,};
	int waiting[GROUPS] = {0,};
	int eating[GROUPS] = {0,};

	for(int i = 0; i < SHEETS+1; ++i){
		sheets[i] = -1;
	}
	sheets[SHEETS] = -2;
	for(int i = 0; i < GROUPS; ++i)
	{
		waiting[i] = -i*5;
		peoples[i] = i%5==1?5:2;
		eating[i] = 17*(i%2)+3*(i%3)+19;
	}
	now = 0;
	for(int t = 0; t < 800; ++t){

		/*
		if( t % 5 == 0 ){
			cout << t / 5 << "ツつウツづアツつェツδ債グツイツδ督つオツづ慊つオツつスツ。\n";
		}
		*/

		for(int i = 0; i < SHEETS; ++i){
			if( sheets[i] >= 0 ){
				--eating[sheets[i]];
				if( eating[sheets[i]] == 0 ){
					for(;sheets[i+1]==sheets[i];++i)
						sheets[i] = -1;
					//if( i < SHEETS )
						sheets[i]=-1;
				}else{
					for(;sheets[i+1]==sheets[i];++i)
						0;
				}
			}
		}

		while( true ){
			bool bCont = false;
			for(int i = 0; i < SHEETS; ++i){
				int cont = 0;
				if( sheets[i] < 0 ){
					for(int j = i; j < SHEETS; ++j){
						if( sheets[j] < 0 ) cont++;
						else break;
					}
					if( cont >= peoples[ now ] && waiting[ now ] >= 0 ){
						for(int j = i; j < i+peoples[now]; ++j)
							sheets[j] = now;
						ans[now] = waiting[now];//<0?0:waiting[now];
						++now;
						bCont = true;
					}
				}
			}
			if( !bCont )
				break;
		}
		for(int i = 0; i < GROUPS; ++i){
			++waiting[i];
		}
		
		/*for(int i = 0; i < SHEETS; ++i){
			cout << sheets[i] << ' ';
		}
		cout << endl;*/
	}
	/*
	for(int i = 0; i < GROUPS;++i){
		cout << ans[i] << ' ';
	}
	*/

	while(true){
		int n;
		cin >> n;
		if(cin.eof())
			break;
		cout << ans[n] << endl;
	}

	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999


int data[110];

queue<pii> ar(){
    queue<pii> ret;
    rep(i,100){
        ret.push(pii(i,i*5));
    }
    return ret;
}


queue<pii> de(){
    vector<pii> tmp;
    queue<pii> ret;
    rep(i,100){
        tmp.pb(pii(i*5+17*(i%2)+3*(i%3)+19,i));
    }
    sort(all(tmp));
    rep(i,100){
        ret.push(pii(tmp[i].second,tmp[i].first));
    }
    return ret;
}



int arr(pii f,int seat[20],queue<pii> &wait,int t){
    int members;
    if( (f.first)%5==1 )members = 5;
    else members = 2;
    
    int dp[20]={};
    for(int i=16;i>=0;i--){
        if(seat[i]==-1) dp[i]=0;
        else            dp[i] = dp[i+1]+1;
    }
    bool flag=false;
    rep(i,17){
        if(dp[i]>=members){
            for(int j=i;j<i+members;i++){
                seat[j] = f.first;
            }
            flag=true;
        }
    }
    if(!flag){
        wait.push( f );
        return -1;
    }
    data[f.first] = t;
    return 0;
}

void pre(){
    int seat[20];
    rep(i,17)seat[i]=-1;
    queue<pii> arrive = ar();
    queue<pii> dep = de();
    bool flag=true;
    int now=0;
    while(arrive.size()+dep.size()){
        if( flag==false || arrive.empty() || arrive.front().second>dep.front().second  ){ //??¢?????????
            int dep_group = dep.front().first;
            now =dep.front().second;
            dep.pop();
            rep(i,17){
                if( seat[i]==dep_group ) seat[i]=-1;
            }
            flag = true;
        }
        else{ //??¢?????\???
            pii f = arrive.front();
            int members;
            if( (f.first)%5==1 )members = 5;
            else members = 2;
            
            int dp[20]={};
            for(int i=16;i>=0;i--){
                if(seat[i]!=-1) dp[i] = 0;
                else            dp[i] = dp[i+1]+1;
            }
            
            flag = false;
            rep(i,17){
                if(dp[i]>=members){
                    for(int j=i;j<i+members;j++){
                        seat[j] = f.first;
                    }
                    flag=true;
                    arrive.pop();
                    data[f.first] = now;
                    break;
                }
            }
        }
    }
}


int main(){
    int n;
    
    pre();
    
    while(cin>>n){
        cout<<max( 0 , data[n]-5*n )<<endl;
    }
}