#include<bits/stdc++.h>

using namespace std;

int main(){
	while(true){
		int many = 32;
		vector<int> get;
		int a;
		scanf("%d", &a);
		if(!a){
			return 0;
		}
		get.resize(a);
		int i = 0;
		for(int i = 0; i < a; i++){
			scanf("%d", &get[i]);
		}
		bool now_ichiro = true;
		while(many != 0){
			if(now_ichiro){
				many -= (many - 1) % 5;
				now_ichiro = false;
			}
			else{
				many = max(0, many - get[i % a]);
				i++;
				now_ichiro = true;
			}
			printf("%d\n", many);
		}
	}
	return 0;
}