#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main()
{
    int jiro[25];
    int l;
    int n;
    int index;
    while(cin >> l && l)
    {   
        n=32;
        index=-1;
        for(int i=0;i<l;++i) cin >> jiro[i];
        while(n)
        {   
            n -= (n-1)%5;
            cout << n << endl;
            n = max(n-jiro[++index], 0); 
            if(index >= l-1) index = -1; 
            cout << n << endl;
        }   
    }   
}