#include<iostream>
using namespace std;
int main(){
  int i,n,hess,bell[100],riri=0,math=32;
  while(1){
    riri=0;
    cin >> n;
    if(n==0){
      break;
    }
    for(i=0;i<n;i++){
      cin >> bell[i];
    }
    hess=i;
    while(1){
      math-=(math-1)%5;

      if(math<0){
	math=0;
      }
      cout << math << endl;
      if(math<=0){
	math=32;
	break;
      }
      math-=bell[riri];
      riri++;

      if(math<0){
	math=0;
      }
      cout << math << endl;
      if(riri==hess){
	riri=0;
      }
      if(math<=0){
	math=32;
	break;
      }
    }
  }
  return (0);
}