#include<iostream>
using namespace std;

int main(){
  int i,n,o;
  int a[25];

  while(1){
    cin >> n;
    if(!n)break;

    for(i=0;i<n;i++)cin >> a[i];

    o = 32;
    i = 0;
    while(1){
      o -= (o-1)%5;
      cout << o << endl;
      if(!o)break;

      o -= a[i];
      if(o<0)o=0;
      i++;
      if(i==n)i=0;
      cout << o << endl;
      if(!o)break;
    }
  }
}