Problem p03741 (python)

Fixed submission:
_ = int(input())
A = list(map(int, input().split()))

ret = float('inf')

sign = 1
s = 0
k = 0
for a in A:
    if sign * (s + a) > 0:
        s += a
    else:
        k += abs(s + a) + 1
        s = sign
    sign *= -1
ret = min(ret, k)

sign = -1
s = 0
k = 0
for a in A:
    if sign * (s + a) > 0:
        s += a
    else:
        k += abs(s + a) + 1
        s = sign
    sign *= -1

ret = min(ret, k)


print(ret)

Buggy submission (verdict: Runtime Error):
_ = int(input())
A = list(map(int, input().split()))


def solve(i, s, k, sign):
    if i >= len(A):
        return k

    if sign * (s + A[i]) > 0:
        return solve(i + 1, s + A[i], k, sign * -1)
    else:
        return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1)


print(min(solve(0, 0, 0, 1), solve(0, 0, 0, -1)))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))


def solve(i, s, k, sign):
    if i >= N:
        return k

    if sign * (s + A[i]) > 0:
        return solve(i + 1, s + A[i], k, sign * -1)
    else:
        return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1)


print(min(solve(0, 0, 0, 1), solve(0, 0, 0, -1)))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))


def solve(i, s, k, sign):
    if i == N:
        return k

    if sign * (s + A[i]) > 0:
        return solve(i + 1, s + A[i], k, sign * -1)
    else:
        return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1)


a = solve(0, 0, 0, 1)
b = solve(0, 0, 0, -1)

print(a)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))


def solve(i, s, k, sign):
    if i == N:
        return k

    if sign * (s + A[i]) > 0:
        return solve(i + 1, s + A[i], k, sign * -1)
    else:
        return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1)


a = solve(0, 0, 0, 1)
b = solve(0, 0, 0, -1)

if a < b:
    print(a)
else:
    print(b)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))


def solve(i, s, k, sign):
    if i == N:
        return k

    if sign * (s + A[i]) > 0:
        return solve(i + 1, s + A[i], k, sign * -1)
    else:
        return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1)


try:
    print(min(solve(0, 0, 0, 1), solve(0, 0, 0, -1)))
except TypeError:
    print(1)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))


def solve(i, s, k, sign):
    if i == N:
        return k

    if sign * (s + A[i]) > 0:
        return solve(i + 1, s + A[i], k, sign * -1)
    else:
        return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1)


try:
    print(min(solve(0, 0, 0, 1), solve(0, 0, 0, -1)))
except ValueError:
    print(1)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))


def solve(i, s, k, sign):
    if i == N:
        return k

    if sign * (s + A[i]) > 0:
        return solve(i + 1, s + A[i], k, sign * -1)
    else:
        return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1)


try:
    print(min(solve(0, 0, 0, 1), solve(0, 0, 0, -1)))
except IndexError:
    print(1)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))


def solve(i, s, k, sign):
    if i == N:
        return k

    if sign * (s + A[i]) >= 0:
        return solve(i + 1, s + A[i], k, sign * -1)
    else:
        return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1)


print(min(solve(0, 0, 0, 1), solve(0, 0, 0, -1)))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))


def solve(i, s, k, plus):
    if i == N:
        return k

    if plus:
        if s + A[i] <= 0:
            return solve(i + 1, 1, k + abs(s + A[i]) + 1, False)
        else:
            return solve(i + 1, s + A[i], k, False)
    else:
        if s + A[i] >= 0:
            return solve(i + 1, -1, k + abs(s + A[i]) + 1, True)
        else:
            return solve(i + 1, s + A[i], k, True)


print(min(solve(0, 0, 0, True), solve(0, 0, 0, False)))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))


def solve(i, s, k, plus):
    if i == N:
        return k

    if plus:
        if s + A[i] <= 0:
            return solve(i + 1, 1, k + abs(s + A[i]) + 1, False)
        else:
            return solve(i + 1, s + A[i], k, False)
    else:
        if s + A[i] >= 0:
            return solve(i + 1, -1, k + abs(s + A[i]) + 1, True)
        else:
            return solve(i + 1, s + A[i], k, True)


print(min(solve(0, 0, 0, True), solve(0, 0, 0, False)))