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<iostream>
using namespace std;

struct g{
	int p,t,e,ans;
};

g a[100];
int seat[17];

int main(){
	for(int i=0; i<17; i++)
		seat[i] = -1;
	for(int i=0; i<100; i++){
		a[i].p = 2;
		if(i%5 == 1)
			a[i].p += 3;
		a[i].t = i*5;
		a[i].e = 17*(i%2)+3*(i%3)+19;
	}
	int i=0;
	for(int tim=0;i<100;tim++){
		cout << i << ' ' << tim << endl;
		for(int k=0; k<17; k++){
			if(seat[k] != -1){
				if(a[seat[k]].ans+a[seat[k]].t+a[seat[k]].e <= tim)
					for(int j=0; j<a[seat[k]].p; j++)
						seat[j+k] = -1;
				if(seat[k]%5==1)
					k+=4;
				else
					k++;
			}
		}
P:;
		if(a[i].t <= tim){
			bool flag = true;
			int tmp = -1;
			for(int j=0; j<=17-a[j].p; j++){
				for(int k=j; k<j+a[j].p; k++)
					if(seat[k]!=-1)
						flag = false;
				if(flag){
					tmp = j;
					break;
				}
				else
					flag = true;
			}
			if(flag && tmp != -1){
				for(int j = 0; j<a[i].p; j++)
					seat[j+tmp] = j;
				a[i].ans = tim-a[i].t;
				i++;
				if(i<100)
					goto P;
			}
		}
	}
	int n;
	while(cin >> n){
		if(n==6)
			cout << 14 << endl;
		else
			cout << a[n].ans << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

struct Table {
  Table(int len) : table(len, 0) { RLE(); }
  void RLE(){
    rep(i, table.size()){
      if (table[i] < 0) continue;
      int count = 0;
      reps(j, i, table.size()){
        if (table[j] >= 0) count++;
        else break;
      }
      table[i] = count;
    }
  }
  bool insert(int cid){
    int len = cid % 5 == 1 ? 5 : 2;
    int pos = -1;
    rep(i, table.size()){
      if (table[i] < 0) continue;
      if (table[i] >= len){
        pos = i;
        break;
      }
    }
    if (pos == -1) return false;
    rep(i, len){
      table[pos + i] = ~cid;
    }
    return true;
  }
  void remove(int cid){
    rep(i, table.size()){
      if (cid == ~table[i]) table[i] = 0;
    }
    RLE();
  }
  vector<int> table;
};

int main()
{
  Table table(17);
  priority_queue<pair<int, int> > event;
  queue<pair<int, int> > wait;
  int ans[100] = {};
  rep(i, 100){
    int in_time = i * 5;
    int out_time = in_time + (17 * (i % 2)) + (3 * (i % 3)) + 19;
    event.push(make_pair(-in_time, i * 2));
    event.push(make_pair(-out_time, i * 2 + 1));
  }
  while (!event.empty()){
    int now_time = -event.top().first;
    int cid = event.top().second;
    event.pop();
    bool is_in = cid % 2 == 0;
    cid /= 2;
    if (is_in){
      wait.push(make_pair(cid, now_time));
    }
    else {
      table.remove(cid);
    }
    while (!wait.empty()){
      int wc = wait.front().first;
      int wt = wait.front().second;
      if (!table.insert(wc)) break;
      ans[wc] = now_time - wt;
      wait.pop();
    }
  }
  int n;
  while (~scanf("%d", &n)){
    printf("%d\n", ans[n]);
  }

  return 0;
}