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 <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef vector<double> vd;
typedef vector<vd> vvd;

int main()
{
	int seat[17] = {0};
	int answer[100];
	int sit = 0;
	deque<int> que;
	
	for(int i=0; sit<100; ++i){
		rep(j, 17)
			if(seat[j]) --seat[j];
		if(i%5 == 0)
			que.push_back(i/5);
		
		while(!que.empty()){
			int g = que.front();
			int n = g % 5 == 1 ? 5 : 2;
			int pos = search_n(seat, seat+17, n, 0) - seat;
			if(pos == 17)
				break;
			fill_n(seat+pos, n, 17*(g%2) + 3*(g%3) + 19);
			answer[que.front()] = i - g * 5;
			que.pop_front();
			++sit;
		}
	}

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

	return 0;
}

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

int ans[100];

class G{
public:
	int id,n,a,d; //O[vÔ,l,,HÔ

	G(int i){
		id = i;
		n = (i % 5 == 1 ? 5 : 2);
		a = 5 * i;
		d = 17 * (i % 2) + 3 * (i % 3) + 19;
	}
};

//nlA±ÅÈðmÛÅ«éêðÔ·
int indexOfSeat(int *seat,int n){
	int count = 0;

	for(int i=0;i<17;i++){
		if(!seat[i]){
			count++;
			if(count == n) return i - n + 1;
		}
		else{
			count = 0;
		}
	}

	return -1;
}

void solve(void){
	vector<G> v; //Ò¿sñ
	for(int i=0;i<100;i++) v.push_back(G(i));

	int time = 0; //»ÝÌ
	int seat[17]; //Èîñ
	memset(seat,0,sizeof(seat));

	while(!v.empty()){
		while(!v.empty() && v[0].a<=time){
			int idx = indexOfSeat(seat,v[0].n);
			if(idx != -1){
				for(int i=idx;i<idx+v[0].n;i++) seat[i] = v[0].d;
				ans[v[0].id] = time - v[0].a;
				v.erase(v.begin());
			}
			else{
				break;
			}
		}

		time++;
		for(int i=0;i<17;i++) if(seat[i] > 0) seat[i]--;
	}
}

int main(void){
	solve();

	int n;
	while(cin>>n) cout<<ans[n]<<endl;

	return 0;
}

C++: #include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int main() {
	int n, cntdwn[17]={}, ans[100];
	queue<int> q;
	for (int m=0; m<600; ++m) {
		if (m%5==0 && m/5<100) q.push(m/5);
		for (int i=0; i<17; ++i) --cntdwn[i];
		while ( ! q.empty()) {
			int num = (q.front()%5==1 ? 5 : 2);
			int c = 0, k = -1;
			for (int i=0; i<17; ++i) {
				c = (cntdwn[i]<=0 ? c+1 : 0);
				if (c==num) {
					k = i-num+1;
					break;
				}
			}
			if (k < 0) break;
			for (int i=k; i<k+num; ++i) {
				cntdwn[i] = 17*(q.front()%2)+3*(q.front()%3)+19;
			}
			ans[q.front()] = m-5*q.front();
			q.pop();
		}
	}
	while (cin >> n) {
		cout << ans[n] << endl;
	}
	return 0;
}

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

using namespace std;

#define MAX 100

struct info{
  int g, t;
  info(int g, int t) : g(g), t(t) {}
};

int arr[MAX];
vector<info> seat;

int minite(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(info(-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 = minite(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(info(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 = minite(g);
          }
          arr[g] = 0;
          break;
        }
      }
      if(!flg){
        _wait.push_back(info(g,0));
      }
      g++;
    }
  }
}

int main(){
  int N;

  make();
  while(cin >> N){
    cout << arr[N] << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <deque>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

int chair[17];
int ans[100];

//øÌA±µÄ¢éÀÈÌÅ¬ÔðÔ·
int isempty(int arg){
	int ret=-1;
	int num=0;
	int maxi = 0;
	int begin=0;
	for(int i=0;i<17;i++){
		if(chair[i] == 0){
			if(num == 0) begin = i;
			num++;
		}else{
			if(num >= arg) return begin;
			num = 0;
		}
	}
	if(num >= arg) return begin;
	return -1;
}

int main(){
	memset(chair, 0, sizeof(chair));
	deque<int> waiting;
	for(int t=0;t<600;t++){
		int n;
		for(int i=0;i<17;i++){
			if(chair[i] != 0) chair[i]--; //cèÔð¸ç·
		}
		if(t%5 == 0){ //q`FbN
			waiting.push_back(t/5);
		}
		while(!waiting.empty()){ //È`FbN
			if(waiting.front()%5==1){
				n=5;
			}else{
				n=2;
			}
			int place = isempty(n);
			if(place == -1) break;
			//ÈÉÂ¯é
			for(int j=0;j<n;j++){
				chair[place+j] = 17 * (waiting.front()%2) + 3 * (waiting.front()%3) + 19;
			}
			ans[waiting.front()] = t - waiting.front() * 5;
			waiting.pop_front();
		}
	}
	int q;
	
	while(cin >> q){
		cout << ans[q] << endl;
	}
}