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 <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


const int INF = INT_MAX;

void solve( int n ) {
    int A[n+1], K[n+1], T[n+1];
    int BG[n+1];
    for ( int i = 0; i <= n; ++ i ) {
        A[i] = 5 * i;
    }
    for ( int i = 0; i <= n; ++ i ) {
        K[i] = ( i % 5 == 1 ) ? 5 : 2;
    }
    for ( int i = 0; i <= n; ++ i ) {
        T[i] = 17 * ( i % 2 ) + 3 * ( i % 3 ) + 19;
    }
    int U[17]; 
    fill( U, U+17, -1 );
    queue <int> Q;
    int cnt = 0;
    bool used[n+1];
    fill( used, used+n+1, false );
    for ( int t = 0; cnt <= n; ++ t ) {
        for ( int i = 0; i <= n; ++ i ) {
            if ( A[i] <= t ) {
                Q.push( i );
                A[i] = INF;
                BG[i] = t;
            }
        }
        for ( int i = 0; i < 17; ++ i ) {
            if ( U[i] == -1 ) continue;
            int id = U[i];
            if ( T[id] <= t ) {
                U[i] = -1;
                if ( ! used[id] ) {
                    cnt ++;
                    used[id] = true;
                }
            }
        }
        while ( ! Q.empty() ) {
            int id = Q.front();
            int k = K[id];
            bool flag2 = false;
            for ( int i = 0; i + k - 1 < 17; ++ i ) {
                bool flag = true;
                for ( int j = 0; j < k; ++ j ) {
                    if ( U[i+j] != -1 ) flag = false;
                }
                if ( flag ) {
                    for ( int j = 0; j < k; ++ j ) {
                        U[i+j] = id;
                    }
                    if ( n == id ) {
                        cout << t - BG[id] << endl;
                        return;
                    }
                    T[id] += t;
                    Q.pop();
                    flag2 = true;
                    break;
                }
            }
            if ( ! flag2 ) break;
        }
    }
    cout << endl;
}

int main() {
    int n;
    while ( cin >> n ) solve( n );
    return 0;
}

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

const int MAXN = 101;
const int W = 17;
int wait[MAXN];
int u[W];

void make() {
  fill(u, u+W, 0);
  queue<pair<int,int> > que;
  for(int t = 0, i = 0; i < 100 || que.size(); ++t) {
    if(i < 100 && t == 5*i) que.push(make_pair(i++, t));
    while(que.size()) {
      int k = que.front().first;
      int s = que.front().second;
      int x = k%5 == 1 ? 5 : 2;
      int d = 17 * (k%2) + 3*(k%3) + 19;

      int pos = -1;
      for(int j = 0; j+x <= W; ++j) {
        bool flag = true;
        for(int a = 0; a < x; ++a) {
          if(u[j+a] > t) {
            flag = false;
            break;
          }
        }
        if(flag) {
          pos = j;
          break;
        }
      }
      if(pos == -1) break;
      wait[k] = t - s;
      que.pop();
      for(int a = 0; a < x; ++a) u[pos+a] = t + d;
    }
  }
}

int main() {
  make();
  int n;
  while(cin >> n) {
    cout << wait[n] << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int d[17];
	int n[100]={0};
	int cnt=0,t=0,g;
	queue<int> q;
	vector<int> l;
	rep(i,17)d[i]=0;
	for(;t<30000;t++){
		rep(i,17)if(d[i]>0)d[i]--;
		if(t%5==0 && cnt < 100){
			l.push_back(cnt);
			q.push(cnt++);
		}
		g=1;
		while(!q.empty() && g){
			int v=q.front();
			int num=v%5==1?5:2;
			g=0;
			int f=1;
			rep(j,17-num){
				if(d[j]<1){
					reps(k,1,num-1)if(d[j+k]>0)f=0;
					if(f){
						q.pop();
						rep(k,num)d[j+k]=17*(v%2)+3*(v%3)+19;
						g=1;
					}
				}
				if(g)break;
			}
		}
		rep(i,l.size())if(!q.empty() && l[i]>=q.front())n[l[i]]++;
	}
	while(~scanf("%d",&t))printf("%d\n",n[t]);
	return 0;
}