import strutils, sequtils, math var a = newSeq[int64](100010) proc f(i, n: int, b: seq[int64]): int64 = if i > n: return -1 if i mod 2 == 0: a[i] = a[i-1] - b[i-1] if a[i] <= 0 or 10^18 < a[i]: return abs(a[i]) return f(i+1, n, b) else: a[i] = b[i-1] - a[i-1] if a[i] <= 0 or 10^18 < a[i]: return abs(a[i]) return f(i+1, n, b) when isMainModule: var n = stdin.readLine.parseInt b = newSeq[int64](n) for i in 0..n-1: b[i] = stdin.readLine.parseBiggestInt if n == 1: if b[0] <= 1: echo "-1" else: echo 2 echo 1 echo b[0] - 1 quit() # var p = 1 # while p < b[0]: # a[0] = p # echo f(1, n, b) # p += 1 var l: int64 = -1 r: int64 = b[0] cnt: int = 0 pos: int64 = -1 while r - l > 10 and cnt < 1000: var x = (l + l + r) div 3 y = (l + r + r) div 3 a[0] = x let xf = f(1, n, b) a[0] = y let yf = f(1, n, b) if xf > yf: l = x else: r = y cnt += 1 for i in max(1, l-100)..min(b[0]-1, l+100): a[0] = i if f(1, n, b) == -1: echo n+1 for i in 0..n: echo a[i] quit() for i in max(1, r-100)..min(b[0]-1, r+100): a[0] = i if f(1, n, b) == -1: echo n+1 for i in 0..n: echo a[i] quit() echo "-1"