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

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