#include<iostream>

using namespace std;

int main(){
  int in;
  while(cin >> in){
    if(in == 0) break;
    int ohajiki = 32;

    int data[in];
    for(int i = 0; i < in; i++){
      cin >> data[i];
    }

    int j = 0;

    while(1){
      ohajiki -= (ohajiki-1) % 5;
      if(ohajiki <= 0) break;
      cout << ohajiki << endl;
      ohajiki -= data[j];
      if(ohajiki <= 0) break;
      cout << ohajiki <<endl;
      j++;
      if(j == in) j = 0;
    }
    cout << "0" << endl; 
  }

  return 0;
}