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 <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

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

int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    vector<int> a(n);
    REP(i,n) cin>>a[i];
    int k=0;
    bool itiro = true;
    int ohajiki = 32;
    while(1){
      if(ohajiki==0) break;
      if(itiro){
        ohajiki -= (ohajiki-1)%5;
        cout<<ohajiki<<endl;
        itiro = false;
      }else{
        ohajiki = max(0,ohajiki-a[k]);
        k = (k+1)%n;
        cout<<ohajiki<<endl;
        itiro = true;
      }
    }
  }

  return 0;
}

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

int main(){
	while(1){
		int n, a[25];
		
		scanf(" %d", &n);
		if(n==0) break;
		for(int i=0; i<n; ++i) scanf(" %d", &a[i]);
		
		int r=32, now=0;
		while(r>0){
			r -= (r-1)%5;
			printf("%d\n", r);
			r -= a[now%n];
			if(r<0) r=0;
			printf("%d\n", r);
			++now;
		}
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

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

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n;
	while (cin >> n && n) {
		VI a(n); rep(i, n)cin >> a[i];

		int now = 32;
		for (int i = 0; now != 0; i++) {

			if (i % 2 == 0) {
				now -= (now - 1) % 5;
			}
			else {
				now -= min(a[i / 2 % n], now);
			}

			Cout(now);
		}
	}
}

C++: #include <cstdio>
#include <cstring>
#define buf 1000
using namespace std;
int Search_A(int z);
int Search_B(int z);
int n,cnt,A[50];
int main(void){
  int m,z,i;
  char str[buf],*line;

  for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
      sscanf(str,"%d",&n);
      if(n==0) break;
      fgets(str,sizeof(str),stdin);
      line=strtok(str," ");
      sscanf(line,"%d",&m); A[0]=m;
      for(i=1;i<n;i++){
        line=strtok(NULL," ");
        sscanf(line,"%d",&m);
        A[i]=m;
      }
      z=32; cnt=0;
      while(z!=0){
        z=Search_A(z);
        z=Search_B(z);
      }
  }
  return 0;
}

int Search_A(int z){
  z=z-(z-1)%5;
  if(z<0) z=0;
  printf("%d\n",z);
  return z;
}
int Search_B(int z){
  z=z-A[cnt%n];
  if(z<0) z=0;
  printf("%d\n",z);
  cnt+=1;
  return z;
}

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);
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int n;
	vector<int> a;
	cin >> n;
	if(n == 0)break;
	REP(i,n) {
	    int temp;
	    cin >> temp;
	    a.PB(temp);
	}
	int oha = 32;
	int i = 0;
	while(oha > 0){
	    oha -= (oha-1)%5;
	    if(oha > 0)
		cout << oha << endl;
	    oha -= a[i%n];
	    i++;
	    if(oha > 0)
		cout << oha << endl;
	}
	cout << 0 << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,p,n1,n2,x,suu,n,r[25];
	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		for(i=0;i<n;i++)	{
			scanf("%d",&r[i]);
		}
		suu=32;
		p=0;
		while(suu>0)	{
			n1=(suu-1)%5;
			suu-=n1;
			printf("%d\n",suu);
			n2=r[p];
			suu-=n2;
			if(suu<0)	suu=0;
			printf("%d\n",suu);
			p=(p+1)%n;
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int n, a[10000], cnt, turn;
int main() {
	while (true) {
		turn = 0; cnt = 31;
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++){
			cin >> a[i];
		}
		cout << "31" << endl;
		while (cnt >= a[turn%n]) {
			cnt -= a[turn%n];
			turn++;
			if (cnt == 0) { break; }
			cout << cnt << endl;
			cnt -= (cnt + 4) % 5;
			cout << cnt << endl;
		}
		cout << "0" << endl;
	}
	return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		vector<int>in(n);
		rep(i,in.size())cin>>in[i];
		int sum=32;
		int co=0;
		while(sum>=0){
			sum-=(sum-1)%5;
			if(sum<0)sum=0;
			cout<<sum<<endl;
			if(!sum)break;
			sum-=in[co%n];
			if(sum<0)sum=0;
			cout<<sum<<endl;
			if(!sum)break;
			co++;
		}
	}
}