// 0164
#include <iostream>
#include <vector>
using namespace std;

int main(){

	while(1){
		int l, num;
		vector<int> a;

		cin>>l;
		if(l == 0)
			break;

		for(int i=0;i<l;i++){
			cin>>num;
			a.push_back(num);
		}

		bool turn = true;
		int ohajiki = 32, j = 0;

		while(ohajiki != 0){
			if(turn){
				ohajiki -= (ohajiki-1)%5;
			}else{
				ohajiki -= a[j];
				j++;
				if(j == l)
					j = 0;
			}

			if(ohajiki < 0)
				ohajiki = 0;

			cout<<ohajiki<<endl;
			turn = !(turn);
		}
	}

	return 0;
}