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

C++: // AOJ 0164
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n;
	while (cin >> n){
		if (cin.eof()) break;
		vector <int> kotori;
		int a, kotori_cnt = 0, cnt = 0, honoka = 32;
		for (int i = 0; i < n; i++){
			cin >> a;
			kotori.push_back(a);
		}
		while (honoka > 0){
			if (cnt % 2 == 0){
				// umi
				honoka -= ((honoka - 1) % 5);
			}
			else {
				// kotori
				honoka -= (kotori[kotori_cnt]);
				kotori_cnt = (kotori_cnt + 1) % n;
				// cout << "*** DEBUG " << kotori_cnt << endl;
			}
			cnt++;
			if (honoka <= 0) break;
			cout << honoka << endl;
		}
		cout << 0 << endl;
	}

	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXA = 26;

int a[MAXA];

int main()
{
    int n, j, now;
    while(cin >> j && j)
    {
        REP(j) cin >> a[i];
        
        n = 32; now = 0;
        while(n)
        {
            n -= (n - 1) % 5;
            cout << n << endl;
            
            if(n - a[now] <= 0){cout << 0 << endl; break;}
            n -= a[now];
            cout << n << endl;
            now = (now + 1 ) % j;
        }

    }

    return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	int jiro[100];
	while(n=in()){
		int i;
		for(i=0;i<n;i++){
			cin>>jiro[i];
		}
		int r=32;
		i=0;
		while(r>0){
			cout<<(r-1)/5*5+1<<endl;
			r=(r-1)/5*5+1;
			if(jiro[i]>r)cout<<0<<endl;
			else cout<<r-jiro[i]<<endl;
			r-=jiro[i];
			i=(i+1)%n;
		}
	}
	return 0;
}

C++: #include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

int main(){

	int n,array[25],NUM,index;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i=0; i < n; i++)scanf("%d",&array[i]);

		NUM = 32;
		index = 0;

		while(NUM > 0){
			NUM -= (NUM-1)%5;
			printf("%d\n",NUM);

			NUM -= array[index%n];
			if(NUM <  0){
				printf("0\n");
			}else{
				printf("%d\n",NUM);
			}
			index++;
		}

	}

    return 0;
}

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

int main()
{
	while (1) {
		int a;
		cin >> a;
		if (a == 0)break;
		vector<int>b(a);
		for (int c = 0; c < a; c++) {
			cin >> b[c];
		}
		int e = 31;
		for (uint16_t f = 0; f < 6; f++){
			cout <<e<<endl;
			cout << e - b[f%size(b)] << endl;
			e -= 5;
		}
		cout << 1 << endl << 0 << endl;
	}
}

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

int operate[25];
int main()
{
	int n;
	while(cin >> n){
		if(!n)
			break;
		int m = 31;
		for(int i=0;i<n;i++){
			cin >> operate[i];
		}
		int pos = 0;
		while(m>0){
			m -= (m-1)%5;
			if(m<=0)
				break;
			cout << m << endl;
			m -= operate[pos];
			if(m<=0)
				break;
			cout << m << endl;
			pos++;
			if(pos==n)
				pos = 0;
		}
		cout << 0 << endl;
	}
	return 0;
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n=31;
	int size;
	while(cin>>size){
		n=31;
		if(size==0)break;
		int dt[size];
		rep(i,size){
			cin>>dt[i];
		}
		int turn=1;
		int ite=0;
		while(n){
			if(n<0)break;
			if(turn%2==1){
				n-=(n-1)%5;
				//if(n<0) cout<<0<<endl;
				cout<<n<<endl;
			}else{
				n-=dt[ite%size];
				//if(n<0) cout<<0<<endl;
				cout<<n<<endl;
				ite++;
			}
			turn++;
		}
	}
	return 0;
}

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

int main(){
	int n, a[26];
	while (scanf("%d", &n), n != 0) {
		for (int i = 0; i < n; i++) {
			scanf(" %d", &a[i]);
		}
		printf("31\n");
		int o = 31, it = 0;
		while (o > 5) {
		printf("%d\n%d\n", o - a[it], o - 5);
		o -= 5;
		if (++it >= n)
			it = 0;
		}
		printf("0\n");
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  while(cin >> n && n) {
    vector<int> v(n);
    for(int i = 0; i < n; ++i) cin >> v[i];
    int num = 32;
    int p = 0;
    while(num) {
      int d = (num - 1) % 5;
      num -= d;
      cout << num << endl;
      if(num) {
        num -= v[p];
        num = max(num, 0);
        p = (p + 1) % v.size();
        cout << num << endl;
      }
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int n,a[100];
main()
{
    whiel(cin>>n,n)
    {
        for(int i=0;i<n;i++)cin>>a[i];
        int c=32,i=0;
        while(c)
        {
            c-=(c-1)%5;
            cout<<c<<endl;
            c-=(a[i]>c?c:a[i]);
            cout<<c<<endl;
            i=(i+1)%n;
        }
    }
}

C++: #include<iostream>

using namespace std;
int main(){
  int n;
  while(cin >> n){
    if(n==0) break;
    int p[25],ohajiki=31;
    for(int i=0; i<n; i++) cin >> p[i];
    int count=0;
    cout << ohajiki << endl;
    while(ohajiki!=1){
      if(count == n) count=0;
      ohajiki-=p[count];
      cout << ohajiki << endl;
      count++;
      ohajiki-=(ohajiki-1)%5;
      cout << ohajiki << endl;
    }
    cout << 0 << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int i=0 ,n ,total=32 ,length;
  while( cin >> length ){
    if( length == 0 ){
      break;
    }
    int jiro[length];
    
    for( int j=0 ; j<length ; j++ ){ // 次郎の取る数
      cin >> jiro[j];
    }
    
    while( 1 ){
      n = total; // 一郎のターン
      total -= (n - 1 ) % 5;
      if( total <= 0 ){
	cout << "0" << endl;
	break;
      }
      cout << total << endl;
    
      total -= jiro[i]; // 次郎のターン
      i++;
      if( i == length ){
	i = 0;
      }
      if( total <= 0 ){
	cout << "0" << endl;
	break;
      }
      cout << total << endl;
    }
    total = 32;
    i = 0;
  }
  return 0;
}

C++: //28
#include<iostream>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int a[25];
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    int r=32;
    for(int t=0;r;t++){
      if(t%2){
	r-=a[t/2%n];
      }else{
	r-=(r-1)%5;
      }
      if(r<0){
	r=0;
      }
      cout<<r<<endl;
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int n, a[10000], cnt, turn;
int main() {
	while (true) {
		turn = 0; cnt = 31;
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++){
			cin >> a[i];
		}
		cout << "31" << endl;
		while (cnt >= a[turn%n]) {
			cnt -= a[turn%n];
			turn++;
			cout << cnt << endl;
			cnt -= (cnt + 4) % 5;
			cout << cnt << endl;
		}
		cout << "0" << endl;
	}
	return 0;
}