#include <iostream>
#include <cstring>
using namespace std;

int main(){
	int n,a[25];
	while(cin >> n,n){
		memset(a,0,sizeof(a));
		for(int i = 0;i < n;i++){
			cin >> a[i];
		}
		//ツ暗ェツ郎ツづ個づつォツづ控RUEツ，ツ篠淞郎ツづ個づつォツづ孝ALSE
		bool turn = true;
		int i = 0,sum = 32;;
		while(sum != 0){
			if(turn)sum -= ((sum - 1) % 5);
			else{sum -= a[i++ % n];}
			if(sum < 0)sum = 0;
			cout << sum << endl;
			turn = !turn;
		}
	}
	return 0;
}