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 <iostream>
using namespace std;
int n,a[4];

void solve() {
  int step=0,coin=32;
  while(1) {
    if(step % 2 == 0) {
      coin -= (coin-1)%5;
      cout << coin << endl;
      step++;
    }
    else if(step % 2 != 0){
      coin -= a[(step/2) % n];
      if(coin <= 0) {
        cout << "0" << endl;
        break;
      }
      cout << coin << endl;
      step++;
    }
  }
  return;
}

int main() {
  while(cin >> n) {
    if(n==0) break;
    for(int i=0;i<n;i++) {
      cin >> a[i];
    }
    solve();
  }
  return 0;
}

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

using namespace std;

int main(void){
  int n;
  while(cin>>n,n){
    vector<int> ary(n);
    for(int i = 0 ; i < n ; i ++)cin>>ary[i];
    int cnt = 31;
    int i = 0;
    int c = 0;
    while(cnt>=0){
      //cout<<" a ";
      if(cnt < 0)break;
      cout<<cnt<<endl;
      cnt -= ary[i];
      i = (i+1)%n;
      //cout<<" b ";
      if(cnt < 0)break;
      cout<<cnt<<endl;
      cnt -= (cnt - 1) % 5;
    }
    cout<<0<<endl;
  }
}

C++: #include<stdio.h>

int main(){

int n[5]={};
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(P>=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<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 (int f = 0; f < 6; f++){
			cout <<e<<endl;
			cout << e - b[f%size(b)] << endl;
			e -= 5;
		}
		cout << 1 << endl << 0 << endl;
	}
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    int n;

    while(cin >> n, n){
        vi series;
        bool player = true;
        int count = 0;
        for(int i=0; i < n; i++){
            int m;
            cin >> m;
            series.push_back(m);
        }
        int hajiki = 32;
        while(0 < hajiki){
            if(player){
                hajiki -= (hajiki-1)%5;
            }else{
                hajiki -= series[count%n];
                count++;
            }
            player = !player;

            if(0 < hajiki) cout << hajiki << endl;
            else cout << 0 << endl;
        }
    }
}

C++: #include <iostream>

using namespace std;

int main()
{
	int len;
	int a[30];
	
	while (cin >> len, len){
		int n = 32;
		
		for (int i = 0; i < len; i++){
			cin >> a[i];
		}
		
		for (int i = 0; n / len; i++){
			for (int j = 0; j < len; j++){
				n -= ((n - 1) % 5);
				cout << n << endl;
				if (n <= a[j]) break;
				n -= a[j];
				if (n <= (n-1) % 5)	break;
				cout << n << endl;
			}
		}
		cout << '0' << endl;
	}
}

C++: #include<iostream>
using namespace std;
int n, a[10000], cnt, turn;
int main() {
	while (true) {
		turn = 0; cnt = 31;
		cin >> n;
		if (!n) { 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 - 1) % 5;
			cout << cnt << endl;
		}
		cout << "0" << endl;
	}
	return 0;
}

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

int main()
{
  while (true)
  {
    int ohajiki = 32;
    int length;
    cin >> length;
    if ( length == 0 ) break;
    int* num_sequence = new int[length];
    for (int i=0; i<length; i++)
    {
      cin >> num_sequence[i];
    }

    for (int i=0,j=0; ohajiki != 0; i++)
    {
      if ( i % 2 == 0 )     //  兄
      {
        ohajiki -= ( ohajiki - 1 ) % 5;
      }
      else                  //  弟
      {
        int minus_num = num_sequence[j%length];
        ohajiki -= ( ohajiki <= minus_num ? ohajiki : minus_num );
        j++;
      }
      cout << ohajiki << endl;
    }

    delete[] num_sequence;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

int main() {
  int n;
  while(cin>>n,n) {
    int a[n];
    REP(i,n)
      cin >> a[i];
    int b = 32;
    int ct = 0;
    while(b>0) {
      b -= (b-1)%5;             // ツ暗ェツ郎
      cout << b << endl;
      b = max(0,b-a[(ct++)%n]);
      cout << b << endl;
    }
  }
}

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

using namespace std;

int main() {
  
  int N;
  while(cin >> N && N) {
    int *arr = new int[N];
    for(int i=0; i<N; i++) {
      cin >> arr[i];
    }
    
    int const S = 32;
    int now = S;
    int counter = 0;
    
    while(1) {
      now -= (now - 1) % 5;
      cout << now << endl;
      if(now == 1) break;
      now -= arr[counter%N];
      counter ++;
      cout << now << endl;
    }
    cout << 0 << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        vector<int> v(n);
        for (auto &&i : v) scanf("%d", &i);
        for (int i = 0, a = 32; a > 0; ++i) {
            if(i&1){
                a -= v[(i/2)%v.size()];
            }else {
                a -= (a-1)%5;
            }
            cout << max(a, 0) << "\n";
        }
    }
    return 0;
}

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

using namespace std;

int main(void){
  int n;
  while(cin>>n,n){
    vector<int> ary(n);
    for(int i = 0 ; i < n ; i ++)cin>>ary[i];
    int cnt = 31;
    int i = 0;
    int c = 0;
    while(cnt>=0){
      //cout<<" a ";
      if(cnt < 0)break;
      cout<<cnt<<endl;
      cnt -= ary[i];
      i = (i+1)%n;
      //cout<<" b ";
      if(cnt < 0)break;
      cout<<cnt<<endl;
      cnt -= (cnt - 1) % 5;
      if(c++>10)break;
    }
    cout<<0<<endl;
  }
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n;
  int a[33];
  while(cin >> n){
    if(!n) break;
    for(int i = 0; i < n; i++){
      cin >> a[i];
    }
    int p = 32;
    for(int i = 0;p; i++){
      if(i%2){
	p -= a[i/2%n];
      }else{
	p -= (p-1)%5;
      }
      p = max(0,p);
      cout << p << endl;
    }
  }
}