#include<stdio.h>
int main()
{
	int length,n,i,a[25];
	while(scanf("%d",&length),length)
	{
		for(i = 0; i < length; ++i)
			scanf("%d",&a[i]);
		bool isJiro=false;
		i = 0;
		n = 32;
		do
		{
			if(isJiro)
			{
				n -= a[i];
				i = (i+1)%length;
			}
			else
			{
				n -= (n-1)%5;
			}
			printf("%d\n",n>0?n:0);
			isJiro = !isJiro;
		}while(n>0);
	}
	return 0;
}