#include <iostream>

using namespace std;

int main()
{
	int len;
	int a[30];
	
	while (cin >> len, len){
		int n = 32;
		
		for (int i = 0; i < len; i++){
			cin >> a[i];
		}
		
		for (int i = 0; n / len; i++){
			for (int j = 0; j < len; j++){
				n -= ((n - 1) % 5);
				cout << n << endl;
				if (n <= a[j]) break;
				n -= a[j];
				if (n <= (n-1) % 5)	break;
				cout << n << endl;
			}
		}
		cout << '0' << endl;
	}
}