#include <cstdio>
#include <cstring>
main(){
int n,a[25];
while(scanf("%d",&n),n){
memset(a,0,sizeof(a));
for(int i = 0;i < n;i++)scanf("%d",a+i);
int i = 0,s = 32,t = 1;
while(s != 0){
(t)?s -= ((s - 1) % 5):s -= a[i++ % n];
if(s < 0)s = 0;
printf("%d\n",s);
t = !t;
}
}
}