//
//  164.cpp
//  
//
//  Created by Minote Tomoki on 2015/06/01.
//
//

#include <stdio.h>

#define INITIAL 32

int number=INITIAL;
int seq[25]={0};
int n;

int step=0;

void turn() {
    if(number-1>0) {
        number-=((number-1)%5);
    }else{
        number--;
        return;
    }
    
    printf("%d\n",number);
    
    int tmp = (step++)%n;
    
    number-=seq[tmp];
}

int main(void) {
    
    for(;;) {
        number=INITIAL;
        step=0;
        scanf("%d",&n);
        if(n==0)break;
        for(int i=0;i<n;i++){
            scanf("%d",&seq[i]);
        }
        
        while(number>0) {
            turn();
            if(number>0)printf("%d\n",number);
        }
        printf("0\n");
        
    }
    return 0;
}