#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;

int main(){
    int a[10000];
    int cnt,i,turn,n;
    while(cin>>n&&n){
        turn=0,cnt=31;
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        cout<<"31"<<endl;
        while(cnt>=a[turn%n]){
            cnt-=a[turn%n];
            turn++;
            if(cnt==0) break;
            cout<<cnt<<endl;
            cnt-=(cnt+4)%5;
            cout<<cnt<<endl;
        }
        cout<<"0"<<endl;
    }
    return 0;
}
