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>
 
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<S> _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 <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

struct Chair{
	int group_id,rest_time;
};

struct Info{
	int group_id,num,wait_sum,before_go;
	bool fixed;
};


int main(){

	int ans[100];

	Chair chair[17];
	for(int i = 0; i < 17; i++)chair[i].group_id = -1;
	Info info[100];
	for(int 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;
	}

	int count;
	int FLG,tmp_num;
	bool isOK,waitFLG;

	while(true){

		for(int 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(int 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(int k = 0; k <= 17-tmp_num;k++){
					isOK = true;
					for(int 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(int 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(int i = 0; i <= 99; i++){
		ans[i] = info[i].wait_sum;
	}

	int N;

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

    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define f(a)(a%5==1?5:2)
using namespace std;
typedef pair<int, int>P;//?????????????????????,??????????????????

int c[17];
int cnt[100];
int main() {
	memset(c, -1, sizeof(c));
	priority_queue<P, vector<P>, greater<>>p;
	queue<int>que;
	int time = 0;
	while (1) {
		if (que.empty() && (time / 5 + 1) * 5 >= 100)break;
		if (time % 5 == 0 && time / 5 < 100)que.push(time / 5);
		while (!p.empty() && p.top().first <= time) {
			replace(c, c + 17, p.top().second, -1);
			p.pop();
		}
		bool flag = true;
		while (flag && !que.empty()) {
			int id = que.front();
			flag = false;
			rep(i, 17 - f(id)) {
				bool ok = true;
				rep(j, f(id)) {
					if (~c[i + j])ok = false;
				}
				if (ok) {
					rep(j, f(id))c[i + j] = id; que.pop();
					cnt[id] = time - 5 * id;
					p.push(P(time + 17 * (id % 2) + 3 * (id % 3) + 19, id));
					flag = true;
					break;
				}
			}
		}
		int Min = INT_MAX;
		if (!p.empty())Min = p.top().first;
		Min = min(Min, (time / 5 + 1)*5);
		time = Min;
	}
	int n; while (~scanf("%d", &n))printf("%d\n", cnt[n]);
}