#include <bits/stdc++.h>
using namespace std;
int main(void){
    std::deque<int> deq;
    int n,a,tmp,hoge;
    hoge=32;
    tmp=0;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            for (int i=0;i<n;i++) {
                cin>>a;
                deq.emplace_back(a);
            }
            while (n>1) {
                hoge=hoge-((hoge-1)%5);
                cout<<hoge<<endl;
                hoge=hoge-deq[tmp];
                if (hoge<=0) {
                    cout<<0<<endl;
                    break;
                } else {
                    cout<<hoge<<endl;
                    if (tmp!=n-1) {
                        tmp++;
                    } else {
                        tmp=0;
                    }
                }
            }
        }
        hoge=32;
        tmp=0;
        deq.clear();
    }
}

