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<cstdio>
using namespace std;
struct cus
{
	int a,b,c,d;
};

int main()
{
	cus a[100];
	for(int i=0;i<100;i++)
	{
		a[i].a=5*i;
		a[i].b=(i%5==1?5:2);
		a[i].c=17*(i%2)+3*(i%3)+19;
		a[i].d=0;
	}
	int t[20]={};
	for(int i=0;i<100;i++)
	{
		//for(int j=0;j<17;j++)printf("%3d",t[j]);
		//cout<<endl;
		int k=max(a[max(0,i-1)].d,a[i].a);
		for(;;k++)for(int j=0;j<17-a[i].b;j++)
		{
			bool x=true;
			for(int l=j;l<j+a[i].b;l++)
			{
				if(t[l]>k)x=false;
			}
			if(x)
			{
				for(int l=j;l<j+a[i].b;l++)
				{
					t[l]=k+a[i].c;
				}
				a[i].c=k-a[i].a;
				a[i].d=k;
				goto end;
			}
		}
		;end:;
	}
	int n;
	while(cin>>n)
	{
		cout<<a[n].c<<endl;
	}
}

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

const int MAX_SIZE = 100;
const int SEATS = 17;

int* calc() {
  queue<int> q;
  int *a = new int[MAX_SIZE]();
  int g, n, s[SEATS] = {};
  for (int t = 0; ; ++t) {
    for (int i = 0; i < SEATS; ++i) {
      if (s[i]) s[i]--;
    }
    if (t % 5 == 0) q.push(t / 5);
    while (!q.empty()) {
      bool c = false;
      g = q.front();
      n = g % 5 == 1 ? 5 : 2;
      for (int i = 0; i < SEATS - n; ++i) {
        if (n == 2 && !(s[i] || s[i + 1])) {
          s[i] = s[i + 1] = 17 * (g % 2) + 3 * (g % 3) + 19;
          c = true;
          break;
        }
        if (n == 5 && !(s[i] || s[i + 1] || s[i + 2] || s[i + 3] || s[i + 4])) {
          s[i] = s[i + 1] = s[i + 2] = s[i + 3] = s[i + 4] = 17 * (g % 2) + 3 * (g % 3) + 19;
          c = true;
          break;
        }
      }
      if (c) {
        a[g] = t - g * 5;
        if (g == MAX_SIZE - 1) return a;
        q.pop();
      } else {
        break;
      }
    }
  }
  return a;
}

int main() {
  int n;
  int *a = calc();
  while (true) {
    cin >> n;
    if (cin.eof()) break;
    cout << a[n] << endl;
  }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define N 100
typedef long long ll;
typedef pair<int,int>P;
typedef struct D{int t,n,e;bool operator <(const D &a)const{ return t>a.t;}};
priority_queue<D>F;
int r[N],s[20],w=0;

int ch(int n)
{
	for(int i=0;i<17;i++)
		if(s[i]==-1)
		{
			int j;
			for(j=0;j<n&&i+j<17;j++)if(s[i+j]!=-1)break;
			if(j==n)return i;
		}
	return -1;
}

int main()
{
	memset(s,-1,sizeof(s));
	for(int i=0;i<N;i++)
	{
		D tmp={i*5,i,0};
		F.push(tmp);
	}
	while(!F.empty())
	{
		D n=F.top();F.pop();
		if(n.e)
		{
			for(int i=0;i<17;i++)
				if(s[i]==n.n)s[i]=-1;
		}
		else
		{
			if(w<n.n)
			{
				n.t++;
				F.push(n);
				continue;
			}
			int a=n.n%5==1?5:2,b=ch(a);
			if(b!=-1)
			{
				for(int j=0;j<a;j++)
					s[b+j]=n.n;
				r[n.n]=n.t-5*n.n;
				w=n.n+1;
				D tmp={n.t+19+17*(n.n%2)+3*(n.n%3),n.n,1};
				F.push(tmp);
			}
			else
			{
				n.t++;
				F.push(n);
			}
		}
	}
	for(;~scanf("%d",&w);)printf("%d\n",r[w]);
	return 0;
}

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

main(){
  int data[100][2], ans[101];
  int seki[17], q=0;
  for(int i=0;i<100;i++){
    if(i%5==1){
      data[i][0]=5;
    }
    else{
      data[i][0]=2;
    }
    data[i][1]=17*(i%2)+3*(i%3)+19;
  }
  for(int i=0;i<17;i++){
    seki[i]=0;
  }
  
  for(int i=0;i<1000;i++){
    // printf("!%d! ", i);
    for(int j=0;j<17;j++){
      //printf("%2d ", seki[j]);
    }
    //printf("\n");
    for(int j=0;j<17;j++){
      if(seki[j]>0){
	seki[j]--;
      }
    }

    while(q<=i/5){
      int tmp=q;
      if(data[q][0]==2){
	for(int j=0;j<16;j++){
	  if(seki[j]==0 && seki[j+1]==0){
	    seki[j]=seki[j+1]=data[q][1];
	    ans[q]=i-q*5;
	    q++;
	    break;
	  }
	}
      }
      else{
	for(int j=0;j<13;j++){
	  if(seki[j]==0 && seki[j+1]==0 && seki[j+2]==0 && seki[j+3]==0 && seki[j+4]==0){
	    seki[j]=seki[j+1]=seki[j+2]=seki[j+3]=seki[j+4]=data[q][1];
	    ans[q]=i-q*5;
	    q++;
	    break;
	  }
	}
      }
      if(tmp==q) break;
    }
  }
  
  int n;
  while(cin >> n){
    cout << ans[n] << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <map>
using namespace std;
 
 int main() {
  int i=0,j,k=0,m,n,t=0,s[17],ad[100],len[100],ans[100];
  multimap<int,int> mp;
  for (k=0;k<17;k++) s[k]=-1;
  while(true) {
  for (;i<100;i++) {
	  len[i]=(i % 5)==1 ? 5 : 2;
	  for (j=0;j<17-len[i];j++) {
		  for (k=0;k<len[i];k++) if (s[j+k]>=0) break;
		  if (k==len[i])  { for (k=j;k<j+len[i];k++) s[k]=i; 
		  ans[i]=t>i*5 ? t-5*i : 0;
		  m=t < i*5 ? i*5 : t;
		  ad[i]=j;
		  mp.insert(multimap<int,int>::value_type(m+17*(i%2)+3*(i%3)+19,i)); 
		  break;} 
	  }
      if (j==17-len[i]) break;
  }
  if (i==100) break;
  t=(*mp.begin()).first;
  while(!mp.empty() && (*mp.begin()).first == t) {
	  m=(*mp.begin()).second;
	  for (j=ad[m]; j<ad[m]+len[m]; j++) s[j]=-1;
	  mp.erase(mp.begin());
     }
  }
  while(cin >> n) cout << ans[n] << endl;
   return 0;
 }