#include <iostream>
#include <vector>

using namespace std;

int main(void){
  int n;
  while(cin>>n,n){
    vector<int> ary(n);
    for(int i = 0 ; i < n ; i ++)cin>>ary[i];
    int cnt = 31;
    int i = 0;
    int c = 0;
    while(cnt>=0){
      //cout<<" a ";
      if(cnt < 0)break;
      cout<<cnt<<endl;
      cnt -= ary[i];
      i = (i+1)%n;
      //cout<<" b ";
      if(cnt < 0)break;
      cout<<cnt<<endl;
      cnt -= (cnt - 1) % 5;
    }
    cout<<0<<endl;
  }
}