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 <stdio.h>
#include <map>
#include <queue>
using namespace std;
 
 int main() {
  int i=0,j,k=0,m,n,t=0,s[17],ad[200],len[200],ans[200];
  multimap<int,int> mp;
  queue<int> qu; ans[99]=-1;
  for (k=0;k<17;k++) s[k]=0;
  while(true) {
  if (!mp.empty()) {  
      if ((*mp.begin()).first==t) {
         while(!mp.empty() && (*mp.begin()).first == t) {
	     m=(*mp.begin()).second;
	     for (j=ad[m]; j<ad[m]+len[m]; j++) s[j]=0;
		 mp.erase(mp.begin()); }
	    }
  }
  if (t % 5==0) { i=t/5; qu.push(i); len[i]=i % 5==1 ? 5 : 2;}
  while(!qu.empty()) {
	  i=qu.front(); 
	  for (j=0;j<18-len[i];j++) {
		  for (k=0;k<len[i];k++) if (s[j+k]>0) break;
		  if (k==len[i]) {for (k=0;k<len[i];k++) s[j+k]=i+1;
		                 ans[i]=t-5*i; ad[i]=j;
						 qu.pop(); mp.insert(multimap<int,int>::value_type(t+17*(i % 2)+3*(i % 3)+19,i)); break;}
	  }
      if (j==18-len[i]) break;
  }
  t++;
  if (ans[99]>=0) break;
  }
  while(cin >> n) cout << ans[n] << endl;
  return 0;
 }

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;
                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 <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  queue<int> Q;
  vector<int> seki(17);
  Q.push(0);
  int time = 0;
  int hoge[100];
  while(1) {
    REP(i, 17) if (seki[i]) seki[i]--;

    if (!Q.empty()) {
      int a = Q.front();
      if (a >= 100) break;
      //   cout << "a" << " " << a << endl;
    
      int num = a%5==1 ? 5 : 2;
      
      int tmp = 0;
      REP(i,17) {
        a = Q.front();
        if (a >= 100) break;
        if (seki[i] == 0) ++tmp;
        else tmp = 0;
        if (tmp >= num) {
          for (int j=i-tmp+1; j<=i; ++j) {
            //         cout << j << endl;
            hoge[a] = time - a*5;
            seki[j] = 17*(a%2)+3*(a%3)+19;
          }
          Q.pop();
          if (Q.empty()) break;
        }
      }
      // cout << time << endl;
      // FOR(it, seki)
      //   cout << *it << " ";
      // cout << endl;
    }
    time++;
    if (time % 5 == 0) Q.push(time/5);
  }
  int n;
  while(cin >> n) {
    cout << hoge[n] << endl;
  }
}

C++: #include<iostream>
using namespace std;
#define SHEETS 17
#define GROUPS 100
int main()
{
	while(true){
		int n;
		int ans = -1;
		int now;
		int sheets[SHEETS+1] = {-1,};
		int peoples[GROUPS] = {0,};
		int waiting[GROUPS] = {0,};
		int eating[GROUPS] = {0,};
		
		cin >> n;
		if(n == 0)
			break;

		for(int i = 0; i < SHEETS+1; ++i){
			sheets[i] = -1;
		}
		for(int i = 0; i < GROUPS; ++i)
		{
			waiting[i] = -i*5;
			peoples[i] = i%5==1?5:2;
			eating[i] = 17*(i%2)+3*(i%3)+19;
		}
		now = 1;
		sheets[0] = sheets[1] = 0;
		for(int t = 0; t < 2000 && ans < 0; ++t){
			
			for(int i = 0; i < GROUPS; ++i){
				++waiting[i];
			}
			
			for(int i = 0; i < SHEETS; ++i){
				if( sheets[i] >= 0 ){
					if( eating[sheets[i]] == 0 )
						sheets[i] = -1;
					else{
						--eating[sheets[i]];
						for(;sheets[i+1]==sheets[i];++i)0;
					}
				}
			}
			
			/*cout << "t="<<t<<":\t\t";
			for(int i = 0; i < SHEETS; ++i){
				cout << (char)(sheets[i]==-1?'_':sheets[i]+'0');
			}
			cout << '\n';*/
			
			while( ans < 0 ){
				bool bCont = false;
				for(int i = 0; i < SHEETS; ++i){
					int cont = 0;
					if( sheets[i] < 0 ){
						for(int j = i; j < SHEETS; ++j){
							if( sheets[j] < 0 ) cont++;
							else break;
						}
						if( cont >= peoples[ now ] && waiting[ now ] >= 0 ){
							for(int j = i; j < i+peoples[now]; ++j)
								sheets[j] = now;
							if( now == n ){
								ans = waiting[now] - 1;
								break;
							}
							++now;
							bCont = true;
						}
					}
				}
				if( !bCont )
					break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}