import sequtils proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = var minus = false block: let k = getchar_unlocked() if k == '-' : minus = true else: result = 10 * result + k.ord - '0'.ord while true: let k = getchar_unlocked() if k < '0' or k > '9': break result = 10 * result + k.ord - '0'.ord if minus: result *= -1 let n = scan() var A = newSeqWith(n+1,scan()) for i in countdown(n, 3): A[i-2] += A[i] if n >= 3 and A[2] != 0: echo 2,"\n",A[0]," ",A[1]," ",A[2] elif n >= 2 and A[1] != 0: echo 1,"\n",A[0]," ",A[1] else: echo 0,"\n",A[0]