#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n=31;
	int size;
	while(cin>>size){
		n=31;
		if(size==0)break;
		int dt[size];
		rep(i,size){
			cin>>dt[i];
		}
		int turn=1;
		int ite=0;
		while(n){
			if(n<0)break;
			if(turn%2==1){
				n-=(n-1)%5;
				if(n<0) cout<<0<<endl;
				cout<<n<<endl;
			}else{
				n-=dt[ite%size];
				if(n<0) cout<<0<<endl;
				cout<<n<<endl;
				ite++;
			}
			turn++;
		}
	}
	return 0;
}