Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    def Chk(a, pos):
        cnt = 0
        tmp = 0

        for a in A:
            tmp += a

            if pos and tmp < 1:
                cnt += 1 - tmp
                tmp = 1
            elif not pos and tmp > -1:
                cnt += 1 + tmp
                tmp = -1

            pos = not pos
        return cnt

    print(min(Chk(A, True), Chk(A, False)))
    
if __name__ == '__main__':
    main()

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

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

def Chk(a, pos):
    cnt = 0
    tmp = 0
    
    for a in A:
        tmp += a
        
        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1
        
        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(a, False)))

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    A = []
    A_append = A.append
    cnt = 0

    for i in range(n-1):
        A_append((a[i]))
        x = sum(A)
        if x > 0 and x + a[i+1] > 0:
            y = -(x + a[i+1] + 1)
            cnt -= y
            a[i+1] += y

        elif x < 0 and x + a[i+1] < 0:
            y = -(x - a[i+1]+ 1)
            cnt += y
            a[i+1] += y

    if sum(a) == 0:
        cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    A = []
    A_append = A.append
    cnt = 0

    for i in range(n-1):
        A_append((a[i]))
        x = sum(A) + a[i+1]
        if sum(A) > 0 and x > 0:
            y = -(x+1)
            cnt -= y
            a[i+1] += y

        elif sum(A) < 0 and x < 0:
            y = -(sum(A) - a[i+1])-1
            cnt += y
            a[i+1] += y

    if sum(a) == 0:
        cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    A = []
    A_append = A.append
    cnt = 0

    for i in range(n-1):
        A_append((a[i]))
        x = sum(A) + a[i+1]
        if sum(A) > 0 and x > 0:
            y = -(x+1)
            cnt -= y
            a[i+1] += y

        elif sum(A) < 0 and x < 0:
            y = -(sum(A) - a[i+1])-1
            cnt += y
            a[i+1] += y

    if sum(a) == 0:
        cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    A = []
    A_append = A.append
    cnt = 0

    for i in range(n-1):
        A_append((a[i]))
        x = sum(A) + a[i+1]
        if sum(A) > 0 and x > 0:
            y = abs(x)+1
            cnt += y
            a[i+1] -= y

        elif sum(A) < 0 and x < 0:
            y = abs(sum(A) - a[i+1])-1
            cnt += y
            a[i+1] += y

    if sum(a) == 0:
        cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    A = []
    A_append = A.append
    cnt = 0

    for i in range(n-1):
        A_append((a[i]))
        x = sum(A) + a[i+1]
        if sum(A) > 0 and x > 0:
            y = abs(x)+1
            cnt += y
            a[i+1] -= y

        elif sum(A) < 0 and x < 0:
            y = abs(sum(A) - a[i+1])-1
            cnt += y
            a[i+1] += y

    if sum(a) == 0:
        cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    A = ()
    A_append = A.append
    cnt = 0

    for i in range(n-1):
        A_append(a[i])
        x = sum(A) + a[i+1]
        if sum(A) > 0 and x > 0:
            y = abs(x)+1
            cnt += y
            a[i+1] -= y

        elif sum(A) < 0 and x < 0:
            y = abs(sum(A) - a[i+1])-1
            cnt += y
            a[i+1] += y

    if sum(a) == 0:
        cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    A = []
    A_append = A.append

    cnt = 0


    for i in range(n-1):
        A_append(a[i])
        x = sum(A) + a[i+1]
        if sum(A) > 0 and x > 0:
            y = abs(x)+1
            cnt += y
            a[i+1] -= y

        elif sum(A) < 0 and x < 0:
            y = abs(sum(A) - a[i+1])-1
            cnt += y
            a[i+1] += y

    if sum(a) == 0:
        cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
A = []
cnt = 0

for i in range(n-1):
    A.append(a[i])
    x = sum(A) + a[i+1]
    if sum(A) > 0 and x > 0:
        y = abs(x)+1
        cnt += y
        a[i+1] -= y

    elif sum(A) < 0 and x < 0:
        y = abs(sum(A) - a[i+1])-1
        cnt += y
        a[i+1] += y

if sum(a) == 0:
    cnt += 1

print(cnt)

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
A = []
cnt = 0

for i in range(n-1):
    A.append(a[i])
    if sum(A) > 0 and sum(A) + a[i+1] > 0:
        cnt += abs(sum(A) + a[i+1])+1
        a[i+1] -= abs(sum(A) + a[i+1])+1

    elif sum(A) < 0 and sum(A) + a[i+1] < 0:
        cnt += abs(sum(A) - a[i+1])-1
        a[i+1] += abs(sum(A) - a[i+1])-1

if sum(a) == 0:
    cnt += 1

print(cnt)

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
A = []
cnt = 0

for i in range(n-1):
    A.append(a[i])
    if sum(A) > 0 and sum(A) + a[i+1] > 0:
        cnt += abs(sum(A) + a[i+1])+1
        a[i+1] -= abs(sum(A) + a[i+1])+1


    elif sum(A) < 0 and sum(A) + a[i+1] < 0:
        cnt += abs(sum(A) - a[i+1])-1
        a[i+1] += abs(sum(A) - a[i+1])-1


if sum(a) == 0:
    cnt += 1

print(cnt)

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
A = []
cnt = 0

for i in range(n-1):
    A.append(a[i])
    if sum(A) > 0:
        while sum(A) + a[i+1] >= 0:
            a[i+1] -= 1
            cnt += 1

    elif sum(A) < 0:
        while sum(A) + a[i+1] <= 0:
            a[i+1] += 1
            cnt += 1

if sum(a) == 0:
    cnt += 1

print(cnt)

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
A = []
cnt = 0

for i in range(n-1):
    A.append(a[i])
    if sum(A) > 0:
        while sum(A) + a[i+1] >= 0:
            a[i+1] -= 1
            cnt += 1

    elif sum(A) < 0:
        while sum(A) + a[i+1] <= 0:
            a[i+1] += 1
            cnt += 1
            
if sum(a) == 0:
    cnt += 1

print(cnt)

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))