Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)
const INF = 0x7fffffff
func main() {
	S := 17
	seat := make([][]int, 27)
	for i :=range seat {
		seat[i] = make([]int, 27)
	}
	ans := make([]int, 105)
	id := 0
	Q := make([][]int, 0)
	for i := 0; i < S; i++ {
		seat[i][0] = -1
	}
	t := -1
	for ans[99] == 0 {
		t++
		if  t%5 == 0 && id <= 99 {
			if id % 5 == 1 {
				n := 5
				tmp := []int{id, n, t}
				Q = append(Q, tmp)
				id++
			} else {
				n := 2
				tmp := []int{id, n, t}
				Q = append(Q, tmp)
				id++
			}
		}
		for i := 0; i < 5; i++ {
			if seat[i][1] == 0 {
				continue
			}
			seat[i][1]--
			if seat[i][1] == 0 {
				seat[i][0] = -1
			}
		}
		f := len(Q)
		for f > 0 {
			i, n := Q[0][0], Q[0][1]
			f = 0
			for j := 0; j < S; j++ {
				g := 0
				for k := 0; k < n; k++ {
					if seat[j+k][0] >= 0 {
						g = 1
						break
					}
				}
				if g != 0 {
					continue
				}
				ans[i] = t-Q[0][2]
				Q = Q[1:]
				f = len(Q)
				for k := 0; k < n; k++ {
					seat[j+k][0] = i
					seat[j+k][1] = 17*(i&1) + 3*(i%3) + 19
				}
				break
			}
		}
	}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		fmt.Println(ans[n])
	}
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999


int data[110];

queue<pii> ar(){
    queue<pii> ret;
    rep(i,100){
        ret.push(pii(i,i*5));
    }
    return ret;
}


queue<pii> de(){
    vector<pii> tmp;
    queue<pii> ret;
    rep(i,100){
        tmp.pb(pii(i*5+17*(i%2)+3*(i%3)+19,i));
    }
    sort(all(tmp));
    rep(i,100){
        ret.push(pii(tmp[i].second,tmp[i].first));
    }
    return ret;
}




void pre(){
    int seat[20];
    rep(i,17)seat[i]=-1;
    queue<pii> arrive = ar();
    queue<pii> dep = de();
    bool flag=true;
    int now=0;
    while(arrive.size()+dep.size()){
        
        if( flag==false || arrive.empty() || arrive.front().second>dep.front().second  ){ //??¢?????????

            int dep_group = dep.front().first;
            now =dep.front().second;
            dep.pop();
            rep(i,17){
                if( seat[i]==dep_group ) seat[i]=-1;
            }
            flag = true;
//            printf("%3d : ",now);
//            rep(i,17){
//                if(seat[i]==-1)cout<<"__ ";
//                else printf("%02d ",seat[i]);
//            }cout<<endl;
        }
        else{ //??¢?????\???
            pii f = arrive.front();
            int members;
            if( (f.first)%5==1 )members = 5;
            else members = 2;
            
            int dp[20]={};
            for(int i=16;i>=0;i--){
                if(seat[i]!=-1) dp[i] = 0;
                else            dp[i] = dp[i+1]+1;
            }
            
            flag = false;
            rep(i,17){
                if(dp[i]>=members){
                    for(int j=i;j<i+members;j++){
                        seat[j] = f.first;
                    }
                    flag=true;
                    arrive.pop();
                    data[f.first] = max(f.second,now);
//                    printf("%3d : ",max(f.second,now));
//                    rep(i,17){
//                        if(seat[i]==-1)cout<<"__ ";
//                        else printf("%02d ",seat[i]);
//                    }cout<<endl;

                    break;
                }
            }
        }
    }
}


