Problem p02984 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
S = sum(A)//2
S = 2*(S - sum(A[1::2]))
ans = [S]
for i in range(1,N):
  ans.append(2*A[i-1]-ans[i-1])
print(' '.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
if A[0] == 0 or A[N-1] == 0:
  A_tmp = A[0]
  A_ = A[1:N]
  A_.append(A_tmp)
  A = A_
  flag = 1
else:
  flag = 0
if A[0]<A[N-1]:
  start = A[0]
else:
  start = A[N-1]
for i in range(2*start-2,1,-2):
  ans = [i]
  A_tmp = A[:]
  A_tmp[0] -= ans[0]//2
  A_tmp[N-1] -= ans[0]//2 
  for j in range(1,N):
    if A_tmp[j-1]<A_tmp[j]:
      ans.append(A_tmp[j-1]*2)
      A_tmp[j] -= ans[j]//2
      A_tmp[j-1] -= ans[j]//2
    else:
      ans.append(A_tmp[j]*2)
      A_tmp[j] -= ans[j]//2
      A_tmp[j-1] -= ans[j]//2
  if sum(A_tmp)==0:
    break
if flag == 1:
  tmp = [0]*N
  tmp[1:] = ans[:N-1]
  tmp[0] = ans[N-1]
  ans = tmp
ans = map(str,ans)
print(' '.join(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
if A[0] == 0 or A[N-1] == 0:
  A_tmp = A[0]
  A_ = A[1:N]
  A_.append(A_tmp)
  A = A_
  flag = 1
else:
  flag = 0
if A[0]<A[N-1]:
  start = A[0]
else:
  start = A[N-1]
for i in range(2,2*start+1,2):
  ans = [i]
  A_tmp = A[:]
  A_tmp[0] -= ans[0]//2
  A_tmp[N-1] -= ans[0]//2 
  for j in range(1,N):
    if A_tmp[j-1]<A_tmp[j]:
      ans.append(A_tmp[j-1]*2)
      A_tmp[j] -= ans[j]//2
      A_tmp[j-1] -= ans[j]//2
    else:
      ans.append(A_tmp[j]*2)
      A_tmp[j] -= ans[j]//2
      A_tmp[j-1] -= ans[j]//2
  if sum(A_tmp)==0:
    break
if flag == 1:
  tmp = [0]*N
  tmp[1:] = ans[:N-1]
  tmp[0] = ans[N-1]
  ans = tmp
ans = map(str,ans)
print(' '.join(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
if A[0] == 0 or A[N-1] == 0:
  A_tmp = A[0]
  A_ = A[1:N]
  A_.append(A_tmp)
  A = A_
  flag = 1
else:
  flag = 0
if A[0]<A[N-1]:
  start = A[0]
else:
  start = A[N-1]
for i in range(2*start,1,-2):
  ans = [i]
  A_tmp = A[:]
  A_tmp[0] -= ans[0]//2
  A_tmp[N-1] -= ans[0]//2 
  for j in range(1,N):
    if A_tmp[j-1]<A_tmp[j]:
      ans.append(A_tmp[j-1]*2)
      A_tmp[j] -= ans[j]//2
      A_tmp[j-1] -= ans[j]//2
    else:
      ans.append(A_tmp[j]*2)
      A_tmp[j] -= ans[j]//2
      A_tmp[j-1] -= ans[j]//2
  if sum(A_tmp)==0:
    break
if flag == 1:
  tmp = [0]*N
  tmp[1:] = ans[:N-1]
  tmp[0] = ans[N-1]
  ans = tmp
ans = map(str,ans)
print(' '.join(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
if A[0] == 0 or A[N-1] == 0:
  A_tmp = A[0]
  A_ = A[1:N]
  A_.append(A_tmp)
  A = A_
  flag = 1
else:
  flag = 0
if A[0]<A[N-1]:
  start = A[0]
else:
  start = A[N-1]
for i in range(2*start,1,-2):
  ans = [i]
  A_tmp = A[:]
  A_tmp[0] -= ans[0]//2
  A_tmp[N-1] -= ans[0]//2 
  for j in range(1,N):
    if A_tmp[j-1]<A_tmp[j]:
      ans.append(A_tmp[j-1]*2)
      A_tmp[j] -= ans[j]//2
      A_tmp[j-1] -= ans[j]//2
    else:
      ans.append(A_tmp[j]*2)
      A_tmp[j] -= ans[j]//2
      A_tmp[j-1] -= ans[j]//2
  if sum(A_tmp)==0:
    break
if flag == 1:
  tmp = [0]*N
  tmp[1:] = ans[:N-1]
  tmp[0] = ans[N-1]
  ans = tmp
print(ans)