/*
	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;
}