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 <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n';)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;if((c=gcu())=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
	_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

int main() {
	for (int n; (n = in);) {
		vector<int> J(n);
		for (int &i: J)
			i = in;
		for (int o {32}, i {}; o;) {
			outl(o -= (o - 1) % 5);
			outl(o -= min(o, J[i++ % n]));
		}
	}
}

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

int main(){

	int n, v[26];
	int w[7] = {31, 26, 21, 16, 11, 6, 1};
	
	while(cin >> n){
		if(n == 0) break;
		for(int i=0; i<n; i++){
			cin >> v[i];
		}
		
		cout << 31 << endl;
		for(int i=0; i<6; i++){
			cout << w[i] - v[i%n] << endl;
			cout << w[i+1] << endl;
		}
		cout << 0 << endl;
	}

	return 0;

}

C++: #include <stdio.h>


int main(void){
    int mbls;
    int len;
    int ary[25], i;
    
    while (scanf("%d", &len)){
        if (len==0) break;
        for (int n=0; n<len; n++){
            scanf("%d", &ary[n]);
        }
        mbls=32;
        i=0;
        while(mbls>0){
            mbls -= (mbls-1)%5;
            printf("%d\n", mbls);
            if (mbls<ary[i]) mbls = 0;
            else mbls -= ary[i];
            printf("%d\n", mbls);
            i = (i+1)%len;
        }
    }
    return 0;
}

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

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

C++: #include <iostream>

using namespace std;

int main()
{
    int n;
    
    while (cin >> n, n) {
        int res = 32;
        int jirou[25];
        int cnt = 0;

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

        while (true) {
            res -= (res - 1) % 5;
            cout << res << endl;

            res -= jirou[cnt];
            cnt = (cnt + 1) % n;
            if (res < 1) {
                cout << 0 << endl;
                break;
            }
            
            cout << res << endl;
        }
    }

    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<iostream>
#include<string>
using namespace std;
int main(){
	int m,n[100];
	while(true){
	cin>>m;
	if(m==0)
		break;
	for(int i=0;i<m;i++)
		cin>>n[i];
	int ans=31;
	int count=0;
	cout<<"31"<<endl;
	while(true){
		if(ans<=n[count]){
			cout<<"0"<<endl;
			break;
		}
		ans-=n[count];
		cout<<ans<<endl;
		ans-=(ans-1)%5;
		cout<<ans<<endl;
		count++;
		count%=m;
	}
	}
	return 0;
}

C++: //
//  164.cpp
//  
//
//  Created by Minote Tomoki on 2015/06/01.
//
//

#include <stdio.h>

#define INITIAL 32

int number=INITIAL;
int seq[25]={0};
int n;

int step=0;

void turn() {
    if(number-1>0) {
        number-=((number-1)%5);
    }else{
        number--;
        return;
    }
    
    printf("%d\n",number);
    
    int tmp = (step++)%n;
    
    number-=seq[tmp];
}

int main(void) {
    
    for(;;) {
        number=INITIAL;
        step=0;
        scanf("%d",&n);
        if(n==0)break;
        for(int i=0;i<n;i++){
            scanf("%d",&seq[i]);
        }
        
        while(number>0) {
            turn();
            if(number>0)printf("%d\n",number);
        }
        printf("0\n");
        
    }
    return 0;
}

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

int n, arr[25];

int main(void){
  while(cin >> n && n != 0){
    for(int i = 0; i < n; i++) cin >> arr[i];
    int ohajiki = 32, i = 0;
    while(ohajiki != 0){
      ohajiki -= (ohajiki - 1) % 5;
      cout << ohajiki << endl;
      ohajiki = max(ohajiki - arr[i % n], 0);
      cout << ohajiki << endl;
      i++;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
main(){
  int N;
  while(1){
    scanf("%d",&N);
    if(N==0) break;
    int o = 32;
    int a[25]={};
    for(int i=0;i<N;i++){
      scanf("%d",&a[i]);
    }
    int i=0;
    while(o>0){
      o-=((o-1)%5);
      if(o<=0) o=0;
      printf("%d\n",o);
      if(o==0) break;
      o-=a[i];
      if(o<=0) o=0;
      printf("%d\n",o);
      i=(i+1)%N;
    }
  }
}

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

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

		int r = 32, p = 0;
		bool turn = false;
		while( true )
		{
			if( !turn )
				r -= ( r - 1 ) % 5;
			else
				r -= v[p], p = ( p + 1 ) % n;
	
			std::cout << r << std::endl;

			if( r == 1 )
				break;

			turn ^= true;
		}
	}

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