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<algorithm>
#include<stdio.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int, P > PP;
int n,ans[100];
PP t[500];
PP u[500];
int ts,te,us,ue;
int state[17];

void t_in(PP x){
  t[te]=x;
  te++;
}
void u_in(PP x){
  u[ue]=x;
  ue++;
}
PP t_out(){
  ts++;
  return t[ts-1];
}
PP u_out(){
  us++;
  return u[us-1];
}


int u_check(){
  int a = u[us].second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	return 1;
      }
    }else{
      cnt=0;
    }
  }
  return 0;
}

int u_ins(){
  int a = u[us].second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	for(int j=i;j>i-b;j--){
	  state[j]=a;
	}
	break;
      }
    }else{
      cnt=0;
    }
  }

  
  u_out();
  return a;
}
int u_check2(PP x){
  int a = x.second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	return 1;
      }
    }else{
      cnt=0;
    }
  }
  return 0;
}
void u_ins2(PP x){
  int a = x.second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	for(int j=i;j>i-b;j--){
	  state[j]=a;
	}
	break;
      }
    }else{
      cnt=0;
    }
  }
}

int main(){
  ts=us=te=ue=0;

  for(int i=0;i<100;i++)ans[i]=0;
  for(int i=0;i<17;i++)state[i]=-1;

  for(int i=0;i<100;i++){
    t_in(PP(5*i,P(1,i)));
  }

  sort(t+ts,t+te);

  PP x,y;
  int flg,z;
  while(!(ts==te)){

    /*
    for(int i=0;i<17;i++)printf("%3d ",state[i]);
    cout<<endl;

    for(int i=us;i<ue;i++)printf("%3d ",u[i].second.second);
    cout<<endl;
    */
    
    sort(t+ts,t+te);
    y=x;
    x=t_out();

    //cout<<x.first<<' '<<x.second.first<<' '<<x.second.second<<endl;
    for(int i=us;i<ue;i++)ans[u[i].second.second]+=(x.first-y.first);

    if(x.second.first==0){
      for(int i=0;i<17;i++)if(state[i]==x.second.second)state[i]=-1;
      while(1){
	if(us==ue)break;
	flg=u_check();
	if(flg==0)break;
	z=u_ins();
	
	t_in(PP(x.first+(17*(z%2)+3*(z%3)+19),P(0,z)));
      }
            
    }else if(x.second.first==1){
      flg=u_check2(x);

      if(flg==0||us!=ue){
	u_in(x);
      }else{
	u_ins2(x);

	z=x.second.second;
	t_in(PP(x.first+(17*(z%2)+3*(z%3)+19),P(0,z)));
      }
    }//if
  }

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

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

int a[16], c[100];
priority_queue<pair<int,int> > b;

int can_sit(int n) {
  int p = 0;
  for (int i=0; i<16; i++) {
    if (a[i] == -1) {
      ++p;
    } else {
      p = 0;
    }
    if (p == n) {
      return i-n+1;
    }
  }
  return -1;
}

int sit(int id, int stt, int n) {
  for (int i=0; i<n; i++) {
    a[i+stt] = id;
  }
}

int stand(int id) {
  for (int i=0; i<16; i++) {
    if (a[i] == id) {
      a[i] = -1;
    }
  }
}

int main() {
  int t, p, q, r;
  for (int i=0; i<16; i++) a[i] = -1;
  t = 0;
  p = 0;
  while (1) {
    while (t >= 5*p && p<100) {
      q = (p%5==1) ? 5 : 2;
      r = can_sit(q);
      if (r != -1) {
        c[p] = t - 5*p;
        sit(p, r, q);
        b.push(pair<int, int>(-(t + 17*(p%2) + 3*(p%3) + 19), p));
        p++;
      } else {
        break;
      }
    }
    if (-b.top().first <= ((t/5)+1)*5) {
      t = -b.top().first;
      stand(b.top().second);
      b.pop();
    } else {
      t = ((t/5)+1)*5;
    }
    if (p==100 && b.empty()) {
      break;
    }
  }

  while (cin >> t) {
    cout << c[t] << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int, P > PP;
int n,ans[100];
PP t[500];
PP u[500];
int ts,te,us,ue;
int state[17];

void t_in(PP x){
  t[te]=x;
  te++;
}
void u_in(PP x){
  u[ue]=x;
  ue++;
}
PP t_out(){
  ts++;
  return t[ts-1];
}
PP u_out(){
  us++;
  return u[us-1];
}


int u_check(){
  int a = u[us].second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	return 1;
      }
    }else{
      cnt=0;
    }
  }
  return 0;
}

int u_ins(){
  int a = u[us].second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	for(int j=i;j>i-b;j--){
	  state[j]=a;
	}
	break;
      }
    }else{
      cnt=0;
    }
  }

  
  u_out();
  return a;
}
int u_check2(PP x){
  int a = x.second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	return 1;
      }
    }else{
      cnt=0;
    }
  }
  return 0;
}
void u_ins2(PP x){
  int a = x.second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
	for(int j=i;j>i-b;j--){
	  state[j]=a;
	}
	break;
      }
    }else{
      cnt=0;
    }
  }
}

int main(){
  ts=us=te=ue=0;

  for(int i=0;i<100;i++)ans[i]=0;
  for(int i=0;i<17;i++)state[i]=-1;

  for(int i=0;i<100;i++){
    t_in(PP(5*i,P(1,i)));
  }

  sort(t+ts,t+te);

  PP x,y;
  int flg,z;
  while(!(ts==te)){

    /*
    for(int i=0;i<17;i++)printf("%3d ",state[i]);
    cout<<endl;

    for(int i=us;i<ue;i++)printf("%3d ",u[i].second.second);
    cout<<endl;
    */
    
    sort(t+ts,t+te);
    y=x;
    x=t_out();

    //cout<<x.first<<' '<<x.second.first<<' '<<x.second.second<<endl;
    for(int i=us;i<ue;i++)ans[u[i].second.second]+=(x.first-y.first);

    if(x.second.first==0){
      for(int i=0;i<17;i++)if(state[i]==x.second.second)state[i]=-1;
      while(1){
	if(us==ue)break;
	flg=u_check();
	if(flg==0)break;
	z=u_ins();
	
	t_in(PP(x.first+(17*(z%2)+3*(z%3)+19),P(0,z)));
      }
            
    }else if(x.second.first==1){
      flg=u_check2(x);

      if(flg==0||us!=ue){
	u_in(x);
      }else{
	u_ins2(x);

	z=x.second.second;
	t_in(PP(x.first+(17*(z%2)+3*(z%3)+19),P(0,z)));
      }
    }//if
  }

  
  //cout<<te<<endl;
  while(cin>>n){
    for(int i=n;i<=n;i++)cout<<ans[i]<<' ';
    cout<<endl;
  }
  return 0;
}