#include<bits/stdc++.h>
using namespace std;

int main()
{
  int array[25];
  int n;
  int now;
  int cnt;
  int turn; //1:ichiro 0:jiro

  while( cin >> n, n ) {
    now = 32;
    turn = 1;
    cnt = 0;
    for(int i=0; i<n; i++) {
      cin >> array[i];
    }

    while( now > 0 ) {
      if( cnt >= n ) cnt = 0;
      if( turn ) {
	now -= (now - 1) % 5;
	turn = 0;
      } else {
	now -= array[cnt];
	cnt++;
	turn = 1;
      }
      cout << max(0, now) << endl;
    }

  }

}