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

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