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 main()
{
	int n, m, a[25], i;
	while (cin >> m && m)
	{
		for (i = 0; i < m; i++)
			cin >> a[i];
		n = 32;
		i = 0;
		while (n > 0)
		{
			n -= (n-1)%5;
			cout << n << endl;
			if (n <= 0) break;
			n -= ((a[i]>=n)?n:a[i]);
			cout << n << endl;
			i++;
			if (i >= m) i = 0;
		}
	}
}

C++: // AOJ 0164
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

int main(void)
{
	int n;
	while (cin >> n, n){
		vector <int> kotori(n);
		int kotori_cnt = 0, honoka = 32;
		for (int i = 0; i < n; i++){
			cin >> kotori[i];
		}
		while (honoka > 0){
			honoka -= ((honoka - 1) % 5);
			cout << honoka << endl;
				// kotori
			honoka -= (kotori[kotori_cnt % n]);
			// cout << "*** DEBUG " << kotori_cnt << endl;
			kotori_cnt++;
			if (honoka <= 0) break;
			cout << honoka << endl;
		}
		cout << 0 << endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
long i,j,a[25],r;
while(cin>>i){
if(i==0)break;
for(j=0;j<i;j++)cin>>a[j];
r=31;
cout<<r<<endl;
for(j=0;;j++){
if(j==i)j=0;
r-=a[j];
cout<<r<<endl;
r=(r-1)/5*5+1;
cout<<r<<endl;
if(r==1)break;
}
cout<<'0'<<endl;
}
return 0;
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#include<complex>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {

	int n;
	while (cin >> n, n) {
		vector<int>v(n);
		for (int i = 0; i < n; i++)cin >> v[i];
		int x = 0;
		int value = 32;
		while (1) {
			value -= (value - 1) % 5;
			cout << value << endl;
			if (value == 1) {
				cout << 0 << endl;
				break;
			}
			value -= v[(x++) % n];
			cout << value << endl;
		}

		
	}

	return 0;
}

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

using namespace std;

int main(){
	while(true){
		int many = 32;
		vector<int> get;
		int a;
		scanf("%d", &a);
		if(!a){
			return 0;
		}
		get.resize(a);
		int i = 0;
		for(int i = 0; i < a; i++){
			scanf("%d", &get[i]);
		}
		bool now_ichiro = true;
		while(many != 0){
			if(now_ichiro){
				many -= (many - 1) % 5;
				now_ichiro = false;
			}
			else{
				many = max(0, many - get[i % a]);
				i++;
				now_ichiro = true;
			}
			printf("%d\n", many);
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#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()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  while(cin>>n, n){
    int j[n];
    int r = 32;
    int rr = 0;
    REP(i,n) cin>>j[i];
    while(r > 0){
      r -= (r-1)%5;
      cout << r << endl;
      r -= j[(rr++)%n];
      if(r < 0) r = 0;
      cout << r << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	int N;
	while(cin>>N,N){
		int A[25];
		for(int i=0;i<N;i++){
			cin>>A[i];
		}
		int c = 32;
		for(int i=0;c!=0;i++){
			c = max(c-(c-1)%5,0);
			printf("%d\n",c);
			if(c==0) break;
			c = max(c-A[i%N],0);
			printf("%d\n",c);
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    for(int n; cin >> n && n;)
	{
		vint v(n);
		rep(i, n) cin >> v[i];
		
		int m = 32;
		for(int i = 0; 0 < m; i++)
		{
			cout << (m -= (m - 1) % 5) << endl;
			cout << (max(0, m -= v[i % n])) << endl;
		}
	}
}

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

int main() {
    int N;
    while (cin >> N, N) {
        vector<int> v(N);
        for (auto& i : v) cin >> i;

        int sum = 32;
        int c = 0;
        while (sum) {
            if (c % 2 == 0) {
                sum -= (sum - 1) % 5;
            } else {
                sum = max(0, sum - v[(c/2)%N]);
            }
            c++;
            cout << sum << endl;
        }
    }

    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, a[100];

int main(){
	while (cin >> n&&n){
		REP(i, n)cin >> a[i];
		int sum = 32;
		int co = 0;
		while (sum){
			sum -= (sum - 1) % 5;
			cout << sum << endl;
			if(sum>a[co])sum -= a[co];
			else sum = 0;
			cout << sum << endl;
			co++;
			if (co == n)co = 0;
		}
	}
}

C++: /*
	0164:Ohajiki Game
*/
#include	<iostream>
#include	<vector>

using namespace std;

int main(void) {
	while(1) {
		int ohajiki, size;
		vector<int> vc;
		
		cin >> size;
		if(size == 0) { break; }
		for(int i = 0; i < size; i++) {
			int a;
			
			cin >> a;
			vc.push_back( a );
		}
		vector<int>::iterator it = vc.begin();
		ohajiki = 32;
		while(1) {
			ohajiki -= (ohajiki - 1) % 5;
			cout << ohajiki << endl;
			if( it == vc.end() ) {
				it = vc.begin();
			}
			if(ohajiki >= *it) {
				ohajiki -= *it;
			} else {
				ohajiki = 0;
			}
			it++;
			cout << ohajiki << endl;
			if(ohajiki == 0) {
				break;
			}
		}
	}
	return 0;
}