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