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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int n, l[30];

void solve() {
  int rest = 32, ptr = 0;
  while (rest) {
    rest -= (rest - 1) % 5;
    cout << rest << endl;
    if (rest > l[ptr]) {
      rest -= l[ptr];
      ptr++;
      if (ptr >= n) ptr = 0;
    } else {
      rest = 0;
    }
    cout << rest << endl;
  }
}

int main() {
  while (cin >> n, n) {
    rep (i,n) {
      cin >> l[i];
    }
    solve();
  }
}

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

int a[100];

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

        int rem = 32,cnt = 0;
        while(rem > 0) {
            rem -= (rem-1)%5;
            cout<<rem<<endl;
            if(rem == 0) break;
            rem -= min(rem,a[cnt%n]);
            cout<<rem<<endl;
            cnt++;
        }
    }
}

C++: #include <iostream>
#include <vector>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.ohajiki", "r", stdin );
	int n;

	while (1) {
		cin >> n;

		if (n == 0 ){
			break;
		} // end if

		vector <int> a (n, 0 );
		int i;

		for (i = 0; i < n; ++i){
			cin >> a[i];
		} // end for
		int ohajiki = 32;
		i = 0;		
	
		while (ohajiki > 0 ){
			int taro = (ohajiki - 1 ) % 5;
			ohajiki -= taro;
			cout << ohajiki << endl;
			int jiro = min (a[i], ohajiki );
			ohajiki -= jiro;
			cout << ohajiki << endl;
			i = (i + 1) % n;
		} // end while
	} // end loop
		
	return 0;
}

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

int main(){
	int n,a[25];
	while(cin >> n,n){
		memset(a,0,sizeof(a));
		for(int i = 0;i < n;i++){
			cin >> a[i];
		}
		//ツ暗ェツ郎ツづ個づつォツづ控RUEツ，ツ篠淞郎ツづ個づつォツづ孝ALSE
		bool turn = true;
		int i = 0,sum = 32;;
		while(sum != 0){
			if(turn)sum -= ((sum - 1) % 5);
			else{sum -= a[i++ % n];}
			if(sum < 0)sum = 0;
			cout << sum << endl;
			turn = !turn;
		}
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<int>as(N);
		for (int i = 0; i < N; ++i) {
			cin >> as[i];
		}
		int num = 31;
		cout << num << endl;
		int k = 0;
		while (num!=1) {
			num -= as[k];
			cout << num << endl;
			num -= 5 - as[k];
			cout << num << endl;
			k++;
			k %= N;
		}
		cout << 0 << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdlib>

using namespace std;
const static int O_NUM = 32; 
const static int I_MAX = 25;
int main() {
  while( 1 ) {
    int n, i, lis[ I_MAX ];
    cin >> i;
    if( !i ) { return EXIT_SUCCESS; }
    for( int j = 0; j < i; j++ ) {
      cin >> lis[ j ];
    }
    n = O_NUM;
    for( int j = 0; n > 0; j++ ) {
      if( !( j % 2 ) ) {
        n -= ( n - 1 ) % 5;
      } else {
        n -= lis[ j / 2 % i ];
      }
      n = max( 0, n );
      cout << n << endl;
    }
  }
}

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

//----- [n - 1 % 5]個のはじきを返す関数 -----//
int f_haziki(int);

int main(void)
{
	//入力変数
	int n = 0;
	//数列格納配列
	int h_retu[100] = {0};

	while (true)
	{
		cin >> n;
		if (n == 0)
		{
			return 0;
		}
		//はじき
		int haziki = 32;

		//数列の入力
		for (int i = 0; i < n; i++)
		{
			cin >> h_retu[i]; 
		}

		//カウント変数
		int count = 0;
		while (haziki > 0)
		{
			//兄の取った個数
			haziki -= f_haziki(haziki);
			if (haziki <= 0)	{	haziki = 0;	}
			cout << haziki << endl;
			//弟の取った個数
			haziki -= h_retu[count % n];
			count++;
			if (haziki <= 0)	{	haziki = 0;	}
			cout << haziki << endl;
		}
	}

	return 0;
}




//*****----- [n - 1 % 5]個のはじきを返す関数 -----*****//

int f_haziki(int n)
{
	return (n - 1) % 5;
}

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

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

C++: //#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
//#include<cmath>
//#include<string>
//#include<cctype>
//#include <vector>
using namespace std;
int main() {
	int n;
	while (cin >>n, n) {
		int a[25] = {};
		int i=0, s = 32;
		while(i<n) cin >> a[i++];
		i = 0;
		while (s>0) {
			s -= (s - 1) % 5;
			cout << s << endl;
			s -= a[i++%n];
			cout << max(0,s) << endl;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int num[25];
        for(int i=0;i<n;i++)cin>>num[i];
        for(int i=0,now=32,turn=1;now>0;turn++){
            if(turn==1)now-=(now-1)%5;
            else{
                if(i==n)i=0;
                now-=num[i];
                turn=0;
                i++;
            }
            if(now<0)now=0;
            cout<<now<<endl;
        }
    }
}

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

using namespace std;

int main(void) {
  int n;
  while (cin >> n, n) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    int rest = 32, i = 0, j = 0;
    while (rest) {
      int sub;
      if (i % 2) {
        rest -= min(rest, a[j++ % n]);
      } else {
        rest -= min(rest, (rest - 1) % 5);
      }
      cout << rest << endl;
      i++;
    }
  }
  
  return 0;
}

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

int main(){

  int n;

  while(cin >> n, n){
    int a[100],m = 32,j = 0,k = 0;

    for(int i=0;i<n;i++) cin >> a[i];

    while(1){
      if(j == n) j = 0;

      if(k == 0){
	m -= ((m-1)%5);
	k = 1;
      }

      else if(k == 1){
	m -= a[j];
	k = 0;
	j++;
      }
      if(m <= 0) break;
      cout << m << endl;
    }
    cout << "0" << endl;
  }
}

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

int main(){

	while(1){
		int l, num;
		vector<int> a;

		cin>>l;
		if(l == 0)
			break;

		for(int i=0;i<l;i++){
			cin>>num;
			a.push_back(num);
		}

		bool turn = true;
		int ohajiki = 32, j = 0;

		while(ohajiki != 0){
			if(turn){
				ohajiki -= (ohajiki-1)%5;
			}else{
				ohajiki -= a[j];
				j++;
				if(j == l)
					j = 0;
			}

			if(ohajiki < 0)
				ohajiki = 0;

			cout<<ohajiki<<endl;
			turn = !(turn);
		}
	}

	return 0;
}