Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		scanner.Scan()
		buf := strings.Split(scanner.Text(), " ")
		input := make([]int, len(buf))
		for i := range input {
			input[i], _ = strconv.Atoi(buf[i])
		}
		fmt.Println(31)
		i, k := 0, 31
		for k > 1 {
			k -= input[i]
			fmt.Println(k)
			k = k - (k-1)%5
			fmt.Println(k)
			i++
			if i >= n {
				i = 0
			}
		}
		fmt.Println(0)
	}
}

Python: while 1:
    n=int(input())
    if n==0: break
    a=list(map(int,input().split()))
    i,s=0,32
    while s>0:
        s-=(s-1)%5
        print(s)
        s-=a[i%n]
        i+=1
        print(max(0,s))

Python: from itertools import cycle

INITIALIZE = 32

while True:

    input_count = int(input())

    if input_count == 0:
        break

    get_list = [int(item) for item in input().split(" ")]

    ohajiki = INITIALIZE
    output = []

    for get_count in cycle(get_list):

        ohajiki -= (ohajiki - 1) % 5
        output.append(ohajiki)

        if get_count < ohajiki:
            ohajiki -= get_count
            output.append(ohajiki)
        else:
            output.append(0)
            break

    output = [str(item) for item in output]
    print("\n".join(output))

Python: from itertools import cycle

INITIALIZE = 32

while True:

    input_count = int(input())

    if input_count == 0:
        break

    get_list = [int(item) for item in input().split(" ")]

    ohajiki = INITIALIZE

    for get_count in cycle(get_list):

        ohajiki -= (ohajiki - 1) % 5
        print(ohajiki)

        if get_count < ohajiki:
            ohajiki -= get_count
            print(ohajiki)
        else:
            print(0)
            break

Python: def ICH(n):
  x=(n-1)%5
  return x
while True:
  n = int(input())
  if n==0:
    break
  J=list(map(int, input().split()))
  i, num=0,31
  print(num)
  while num>1:
    num-=J[i]
    print(num)
    num=num-ICH(num)
    print(num)
    i+=1
    if i>=n:
      i=0
  print(0)

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

"""
import sys
from sys import stdin
from itertools import cycle
input = stdin.readline


def taro(n):
    return (n - 1) % 5


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break

        jiro = cycle([int(x) for x in input().split(' ')])

        ohajiki = 32
        while ohajiki > 0:
            ohajiki -= taro(ohajiki)
            print(ohajiki)
            ohajiki -= jiro.__next__()
            print(max(0, ohajiki))


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

Python: while True:
    n = int(input())
    if n == 0: break
    a = list(map(int, input().split()))
    i, o = 0, 32
    while o > 0:
        o = o - (o-1)%5
        print(o)
        o = 0 if a[i] > o else o - a[i]
        print(o)
        i = 0 if i == n-1 else i+1

Python: from itertools import cycle

INITIALIZE = 32

while True:

    input_count = int(input())

    if input_count == 0:
        break

    get_list = [int(item) for item in input().split(" ")]

    ohajiki = INITIALIZE
    output = []

    for get_count in cycle(get_list):

        ohajiki -= (ohajiki - 1) % 5
        print(ohajiki)

        if get_count < ohajiki:
            ohajiki -= get_count
            print(ohajiki)
        else:
            print(0)
            break

Python: # AOJ 0164 Ohajiki Game
# Python3 2018.6.18 bal4u

while True:
	n = int(input())
	if n == 0: break
	a = list(map(int, input().split()))
	print(31)
	i, k = 0, 31
	while k > 1:
		k -= a[i]
		print(k)
		k = k - (k-1) % 5;
		print(k)
		i += 1
		if i >= n: i = 0
	print(0)

Python: while True:

    n = int(input())
    if n == 0:
        break

    a = [int(i) for i in input().split()]

    stone = 32
    k = 0
    while True:
        stone = stone - (stone-1)%5
        if stone > 0:
            print(stone)
        else:
            print(0)
            break
        stone = stone - a[k]
        if stone > 0:
            print(stone)
        else:
            print(0)
            break
        k = (k + 1) % n

Python: while True:
    n = int(input())
    if n == 0:
        break
    Num = list(map(int,input().split()))
    noko = 32
    jun = 0
    iti = 0
    while noko > 0:
        if jun == 0:
            noko -= (noko - 1) % 5
        else:
            noko -= Num[iti % len(Num)]
            iti += 1
        if noko < 0:
            noko = 0
        print(noko)
        jun = (jun + 1) % 2

Python: while True:
  n = int(input())
  if n == 0:
    break
  alst = list(map(int, input().split())) * 16
  turn = 0
  rest = 32
  while True:
    if turn % 2 == 0:
      rest -= (rest - 1) % 5
    else:
      rest -= alst[turn // 2]
      rest = max(rest, 0)
    print(rest)
    turn += 1
    if rest == 0:
      break

Python: import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


NUM = 32

while True:
    N = int(input())
    if N == 0:
        break

    table = list(map(int,input().split()))

    num_card = NUM
    tern = 0

    while num_card > 0:
        sente = (num_card-1)%5
        num_card -= sente
        print("%d"%(num_card))

        gote = table[tern%(len(table))]
        num_card = max(0,num_card-gote)
        print("%d"%(num_card))
        tern += 1

Python: from itertools import cycle

INITIALIZE = 32

while True:

    input_count = int(input())

    if input_count == 0:
        break

    get_list = [int(item) for item in input().split(" ")]

    ohajiki = INITIALIZE
    output = []

    for get_count in cycle(get_list):

        ohajiki -= (ohajiki - 1) % 5
        output.append(ohajiki)

        if get_count <= ohajiki:
            ohajiki -= get_count
            output.append(ohajiki)
        else:
            output.append(0)
            break

    output = [str(item) for item in output]
    print("\n".join(output))

Python: # Aizu Problem 00164: Ohajiki Game
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    n = int(input())
    if n == 0:
        break
    A  = [int(_) for _ in input().split()]
    oha = 32
    i = 0
    while oha != 0:
        oha -= (oha - 1) % 5
        print(oha)
        oha = max(oha - A[i % n], 0)
        print(oha)
        i += 1

Python: while 1:
    n = int(input())
    if n == 0:
        break
    alist = list(map(int, input().split()))

    ohajiki = 32
    cnt = 0
    while ohajiki != 0:
        taro = (ohajiki - 1) % 5
        ohajiki -= taro
        print(ohajiki)

        jiro = alist[cnt % n]
        ohajiki -= jiro
        if ohajiki < 0:
            ohajiki = 0
        print(ohajiki)
        cnt += 1

Python: #!/usr/bin/env python3
#import pdb;pdb.set_trace()
import sys
if False:
    fh=open('vol1_0164.txt','r')
else:
    fh=sys.stdin
j=0
a=[]

def ichi(n):
    n -= (n-1) % 5
    return(n)

def ji(n):
    global j    
    if n < a[j]:
        n = 0
    else:
        n -= a[j]
    j = (j+1) % len(a)
    #print('j=',j,' len(a)=',len(a))
    return(n)

while True:
    m = int(fh.readline())
    if m==0:
        break
    a = list(map(int, fh.readline().strip().split()))
    j=0
    n=32
    while True:
        n = ichi(n)
        print(n)
        if n==0:
            #print('ichiro lose')
            break
        n = ji(n)
        print(n)
        if n==0:
            #print('jiro lose')
            break