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>
 
using namespace std;
 
#define MAX 100
 
struct S{
  int g, t;
  S(int g, int t) : g(g), t(t) {}
};
 
int arr[MAX];
vector<S> seat;
 
int minute(int i){
  return 17*(i%2) + 3*(i%3) + 19;
}
 
void make(){
  int g = 0;
  for(int i = 0 ; i < 17 ; i++){
    seat.push_back(S(-1,-1));
  }
  vector<info> _wait;
  for(int i = 0 ; i < 570 ; i++){
    int size = _wait.size();
 
    if(size){
      for(int j = 0 ; j < size ; j++){
        _wait[j].t++;
      }
    }
    
    for(int j = 0 ; j < 17 ; j++){
      if(seat[j].g != -1){
        seat[j].t--;
        if(seat[j].t == 0){
          seat[j].g = seat[j].t = -1;
        }
      }
    }
  
    if(size){
      for(int j = 0 ; j < size ; j++){
        int n = _wait[j].g;
        int cnt, c;
        bool flg = false;
        if(n % 5 == 1) cnt = c = 5;
        else cnt = c = 2;
        for(int k = 0 ; k < 17 ; k++){
          if(seat[k].g == -1) cnt--;
          else cnt = c;
          if(cnt == 0){
            for(int l = k-c+1 ; l <= k ; l++){
              seat[l].g = n;
              seat[l].t = minute(n);
            }
            arr[n] = _wait[j].t;
            flg = true;
            j--;
            _wait.erase(_wait.begin());
            break;
          }
        }
        if(!flg || !_wait.size()) break;
      }
      size = _wait.size();
    }
    if(g == 100) continue;
    if(i % 5 == 0){
      int cnt, c;
      bool flg = false;
      if(size){
        _wait.push_back(S(g,0));
        g++;
        continue;
      }
      if(g % 5 == 1) cnt = c = 5;
      else cnt = c = 2;
       
      for(int j = 0 ; j < 17 ; j++){
        if(seat[j].g == -1) cnt--;
        else cnt = c;
        if(cnt == 0){
          flg = true;
          for(int k = j-c+1 ;  k <= j ; k++){
            seat[k].g = seat[k].g = g;
            seat[k].t = seat[k].t = minute(g);
          }
          arr[g] = 0;
          break;
        }
      }
      if(!flg){
        _wait.push_back(S(g,0));
      }
      g++;
    }
  }
}
 
int main(){
  int N;
 
  make();
  while(cin >> N){
    cout << arr[N] << endl;
  }
 
  return 0;
}

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

int main() {
  vector<int> start(100);
  vector<int> number(100);
  for(int i = 0; i < 100; ++i) {
    start[i] = 5 * i;
    number[i] = (i % 5 == 1 ? 5 : 2);
    // t + 17*(i%2) + 3*(i%3) + 19;
  }
  vector<int> sheet(17, -1);
  vector<int> wait(100, -1);
  vector<int> end(100, -1);
  queue<int> que;
  for(int t = 0; ; ++t) {
    for(int i = 0; i < 100; ++i) {
      if(end[i] == t) {
        for(int j = 0; j < 17; ++j) {
          if(sheet[j] == i) sheet[j] = -1;
        }
      }
      if(start[i] == t) {
        que.push(i);
      }
    }
    while(!que.empty()) {
      int n = number[que.front()];
      int s = -1;
      for(int i = 0; i < 17; ++i) {
        int c = 0;
        for(int j = i; j < 17; ++j) {
          if(sheet[j] == -1) ++c;
          else break;
        }
        if(c >= n) {
          s = i;
          break;
        }
      }
      if(s != -1) {
        int k = que.front(); que.pop();
        for(int j = 0; j < n; ++j) {
          sheet[s + j] = k;
        }
        wait[k] = t - start[k];
        end[k] = t + 17*(k%2) + 3*(k%3) + 19;
      }
      else {
        break;
      }
    }
    bool f = true;
    for(int i = 0; i < 100; ++i) {
      if(end[i] == -1) f = false;
    }
    if(f) break;
  }
  for(int q; cin >> q; ) {
    cout << wait[q] << endl;
  }
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    vector<int> seat(17, -1);
    multimap<int, int> leave;

    vector<int> waitTime(100);
    int time = 0;
    for(int i=0; i<100; ++i){
        while(leave.size() > 0 && leave.begin()->first <= 5*i){
            replace(seat.begin(), seat.end(), leave.begin()->second, -1);
            leave.erase(leave.begin());
        }

        time = max(time, 5*i);
        int num = (i%5==1? 5:2);
        vector<int> tmp(num, -1);
        for(;;){
            int j = search(seat.begin(), seat.end(), tmp.begin(), tmp.end()) - seat.begin();
            if(j == 17){
                time = leave.begin()->first;
                while(leave.size() > 0 && leave.begin()->first == time){
                    replace(seat.begin(), seat.end(), leave.begin()->second, -1);
                    leave.erase(leave.begin());
                }
            }else{
                for(int k=0; k<num; ++k)
                    seat[j+k] = i;
                break;
            }
        }

        waitTime[i] = time - 5*i;
        leave.insert(make_pair(time + 17*(i%2) + 3*(i%3) + 19, i));
    }

    for(;;){
        int n;
        if(!(cin >> n))
            return 0;
        cout << waitTime[n] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;

struct Group{
	int indx, num;
	Group(){}
	Group(int indx_c, int num_c){
		indx = indx_c; num = num_c;
	}
};

int main(){
	int table[17] = {}, ans[100];
	queue<Group> q;
	for(int t = 0;; t++){
		for(int i = 0; i < 17; i++) table[i]--;
		
		if(t%5 == 0 && t/5 < 100){
			q.push( Group(t/5, ( (t/5)%5 == 1 ) ? 5 : 2 ) );
		}
		if( t/5 >= 100 && q.empty() ) break;
		
		while( !q.empty() ){
		
		Group front_group = q.front();
		int space_cnt = 0;
		bool was_pop = false;
		for(int i = 0; i < 17; i++){
			if( table[i] <= 0) space_cnt++;
			else space_cnt = 0;
			if(space_cnt >= front_group.num){
				for(int j = 0; j < space_cnt; j++){
					table[i-j] = 17*(front_group.indx%2)+3*(front_group.indx%3)+19;
				}
				ans[front_group.indx] = t - front_group.indx*5;
				q.pop();
				was_pop = true;
				break;
			}
		}
		
		if(was_pop == false) break;
		}
	}
	
	int N;
	while(cin >> N){
		printf("%d\n", ans[N]);
	}
	
	return 0;
}