a[9999],n;main(j){for(;~scanf("%d",a+n)?++n:n>3?a[n-2]+=a[n],n--:n-~j--?printf("%d%c",!j?n=a[3]?2:!!a[2]:a[-j],j?32:10):0;);}