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])
	}
}

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0147

"""
import sys
from sys import stdin
from heapq import heappop, heappush
from collections import deque
input = stdin.readline


class Seat():
    def __init__(self, n):
        self.seat = '_' * n

    def get(self, num):
        i = self.seat.find('_'*num)
        if i != -1:
            self.seat = self.seat[0:i] + 'o'*num + self.seat[i+num:]
            return i
        return None

    def release(self, i, num):
        self.seat = self.seat[0:i] + '_'*num + self.seat[i+num:]


def solve():
    waiting_time = [-1] * 100
    NUM_OF_SEAT = 17
    seat = Seat(NUM_OF_SEAT)
    LEAVE = 0
    COME = 1
    in_out = []                 #  ??\?????????????????????????????????
    Q = deque()                      #  ??§??????????????????
    # 100???????????\????????????????????????
    for group_id in range(100):
        if group_id % 5 == 1:
            num = 5
        else:
            num = 2
        heappush(in_out, (group_id * 5, COME, NUM_OF_SEAT+1, group_id, num))

    while in_out:
        time, event, start_seat, group_id, num = heappop(in_out)
        if event == COME:
            Q.append((time, group_id, num))
        else:
            seat.release(start_seat, num)
        while Q:
            res = seat.get(Q[0][2])
            if res is not None:
                arrive, group_id, num = Q.popleft()
                waiting_time[group_id] = time - arrive
                eating_time = 17 * (group_id % 2) + 3*(group_id % 3) + 19
                heappush(in_out, (time + eating_time, LEAVE, res, group_id, num))
            else:
                break
    return waiting_time


def main(args):
    waiting_time = solve()

    for line in sys.stdin:
        print(waiting_time[int(line)])


if __name__ == '__main__':
    main(sys.argv[1:])

Python: # AOJ 0147 Fukushimaken
# Python3 2018.6.23 bal4u
# キューで待ち行列

S = 17
seat = [[0 for t in range(27)] for id in range(27)]
ans = [0]*105
id = 0
Q = []
for i in range(S): seat[i][0] = -1
t = -1
while ans[99] == 0:
	t += 1
	# グループ到着
	if t % 5 == 0 and id <= 99:
		n = 5 if (id % 5) == 1 else 2
		Q.append((id, n, t))
		id += 1

	# 食事時間の確認
	for i in range(S):
		if seat[i][1] == 0: continue
		seat[i][1] -= 1
		if seat[i][1] == 0: seat[i][0] = -1

	# 待ち行列の案内
	f = len(Q)
	while f > 0:
		i, n = Q[0][0], Q[0][1]
		f = 0;
		for j in range(S):
			g = 0
			for k in range(n):
				if seat[j+k][0] >= 0:
					g = 1
					break
			if g: continue
			ans[i] = t-Q[0][2]
			del Q[0]
			f = len(Q)
			for k in range(n):
				seat[j+k][0] = i
				seat[j+k][1] = 17*(i&1) + 3*(i%3) + 19
			break

while 1:
	try: n = int(input())
	except: break	
	print(ans[n])

Python: from collections import deque

que = deque()
t = 0
seat = [0] * 17
score = []
while que or t < 500:
  if t % 5 == 0 and t < 500:
    i = t // 5
    que.append([t, 5 if i % 5 == 1 else 2, 17 * (i % 2) + 3 * (i % 3) + 19])
  
  for i in range(17):
    if seat[i]:
      seat[i] -= 1

  while que:
    need_space = que[0][1]
    for i in range(18 - need_space):
      if not any(seat[i:i+need_space]):
        for j in range(i, i + need_space):
          seat[j] = que[0][2]
        score.append(t - que[0][0])
        que.popleft()
        break
    else:
      break
  t += 1

while True:
  try:
    print(score[int(input())])
  except EOFError:
    break

Python: from collections import deque
from heapq import heappush, heappop
que = deque()
q = []
N = 100
for i in range(N):
    heappush(q, (5*i, 0, i))
M = 17
S = [-1]*M
T = [0]*N
while q:
    t = None
    while q and (t is None or q[0][0] == t):
        t, c, i = heappop(q)
        if c == 0:
            que.append(i)
        else:
            for j in range(M):
                if S[j] == i:
                    S[j] = -1

    while que:
        i = que[0]
        m = 5 if i % 5 == 1 else 2

        cnt = 0; j = -1
        for k in range(M):
            if S[k] == -1:
                cnt += 1
                if cnt == m:
                    j = k-m+1
                    break
            else:
                cnt = 0
        if j == -1:
            break
        for k in range(m):
            S[j + k] = i
        T[i] = t - 5*i
        que.popleft()
        heappush(q, (t + (17*(i%2) + 3*(i%3) + 19), 1, i))
open(1, 'w').writelines(["{}\n".format(T[v]) for v in map(int, open(0).read().split())])