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 "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

struct group {
	int id;
	int num;
	int time;
};

int cansit(const vector<int>&seats, int num) {
	for (int i = 0; i <= 17 - num; ++i) {
		bool ok = true;
		for (int j = i; j < i + num; ++j) {
			if (seats[j] != -1) {
				ok = false;
			}
		}
		if (ok)return i;
	}
	return -1;
}
void dosit(vector<int>&seats, int num, int place,int leavetime) {
	for (int i = place; i < place + num; ++i) {
		seats[i] = leavetime;
	}
}

int main() {
	int N;
	while (cin >> N) {
		queue<group>waiting;
		vector<int>seats(17,-1);
		vector<int>anss(100);
		for (int t = 0; (t<=1000||!waiting.empty()); ++t) {
			for (int i = 0; i < 17; ++i) {
				if (t == seats[i])seats[i] = -1;
			}
			if (!(t % 5)) {
				const int id = t / 5;
				if (id < 100) {

					const int num = id % 5 == 1 ? 5 : 2;
					const int time = 17 * (id % 2) + 3 * (id % 3) + 19;
					waiting.push(group{ id,num,time });
				}
			}
			while (!waiting.empty()) {
				group atop(waiting.front());
				int place = cansit(seats, atop.num);
				if (place != -1) {
					dosit(seats, atop.num, place,atop.time+t);
					anss[atop.id] = t - atop.id * 5;
					waiting.pop();
				}
				else {
					break;
				}
			}
		}

		cout << anss[N] << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main()
{
	int table[18];
	int wait[100];
	memset(table, -1, sizeof(table));
	memset(wait, 0, sizeof(wait));
	table[17] = 1;

	int front = 0;
	int len = 2;
	for (int i = 0; front < 100; ++i)
	{
		while (i >= front*5 && front < 100)
		{
			int l = 0;
			int p = -1;
			for (int j = 0; p == -1 && j < 17 + 1; ++j)
			{
				if (table[j] <= 0)
					++l;
				else
				{
					if (l >= len)
						p = j - l;
					l = 0;
				}
			}
			if (p != -1)
			{
				for (int j = 0; j < len; ++j)
					table[p+j] = 17*(front%2) + 3*(front%3) + 19;
				wait[front] = i - front*5;
				len = ++front % 5 == 1 ? 5 : 2;
			}
			else
				break;
		}
		for (int j = 0; j < 17; ++j)
			--table[j];
	}

	int n;
	while (scanf("%d", &n) != EOF)
		printf("%d\n", wait[n]);

	return 0;
}

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

#define fi first
#define se second

int main() {
	int chair[17] = {0};
	int ans[100];
	queue<pair<int,int> > customer;

	for(int clock = 0; clock <= 500 || !customer.empty(); clock++) {
		if(!(clock % 5) && clock < 500) {
			if((clock / 5) % 5 == 1)
				customer.push(pair<int,int>(clock / 5, 5));
			else
				customer.push(pair<int,int>(clock / 5, 2));
		}

		bool flg = true;
		while(flg && !customer.empty()) {
			int seq;
			pair<int,int> tmp;
			bool prev;

			flg = false;
			tmp = customer.front();
			seq = 0;
			for(int i = 0; i < 17; i++) {
				if(chair[i] <= clock)
					seq++;
				else
					seq = 0;
				if(seq >= tmp.se) {
					ans[tmp.fi] = clock - 5 * tmp.fi;
					for(int j = 0; j < tmp.se; j++) {
						chair[i - seq  + 1 + j] = 17 * (tmp.fi % 2) + 3 * (tmp.fi % 3) + 19 + clock;
					}
					customer.pop();
					flg = true;
					break;
				}
			}
		}
	}

	int q;
	while(cin >> q) {
		cout << ans[q] << endl;
	}
}

C++: #include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int d[17];
	int n[100]={0};
	int cnt=0,t=0;
	queue<int> q;
	rep(i,17)d[i]=0;
	for(;cnt<100;t++){
		rep(i,17)if(d[i]>0)d[i]--;
		if(t%5==0)q.push(t/5);
		while(!q.empty()){
			int v=q.front();
			int num=v%5==1?5:2;
			int g=0;
			rep(j,17-num){
				if(d[j]<1){
					g=1;
					reps(k,1,num-1){
						if(d[j+k]>0)g=0;
					}
					if(g){
						rep(k,num)d[j+k]=17*(v%2)+3*(v%3)+19;
					}
				}
				if(g)break;
			}
			if(!g)break;
			q.pop();
			n[v]=t-v*5;
			cnt++;
		}
	}
	while(~scanf("%d",&t))printf("%d\n",n[t]);
	return 0;
}