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>
#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 inp, 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++;
        }
    }
}

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=32;
	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;
				else cout<<n<<endl;
			}else{
				n-=dt[ite%size];
				if(n<0) cout<<"0"<<endl;
				else cout<<n<<endl;
				ite++;
			}
			turn++;
		}
	}
	return 0;
}

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

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int m;
        cin >> m;
        if(m == 0)
            return 0;
        vector<int> a(m);
        for(int i=0; i<m; ++i)
            cin >> a[i];

        int n = 32;
        for(int i=0; ; (++i)%=m){
            n -= (n - 1) % 5;
            cout << n << endl;

            n -= a[i];
            n = max(n, 0);
            cout << n << endl;
            if(n == 0)
                break;
        }
    }
}

C++: #include<iostream>
#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];
		}
		uint16_t 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>
#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 = 32;
        rep(i,n){
            cin >> a[i];
        }
        int i = 0;
        while(sum){
            sum -= (sum - 1) % 5;
            cout << sum << endl;
            sum-= a[i % n];
            sum = sum < 0 ? 0 : sum;
            cout << sum << endl;
            i++;
        }
    }
}

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

int main(){
  int n;
  while(cin >> n ,n){
    int num[100];
    for(int i=0;i<n;i++){
      cin >> num[i];
    }
    int now = 32;
    int idx = 0;
    while(now != 0){
      if(idx % 2 == 0){
	now = max(0,now-(now-1)%5);
      } else {
	now = max(0,now-num[(idx/2)%n]);
      }
      cout << now << endl;
      idx++;
    }
  }
}

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

using namespace std;

int a[100];

int main(){
	
	while(true){
		
		int n;
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		
		int index = 0;
		int rest = 31;
		
		while(true){
			cout << rest << endl;
			if(rest - a[index] <= 0){
				cout << "0" << endl;
				break;
			}
			cout << rest - a[index] << endl;
			index++;
			if(index >= n){
				index = 0;
			}
			rest -= 5;
		}
		
	}
	return 0;
}

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

int main(){
  while(true){
    int n;
    cin>>n;
    if(n==0)break;
    int sequence[n];
    for(int i=0;i<n;i++){
      cin>>sequence[i];
    }
    int ohaziki=32;int now=0;
    while(ohaziki>0){
      ohaziki=ohaziki-(ohaziki-1)%5;
      if(ohaziki<0)ohaziki=0;
      cout<<ohaziki<<endl;
      ohaziki=ohaziki-sequence[now];
      if(ohaziki<0)ohaziki=0;
      cout<<ohaziki<<endl;
      now++;
      if(now>n-1)now=0;
    }
  }
}

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

int main()
{
	int n, i, a;
	vector<int> v(25);
	int o;
	while (cin>>n, n) {
		for (i = 0; i < n; i++) {
			cin>>a;
			v[i] = a;
		}
		o = 31;
		cout<<o<<endl;
		for (i = 0; o > 0; i++) {
			o -= v[i%n];
			if (o<0) o = 0;
			cout<<o<<endl;
			if (o==0) break;
			o -= (o-1)%5;
			cout<<o<<endl;
		}
	}
	return 0;
}

C++: 

#include <iostream>
#include <list>
using namespace std;

int main(int argc, const char * argv[]) {

    while (true) {
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        
        int suuretu[25] = {0};
        for(int i=0;i<n;i++){
            cin >> suuretu[i];
        }
        
        int sum = 32;
        bool ichiro = false;
        int i = 0;
        while(sum > 1){
            if(ichiro){
                sum -= suuretu[i];
                i = (i + 1) % n;
                ichiro = false;
            }
            else{
                sum -= (sum - 1) % 5;
                ichiro = true;
            }
            
            cout << sum << endl;
        }
        
        cout << 0 << endl;
    }
    
    
    
    return 0;
}

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

int main(){
    while(1){
        int n;
        cin >> n;
        
        if(n == 0)  break;
        
        int A[n];
        for(int i = 0; i < n; i++)  cin >> A[i];

        int rest = 32;
        bool ichiro = true;
        int pos = 0;

        while(rest != 0){
            if(ichiro){
                rest -= (rest-1)%5;
            }else{
                rest -= A[pos];
                pos = (pos+1)%n;
            }

            ichiro = !ichiro;
            if(rest < 0)    rest = 0;
            cout << rest << endl;
        }
    }

    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n,i,j,num,array[30];
	
	for(;;)
	{
		cin >> n;
		if(n==0)
			break;
		num=32;
		
		for(i=0;i<n;i++)
			cin >> array[i];
		
		for(i=0;num>0;i++)
		{
			num-=(num-1)%5;
			cout << num << endl;
			if(i==n)
				i=0;
			num-=array[i];
			if(num<0)
			cout << "0" << endl;
			else
			cout << num << endl;
		}
	}
}

C++: #include <iostream>

using namespace std;

int main(void){

  int n;
  while( cin >> n , n ){

    int o[32];
    for( int i = 0 ; i < n ; i++ ){
      cin >> o[i];
    }

    int num = 32;
    int I = 0;

    while(num){
      num -= (num - 1) % 5;
      cout << num << endl;
      num -= o[(I++) % n];
      if(num < 0) num = 0;
      cout << num << endl;
    }
  }
  return 0;
}