// AOJ 0164
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n;
	while (cin >> n){
		if (cin.eof()) break;
		vector <int> kotori;
		int a, kotori_cnt = 0, cnt = 0, honoka = 32;
		for (int i = 0; i < n; i++){
			cin >> a;
			kotori.push_back(a);
		}
		while (honoka > 0){
			if (cnt % 2 == 0){
				// umi
				honoka -= ((honoka - 1) % 5);
			}
			else {
				// kotori
				honoka -= (kotori[kotori_cnt]);
				kotori_cnt = (kotori_cnt + 1) % n;
				// cout << "*** DEBUG " << kotori_cnt << endl;
			}
			cnt++;
			if (honoka <= 0) break;
			cout << honoka << endl;
		}
		cout << 0 << endl;
	}

	return 0;
}