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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-6;

struct group{
	int num;
	int eatTime;
	int idx;
};

void checkTable(int table[17],queue<group>& que,int time,map<int,int>& waitTime){
	for(int i=0;i<17;i++){
		table[i] -= table[i]>=1 ? 1 : 0;
	}

	for(int i=0;i<17;i++){
		for(int j=i;j<17;j++){
			if(table[j] > 0) break;
			if(que.empty()) goto end;

			if(j-i+1 == que.front().num && que.front().idx * 5 <= time){
				waitTime[que.front().idx] = abs(time - que.front().idx * 5);
				int num = que.front().num;
				int eat = que.front().eatTime;
				que.pop();
				for(int k=i;k<=j;k++){
					table[k] = eat;
				}
			}
		}
	}
end:;
}

int main(){
	int n;
	int table[17];
	memset(table,0,sizeof(table));
	queue<group> que;
	map<int,int> waitTime;

	for(int i=0;i<100;i++){
		int num = i % 5 == 1 ? 5 : 2;
		int eat = 17*(i%2)+3*(i%3)+19;
		group g;
		g.eatTime = eat;
		g.idx = i;
		g.num = num;
		que.push(g);		
	}

	for(int i=0;i<1000000;i++){
		checkTable(table,que,i,waitTime);
	}

	while(~scanf("%d",&n)){
		cout << waitTime[n] << endl;
	}
}

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

const int INF = 1 << 30;

int main()
{
  int time = 0;
  vector<int> seat(17, INF), ans(100);
  for (int i = 0; i < 100; ++i) {
    time = max(time, i*5);
    int people = 2;
    if (i%5 == 1)
      people = 5;

    for ( ; ; ) {
      for (int j = 0; j < seat.size(); ++j) {
	if (seat[j] <= time)
	  seat[j] = INF;
      }

      int con = 0;
      bool in = false;
      for (int j = 0; j < seat.size(); ++j) {
	if (seat[j] == INF) {
	  ++con;
	  if (con == people) {
	    in = true;
	    for (int k = j; k > j-con; --k)
	      seat[k] = time + 17*(i%2) + 3*(i%3) + 19;
	    ans[i] = max(0, time - i*5);
	    break;
	  }
	} else {
	  con = 0;
	}
      }

      if (in)
	break;

      int min_time = INF;
      for (int j = 0; j < seat.size(); ++j)
	min_time = min(min_time, seat[j]);
      time = min_time;
    }
  }

  int n;
  while (cin >> n)
    cout << ans[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;
	queue<int> q;
	rep(i,17)d[i]=0;
	for(;cnt<100;t++){
		if(t%5==0 && t<500)q.push(t/5);
		while(!q.empty()){
			int v=q.front();
			int num=v%5==1?5:2;
			int g=0;
			rep(j,18-num){
				if(d[j]<1 && !g){
					g=1;
					reps(k,1,num-1){
						if(d[j+k]>0)g=0;
					}
					if(g){
						rep(k,num)d[j+k]=17*(v%2)+3*(v%3)+19;
					}
				}
			}
			if(!g)break;
			q.pop();
			n[v]=t-v*5;
			cnt++;
		}
		rep(i,17)if(d[i]>0)d[i]--;
	}
	while(~scanf("%d",&t))printf("%d\n",n[t]);
	return 0;
}

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

typedef pair<int, int> P;

int ans[110];
P seat[20];
queue<int> waiting;
int Cnt = 0;

void outputSeat(){
  for(int i = 0 ; i < 17 ; i++){
    printf("%3d ", seat[i].first);
  }
  cout << endl;
  
  for(int i = 0 ; i < 17 ; i++){
    printf("%3d ", seat[i].second);
  }
  cout << endl << endl;
}

bool come(int n, int t){
  int group = n % 5 == 1 ? 5 : 2;
  int cnt = 0, s = 0;
  bool f = false;
  for(int i = 0 ; i < 17 ; i++){
    if(seat[i].first == -1 && !f){
      s = i;
      f = true;
    }
    
    if(seat[i].first == -1){
      cnt++;
    }
    
    else cnt = 0, s = i+1, f = false;
  
    if(cnt == group){
      //cout << "OK"<<endl;
      for(int j = s ; j < s+group ; j++){
	seat[j].first = n;
	seat[j].second = 17*(n%2) + 3*(n%3) + 19 + t;
      }
      return true;
    }
  }
  return false;
}
  
void off(int n){
  for(int i = 0 ; i < 17 ; i++){
    if(seat[i].first == n) seat[i].first = -1, seat[i].second = -1;
  }
}

void solve(){
  for(int t = 0 ; t <= 610 ; t++){
    //outputSeat();
    //cout << "time = " << t << endl;
    for(int i = 0 ; i < 17 ; i++){
      if(seat[i].second == t){
	off(seat[i].first);
	if(waiting.size() > 0){
	  int num = waiting.front();
	  while(1){
	    bool f = come(num, t);
	    if(f){
	      ans[num] = t - ans[num];
	      waiting.pop();
	      num = waiting.front();
	      if(num == 0) break;
	    }
	    else break;
	  }
	}
      }
    }
    
    //cout << "front = " << waiting.front() << endl;
    
    if(t % 5 == 0 && Cnt < 100){
      Cnt++;
      int number = t / 5;
      if(waiting.size() > 0){
	ans[number] = t;
	waiting.push(number);
	continue;
      }
      bool f = come(number, t);
      if(f) ans[number] = 0;
      else{
	waiting.push(number);
	ans[number] = t;
      }
    }    
    
  }
  
}

void init(){
  memset(seat, -1 , sizeof(seat));  
  memset(ans, 0, sizeof(ans));
}

int main(){
  init();
  solve();
  int n;

  while(cin >> n) cout << ans[n] << endl;
  return 0;
}