int main(){
    int n;
    pre();
    while(cin>>n){
        cout<<max( 0 , data[n]-(5*(int)n) )<<endl;
    }
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int t[110];
int now[20];
int p[110];
int q[110];
int r[110];
int main(){
	for(int i=0;i<100;i++){
		p[i]=i*5;
		if(i%5==1)q[i]=5;
		else q[i]=2;
		r[i]=17*(i%2)+3*(i%3)+19;
	}
	int at=0;
	for(int i=0;i<17;i++)now[i]=-1;
	for(int i=0;i<5000;i++){
		for(int j=0;j<at;j++){
			if(i==t[j]+r[j])for(int k=0;k<17;k++)if(now[k]==j)now[k]=-1;
		}
		while(at<=min(99,i/5)){
			int len=0;
			bool ok=false;
			for(int j=0;j<17;j++){
				if(!~now[j])len++;
				else len=0;
				if(len==q[at]){
					for(int k=j-q[at]+1;k<=j;k++)now[k]=at;
					ok=true;
				}
			}
			if(ok)t[at++]=i;
			else break;
		}
	}int a;
	while(~scanf("%d",&a)){
		printf("%d\n",t[a]-a*5);
	}
}

C++: #include<vector>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int seat[17];
vector<int> rm[5000];
queue<int> q;
int result[100];

int ck(int c){
	c=c%5==1?5:2;
	int suc=0;
	rep(i,17){
		if(seat[i]==-1){
			suc++;
			if(suc==c)return i-suc+1;
		}
		else suc=0;
	}
	return -1;
}
void in(int c,int p,int t){
	int n=c%5==1?5:2;
	rep(i,n)seat[i+p]=c;
	rm[5*c+17*(c%2)+3*(c%3)+19].push_back(c);
	result[c]=t-5*c;
	q.pop();
}
void remove(int c){
	rep(i,17)if(seat[i]==c)seat[i]=-1;
}
int main(){
	rep(i,17)seat[i]=-1;
	
	for(int t=0;t<=500||!q.empty();t++){
		if(t%5==0)q.push(t/5);
		rep(i,rm[t].size())remove(rm[t][i]);
		if(q.empty())continue;
		for(int p=ck(q.front());p>=0&&!q.empty();p=ck(q.front()))in(q.front(),p,t);
	}
	
	int n;
	while(cin>>n)cout<<result[n]<<endl;
	return 0;
}

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

int ans[100];

class G{
public:
  int id,n,a,d; //??°???????????????,?????°,??°?????????,?£??????????

  G(int i){
    id = i;
    n = (i % 5 == 1 ? 5 : 2);
    a = 5 * i;
    d = 17 * (i % 2) + 3 * (i % 3) + 19;
  }
};

//n?????£?¶???§???????¢??????§????????´????????????
int indexOfSeat(int *seat,int n){
  int count = 0;

  for(int i=0;i<17;i++){
    if(!seat[i]){
      count++;
      if(count == n) return i - n + 1;
    }
    else{
      count = 0;
    }
  }

  return -1;
}

void solve(void){
  vector<G> v; //????????????
  for(int i=0;i<100;i++) v.push_back(G(i));

  int time = 0; //?????¨?????????
  int seat[17]; //????????±
  memset(seat,0,sizeof(seat));

  while(!v.empty()){
    while(!v.empty() && v[0].a<=time){
      int idx = indexOfSeat(seat,v[0].n);
      if(idx != -1){
        for(int i=idx;i<idx+v[0].n;i++) seat[i] = v[0].d;
        ans[v[0].id] = time - v[0].a;
        v.erase(v.begin());
      }
      else{
        break;
      }
    }

    time++;
    for(int i=0;i<17;i++) if(seat[i] > 0) seat[i]--;
  }
}

int main(void){
  solve();

  int n;
  while(cin>>n) cout<<ans[n]<<endl;

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int seat[17] = {0};
	int X = 0;
	int stop[100] = {0};
	int time = 0;
	queue<int> Q;
	while(X < 100){
		int x;
		if(time%5 == 0 && time < 500){
			Q.push(time/5);
		}
		while(1){
			if(Q.size())x = Q.front();
			else x = -1;
			bool f = false;
			
			if(~x){
				int people = (x%5==1?5:2);
				int use = 19 + 3 * (x%3) + 17 * (x%2);
				rep(i,17-people+1){
					bool flag = true;
					rep(j,people){
						flag &= seat[i+j] == 0;
					}
					if(flag){
						rep(j,people){
							seat[i+j] = use;
						}
						f = true;
						break;
					}
				}
			}
			if(f){	
				stop[x] = time - x * 5;
				Q.pop();
				X++;
			}
			if(!f)break;
		}
		rep(i,17){
			seat[i] = max(0,seat[i]-1);
		}
		time++;
	}
	int n,c=0;
	
	while(cin >> n){
		if(n < 50)c++;
		cout << stop[n] << endl;
	}
	while(c>=5){return 1;};
	
}