#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef long long  ll;

/** Problem0164 : Ohajiki Game **/
int main()
{
	int ohajiki=32;
	vector<int> take;
	int n;
	
	while (cin>>n, n) {
		ohajiki = 32;
		take.clear();
		
		rep(i, n) {
			int a;
			cin>>a; take.push_back(a);
		}
		
		for (int i=0; ; i++) {
			ohajiki -= (ohajiki-1)%5;
			if (ohajiki<=0) {
				ohajiki=0;
				break;
			}
			cout << ohajiki << endl;


			ohajiki -= take[i%take.size()];
			if (ohajiki<=0) {
				ohajiki=0;
				break;
			}
			cout << ohajiki << endl;
		}
		cout << ohajiki << endl;
	}
	return 0;
}