#include <iostream>
using namespace std;

int main() {
	int n;
	while(cin >> n, n) {
		int jiro[32];
		for(int i = 0; i < n; i++)
			cin >> jiro[i];

		int ohajiki = 32;
		int turn = 0;

		while(ohajiki) {
			if(turn % 2) {
				ohajiki = ohajiki - jiro[(turn / 2) % n];
				ohajiki = ohajiki < 0 ? 0 : ohajiki;
			}
			else {
				ohajiki = ohajiki - (ohajiki - 1) % 5;
			}
			cout << ohajiki << endl;
			turn++;
		}
	}
}