Buggy python submission (verdict: Time Limit Exceeded):

def check1(a):
  sum = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        return (i, -abs(sum)-1)
    else:
      sum += a[i]
      if(sum <= 0):
        return (i, abs(sum)+1)
  return True

def check2(a):
  sum = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        return (i, abs(sum)+1)
    else:
      sum += a[i]
      if(sum >= 0):
        return (i, -abs(sum)-1)
  return True



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = 0
ans2 = 0

while(True):
  c = check1(a)
  if(c == True):
    break

  a[c[0]] += c[1]
  ans1 += abs(c[1])


while(True):
  c = check2(a2)
  if(check2(a2) == True):
    break
  a2[c[0]] += c[1]
  ans2 += abs(c[1])


print(ans1) if(ans1<ans2) else print(ans2)

Fixed submission:

def check1(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
    else:
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
  return ans

def check2(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
    else:
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
  return ans



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = check1(a)
ans2 = check2(a2)


print(ans1) if(ans1<ans2) else print(ans2)

Buggy python submission (verdict: Time Limit Exceeded):

def check1(a):
  sum = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        return (i, -1)
    else:
      sum += a[i]
      if(sum <= 0):
        return (i, 1)
  return True

def check2(a):
  sum = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        return (i, 1)
    else:
      sum += a[i]
      if(sum >= 0):
        return (i, -1)
  return True



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = 0
ans2 = 0

while(True):
  c = check1(a)
  if(c == True):
    break

  a[c[0]] += c[1]
  ans1 += 1


while(True):
  c = check2(a2)
  if(check2(a2) == True):
    break
  a2[c[0]] += c[1]
  ans2 += 1


print(ans1) if(ans1<ans2) else print(ans2)

Fixed submission:

def check1(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
    else:
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
  return ans

def check2(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
    else:
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
  return ans



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = check1(a)
ans2 = check2(a2)


print(ans1) if(ans1<ans2) else print(ans2)

Buggy python submission (verdict: Time Limit Exceeded):

def check1(a):
  sum = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(a[i] >= 0 or sum >= 0):
        return (i, -1)
    else:
      sum += a[i]
      if(a[i] <= 0 or sum <= 0):
        return (i, 1)
  return True

def check2(a):
  sum = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(a[i] <= 0 or sum <= 0):
        return (i, 1)
    else:
      sum += a[i]
      if(a[i] >= 0 or sum >= 0):
        return (i, -1)
  return True



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = 0
ans2 = 0

while(True):
  c = check1(a)
  if(c == True):
    break

  a[c[0]] += c[1]
  ans1 += 1


while(True):
  c = check2(a2)
  if(check2(a2) == True):
    break
  a2[c[0]] += c[1]
  ans2 += 1


print(ans1) if(ans1<ans2) else print(ans2)

Fixed submission:

def check1(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
    else:
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
  return ans

def check2(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
    else:
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
  return ans



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = check1(a)
ans2 = check2(a2)


print(ans1) if(ans1<ans2) else print(ans2)

Buggy python submission (verdict: Time Limit Exceeded):
n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]


def check(a):
  sum = 0
  for i in range(len(a)):
    if(i == 0):
      if(a[i] == 0):
        return (i, +1)
      sum += a[0]
      continue
    if(sum > 0):
      sum += a[i]
      if(a[i] == 0 or sum >= 0):
        return (i, -1)

    elif(sum < 0):
      sum += a[i]
      if(a[i] == 0 or sum <= 0):
        return (i, +1)
    else:
      if(a[i-1] > 0):
        return (i, -1)
      else:
        return (i, +1)



  return True

ans = 0
while(True):
  c = check(a)
  if(c == True):
    break

  a[c[0]] += c[1]

  ans += 1



print(ans)

Fixed submission:

def check1(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
    else:
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
  return ans

def check2(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
    else:
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
  return ans



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = check1(a)
ans2 = check2(a2)


print(ans1) if(ans1<ans2) else print(ans2)

Buggy python submission (verdict: Time Limit Exceeded):
n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]


def check(a):
  sum = 0
  for i in range(len(a)):
    if(i == 0):
      sum += a[0]
      continue
    if(sum > 0):
      sum += a[i]
      if(a[i] == 0 or sum >= 0):
        return (i, -1)

    elif(sum < 0):
      sum += a[i]
      if(a[i] == 0 or sum <= 0):
        return (i, +1)
    else:
      if(a[i-1] > 0):
        return (i, -1)
      else:
        return (i, +1)



  return True

ans = 0
while(True):
  c = check(a)
  if(c == True):
    break

  a[c[0]] += c[1]

  ans += 1



print(ans)

Fixed submission:

def check1(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
    else:
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
  return ans

def check2(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
    else:
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
  return ans



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = check1(a)
ans2 = check2(a2)


print(ans1) if(ans1<ans2) else print(ans2)

Buggy python submission (verdict: Time Limit Exceeded):
n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]


def check(a):
  sum = 0
  for i in range(len(a)):
    if(i == 0):
      sum += a[0]
      continue
    if(sum > 0):
      sum += a[i]
      if(a[i] == 0 or sum >= 0):
        return (i, -1)

    else:
      sum += a[i]
      if(a[i] == 0 or sum <= 0):
        return (i, +1)



  return True

ans = 0
while(True):
  c = check(a)
  if(c == True):
    break

  a[c[0]] += c[1]

  ans += 1



print(ans)

Fixed submission:

def check1(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
    else:
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
  return ans

def check2(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
    else:
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
  return ans



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = check1(a)
ans2 = check2(a2)


print(ans1) if(ans1<ans2) else print(ans2)