#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
  int i, n, m, ohajiki;
  vector<int> sequence;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0; i<n; ++i){
      cin >> m;
      sequence.push_back(m);
    }

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

      if(sequence[i] >= ohajiki) ohajiki = 0;
      else ohajiki -= sequence[i];
      cout << ohajiki << endl;
      if(ohajiki == 0) break;
      if(i == sequence.size()-1) i = 0;
      else ++i;
    }

    sequence.clear();
  }

  return 0;
}