#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n;
  while(cin >> n){
    if( n == 0 ) break;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];

    int j = 0;
    int o = 32;
    int t = 0;
    while(o != 0){
      if( t%2 == 0 ) o -= (o-1)%5;
      else{
        o -= a[j];
        j++;
        j %= n;
      }
      if( o < 0 ) o = 0;
      cout << o << endl;
      t++;
    }

  }

  return 0;
}

// EOF