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++: #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;
      assert(d);
      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>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
    for(int len; cin >> len, len; ) {
        vector<int> arr(len);
        for(int i = 0; i < len; i++) cin >> arr[i];
        int a = 0;
        int num = 32;
        num -= (num - 1) % 5;
        cout << num << endl;
        while(num >= 0) {
            if(arr[a] >= num) {
                cout << 0 << endl;
                break;
            }
            num -= arr[a];
            cout << num << endl;
            num -= (num - 1) % 5;
            cout << num << endl;
            a = (a + 1) % arr.size();
        }
    }
}

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

using namespace std;

int main()
{
	int n;
	while (cin >> n){
		if (cin.eof()) break;
		vector <int> kotori(n);
		int kotori_cnt = 0, honoka = 32;
		for (int i = 0; i < n; i++){
			cin >> kotori[i];
		}
		while (honoka > 0){
			honoka -= ((honoka - 1) % 5);
			cout << honoka << endl;
				// kotori
			honoka -= (kotori[kotori_cnt % n]);
			// cout << "*** DEBUG " << kotori_cnt << endl;
			kotori_cnt++;
			if (honoka <= 0) break;
			cout << honoka << endl;
		}
		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<stdio.h>

int main(){

int n[30]={};
int N;
int r=0;
while(1){
scanf("%d",&N);if(N==0)break;

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

int P=32;
int j=0;
while(1){
if(P<=0)break;
P-=(P-1)%5;printf("%d\n",P);
if(P==1)break;
P-=n[j];printf("%d\n",P);
j++;j=j%N;
}
P=0;printf("%d\n",P);
}
return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int l;
	while (cin >> l, l) {
		vector<int> num(l);
		REP(i, l) cin >> num[i];
		
		int now = 32, pos = 0;
		bool itiro = true;
		
		while (now > 0) {
			if (itiro) now -= (now - 1) % 5;
			else {
				now -= num[pos++];
				pos %= l;
			}
			if (now > 0) cout << now << endl;
			else puts("0");
			itiro = !itiro;
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

void loop(int remain, int* jiro_rule, int rule_size, int cur) {
    remain -= (remain - 1) % 5;
    cout << remain << endl;
    if (remain == 0) return;
    if (remain <= *(jiro_rule + cur)) {
        cout << 0 << endl;
        return;
    }
    remain -= *(jiro_rule + cur);
    cout << remain << endl;
    cur++;
    if (cur == rule_size) cur = 0;
    loop(remain, jiro_rule, rule_size, cur);
}

int main() {
    int i;
    while (cin >> i) {
        if (i == 0) break;
        int a[i];
        for (int p = 0; p < i; p++) {
            cin >> a[p];
        }
        loop(32, a, i, 0);
    }
    return 0;
}

C++: #include <stdio.h>
int n, a[25];
int main() {
	while(true) {
		scanf("%d", &n);
		if(n == 0) break;
		for(int i = 0; i < n; i++) scanf("%d", &a[i]);
		int c = 0, d = 32;
		while(d > 0) {
			if(c++ % 2 == 0) {
				d -= (d - 1) % 5;
			}
			else {
				d -= a[(c - 1) / 2 % n];
			}
			printf("%d\n", d > 0 ? d : 0);
		}
	}
	return 0;
}

C++: // 2011/02/06 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int i;
		cin >> i;
		if(i==0)
			break;

		int jir[25];
		for(int j=0; j<i; j++)
			cin >> jir[j];

		int n = 32;
		bool flg = true;
		int jir_i = 0;
		while(n>0){
			if(flg){
				int taro = (n-1)%5;
				if(taro>n)
					taro = n;
				n -= taro;
				cout << n << endl;
				flg = false;
			}
			else{
				int jiro = jir[jir_i];
				jir_i = (jir_i+1)%i;
				if(jiro>n)
					jiro = n;
				n -= jiro;
				cout << n << endl;
				flg = true;
			}
		}
	}

	return 0;
}

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

int i;
int main()
{
    while(cin >> i && i) {
        int a[i];
        for(int k = 0; k < i; k++) 
            cin >> a[k];

        int n = 32;
        for(int k = 0; n != 0; k++) {
            if(k % 2 == 0) n -= (n-1) % 5;
            else n -= a[(k / 2) % i];
            n = (n < 0) ? 0 : n;
            cout << n << endl;
        }
    }
}

C++: #include <bits/stdc++.h>

using namespace std;


int TakeQueue[25];

void judge(const int n) {
	int sum,i;
	bool flag;

	sum = 32;
	i = 0;
	flag = true;
	while (sum != 1) {
		if (flag) {
			sum -= (sum - 1) % 5;
			cout << sum << endl;
			flag = false;
		}
		else {
			sum -= TakeQueue[i];
			i = (i + 1) % n;
			cout << sum << endl;
			flag = true;
		}
	}
	cout << "0" << endl;
}


int main(void) {
	int n;

	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> TakeQueue[i];
		}
		judge(n);
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	int n;

	while (cin >> n, n){
		vector<int> v;
		for (int i = 0; i < n; i++){
			int t;
			cin >> t;
			v.push_back(t);
		}

		int total = 32;
		int i = 0;
		while (total){
			total -= (total - 1) % 5;
			cout << total << endl;
			total = fmax(total - v[i % n], 0);
			cout << total << endl;
			i++;
		}
	}

	return 0;
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int* a = new int [n];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int i = 0, ohajiki = 32;
        while (ohajiki > 0) {
            ohajiki -= (ohajiki - 1) % 5;
            cout << ohajiki << endl;
            if (ohajiki < a[i]) {
                ohajiki = 0;
            } else {
                ohajiki -= a[i];
            }
            i = (i + 1) % n;
            cout << ohajiki << endl;
        }
    }
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n, a[30];;
    while(cin >> n, n){
        int sum = 31;
        rep(i,n){
            cin >> a[i];
        }
        int i = 0;
        while(true){
            cout << sum << endl;
            sum-= a[i % n];
            if(sum <= a[i % n]){
                cout << '0' << endl;
                break;
            }
            cout << sum << endl;
            sum -= (sum - 1) % 5;
            i++;
        }
    }
}