#include<iostream>
using namespace std;

int main()
{
    int n, o, a[25];

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

        o = 32;

        for( int i = 0; i < n; i++ )
            cin >> a[i];

        int i = 0;
        while( o != 0 )
        {
            o -= ( o - 1 ) % 5;
            if( o < 0 )
                o = 0;
            cout << o << endl;
    
            if( o == 0 )
                break;

            o -= a[i%n];
            if( o < 0 )
                o = 0;
            cout << o << endl;

            i++;
        }
    }
    return 0;
}
