#include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main(){
	int n;
	while(cin >> n, n) {
		int s = 32, cnt = 0, a[25] = {};
		rep(i,n) {
			cin >> a[i];
		}
		while(1) {
			s -= (s-1)%5;
			if(s<=0) {
				cout << 0 << endl;
				break;
			}
			cout << s << endl;
			s -= a[cnt%n];
			if(s<=0) {
				cout << 0 << endl;
				break;
			}
			++cnt;
			cout << s << endl;
		}
	}
    return 0;
}