#include <iostream>
using namespace std;

int operate[25];
int main()
{
	int n;
	while(cin >> n){
		if(!n)
			break;
		int m = 31;
		for(int i=0;i<n;i++){
			cin >> operate[i];
		}
		int pos = 0;
		while(m>0){
			m -= (m-1)%5;
			if(m<=0)
				break;
			cout << m << endl;
			m -= operate[pos];
			if(m<=0)
				break;
			cout << m << endl;
			pos++;
			if(pos==n)
				pos = 0;
		}
		cout << 0 << endl;
	}
	return 0;
}