Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
    h, w = map(int, input().split())

    m = []
    wall = ['.' for _ in range(w + 2)]
    m.append(wall)
    for _ in range(w):
        r = ["."] + list(input()) + ["."]
        m.append(r)
    m.append(wall)

    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if m[i][j] == '#':
                f = any([m[i + x][j + y] == "#" for (x, y) in ((1, 0), (-1, 0), (0, 1), (0, -1))])
                if not f:
                    print("No")
                    exit()
    else:
        print("Yes")


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    h, w = map(int, input().split())

    m = []
    wall = ['.' for _ in range(w + 2)]
    m.append(wall)
    for _ in range(h):
        r = ["."] + list(input()) + ["."]
        m.append(r)
    m.append(wall)

    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if m[i][j] == '#':
                f = any([m[i + x][j + y] == "#" for (x, y) in ((1, 0), (-1, 0), (0, 1), (0, -1))])
                if not f:
                    print("No")
                    exit()
    else:
        print("Yes")


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from itertools import accumulate

    n = int(input())
    a = list(map(int, sys.stdin.readline().split()))
    b = list(accumulate(a))

    ans = 0
    for i, x in enumerate(b):
        if x == 0: ans += 1
        for y in b[:i]:
            if x - y == 0:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import sys
    from itertools import accumulate
    from collections import Counter

    n = int(input())
    a = list(map(int, sys.stdin.readline().split()))
    b = [0] + list(accumulate(a))
    c = Counter(b)

    ans = 0
    for v in c.values():
        ans += v * (v - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(map(int,input().split()))
ans=0
for i in range(n):
  for j in range(i+1,n+1):
    ans+=sum(s[i:j])==0
print(ans)

Fixed submission:
def main():
    import sys
    from itertools import accumulate
    from collections import Counter

    n = int(input())
    a = list(map(int, sys.stdin.readline().split()))
    b = [0] + list(accumulate(a))
    c = Counter(b)

    ans = 0
    for v in c.values():
        ans += v * (v - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
c=0
for i in range(n):
  for j in range(i+1,n+1):
    s=l[i:j]
    if sum(s)==0:
      c+=1
print(c)

Fixed submission:
def main():
    import sys
    from itertools import accumulate
    from collections import Counter

    n = int(input())
    a = list(map(int, sys.stdin.readline().split()))
    b = [0] + list(accumulate(a))
    c = Counter(b)

    ans = 0
    for v in c.values():
        ans += v * (v - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n,m,x = map(int,input().split())
a = [int(input()) for _ in range(m)]
c = sum(0+a[i] for i in range(len(a)) if x<i)
print(c)

Fixed submission:
n,m,x=map(int,input().split())
s=sum(int(i)<x for i in input().split())
print(min(s,m-s))
Buggy python submission (verdict: Runtime Error):
n=int(input())
d,x=map(int,input().split())
print(sum(d//(int(input()+1) for _ in range(n))))

Fixed submission:
n=int(input())
d,x=map(int,input().split())
ans=x+n
for _ in range(n):
  ans+=(d-1)//int(input())
print(ans)
Buggy python submission (verdict: Runtime Error):
n=input()
print("Four" if len(set(map(int,input().split())))==4 else "Three")

Fixed submission:
n=input()
print("Four" if len(set(map(str,input().split())))==4 else "Three")
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    l = len(str(n))
    v = int(str(n)[0]) + 9 * (l - 1)
    if str(n)[1:] == '9' * (l - 1):
        print(ans)
    else:
        print(v-1)

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    l = len(str(n))
    v = int(str(n)[0]) + 9 * (l - 1)
    if str(n)[1:] == '9' * (l - 1):
        print(v)
    else:
        print(v-1)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
s=str(input())
f= s[a]=="-" and len(s)==a+b+1
print("Yes" if f is True else "No')

Fixed submission:
a,b=map(int,input().split())
s=str(input())
f= s[a]=="-" and len(s)==a+b+1 and s.count("-")==1
print("Yes" if f is True else "No")
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = set(a)
    ans = 0
    for x in s:
        y = a.count(x)
        if x == y:
            continue
        if x > y:
            ans += y
        else:
            ans += y - x

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from collections import Counter
    n = int(input())
    a = list(map(int, input().split()))
    b = Counter(a)
    ans = 0
    for k, v in b.items():
        if k == v:
            continue
        if k > v:
            ans += v
        else:
            ans += v - k

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in l:
  t=0
  while(i%2=0):
    i=i//2
    t+=1
  ans=min(ans,t)
print(ans)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
ans=1000
for i in l:
  t=0
  while(i%2==0):
    i=i//2
    t+=1
  ans=min(ans,t)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k, *a = map(int, open(0).read().split())
    s = set(a)
    v = len(s) - k
    l = sorted([a.count(i) for i in s])
    ans = sum(l[:v])
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from collections import Counter

    n, k, *a = map(int, open(0).read().split())
    c = Counter(a)
    v = len(c)
    l = list(c.values())
    l.sort()
    ans = sum(l[:v - k])
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
x=int(input())
print("Yes" if x%sum(list(str(x)))==0 else "No")

Fixed submission:
x=int(input())
print("Yes" if x%sum(map(int,str(x)))==0 else "No")
Buggy python submission (verdict: Runtime Error):
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10 ** 5 + 2)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m = sorted(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * 2 * (10 ** 5 + 1)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == 2 * s:
            table[t_ + 1] += 1
        else:
            table[2 * s - 1] += 1

        table[2 * t + 1] -= 1
        t_ = 2 * t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10 ** 5 + 1)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * 2 * (10 ** 5 + 1)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == 2 * s:
            table[t_ + 1] += 1
        else:
            table[2 * s - 1] += 1

        table[2 * t + 1] -= 1
        t_ = 2 * t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    s = str(input())
    t = 'AKIHABARA'
    i = 0

    for u in t:
        if s[i] == u:
            i += 1
        if i == len(t):
            print('YES')
            break
    else:
        print('NO')


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import re

    f = re.match('A?KIHA?BA?RA?$',input())
    print('YES'if f else 'NO')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
i=1
while(True):
  if (i+1)**2<=n:
    i+=1
print(i**2)

Fixed submission:
n=int(input())
i=1
while(True):
  if (i+1)**2<=n:
    i+=1
  else:
    break
print(i**2)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from bisect import bisect_left
    n, *abc = map(int, open(0).read().split())
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    a, b, c = sorted(a), sorted(b), sorted(c)
    ans = 0
    for i in c:
        j = bisect_left(b, i)
        for k in b[:j]:
            l = bisect_left(a, k)
            ans += l

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from bisect import bisect_left, bisect_right
    n, *abc = map(int, open(0).read().split())
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    a, b, c = sorted(a), sorted(b), sorted(c)
    ans = 0
    for i in b:
        j = bisect_left(a, i)
        k = n - bisect_right(c, i)
        ans += j * k

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
x,y=sum(x%2==0 for x in l),n-x
print(3**n-2**x)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
e=sum(x%2==0 for x in a)
print(3**n-2**e)
Buggy python submission (verdict: Runtime Error):
import collections
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
dd,tt=collections.Counter(d),collections.Counter(t)
for k,v in tt.items():
  h=dd.get(k)>=v
  if h==False or h==None:
    print("NO")
    exit()
print("YES")

Fixed submission:
import collections
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
dd,tt=collections.Counter(d),collections.Counter(t)
for k,v in tt.items():
  if dd.get(k)==None:
    print("NO")
    exit()
  elif dd.get(k)<v:
    print("NO")
    exit()
print("YES")

Buggy python submission (verdict: Runtime Error):
import collections
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
dd,tt=collections.Counter(d),collections.Counter(t)
for k,v in tt.items():
  h=dd.get(k)>=v
  if h==False:
    print("NO")
    exit()
print("YES")

Fixed submission:
import collections
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
dd,tt=collections.Counter(d),collections.Counter(t)
for k,v in tt.items():
  if dd.get(k)==None:
    print("NO")
    exit()
  elif dd.get(k)<v:
    print("NO")
    exit()
print("YES")
Buggy python submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
if n%k==0 or m%k==0:
  print("Yes")
  exit()
for i in range(n):
  for j in range(m):
    s=(n*i+m*j-i*j)-i*j
    if s==k:
      print("Yes")
      exit()
print("No")

Fixed submission:
n,m,k=map(int,input().split())
for i in range(n+1):
  for j in range(m+1):
    s=m*i+n*j-2*i*j
    if s==k:
      print("Yes")
      exit()
print("No")
Buggy python submission (verdict: Runtime Error):
def main():
    from itertools import product
    a, b, c, d, e, f = map(int, input().split())
    a, b = max(a, b), min(17 19 22 26 55 2802a, b)
    c, d = max(c, d), min(c, d)
    aa, bb, cc, dd = f // (100 * a), f // (100 * b), f // c, f // d
    aaa, bbb, ccc, ddd = range(aa + 1), range(bb + 1), range(cc, -1, -1), range(dd, -1, -1)
    n = 0
    ans = (0, 0)
    for (k, l, j, i) in product(ddd, ccc, bbb, aaa):
        w = 100 * (a * i + b * j)
        s = c * k + d * l

        if w == 0:
            continue

        m = 100 * s / w

        ok = (s + w <= f) and (100 * s <= e * w)
        if ok:
            n = m
            ans = (s + w, s)
            break

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from itertools import combinations
    a, b, c, d, e, f = map(int, input().split())
    a *= 100
    b *= 100

    water = [a * i + b * j for i in range(f // a + 1) for j in range(f // b + 1)]
    sugar = [c * i + d * j for i in range(f // c + 1) for j in range(f // d + 1)]
    water.sort()
    sugar.sort(reverse=True)

    tmp = 0
    x, y = 0, 0
    for w in water:
        if w == 0:
            continue
        for s in sugar:
            if s + w > f:
                continue
            if s * 100 <= e * w and tmp <= s / (s + w):
                tmp = s / (s + w)
                x = s + w
                y = s
    print(x,y)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    m = [list(map(int, input().split())) for _ in range(n)]

    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            d = m[i][j]
            t = min(m[i][k] + m[k][j] if k != i and k != j else d + 1 for k in range(n))
            if t < d:
                print(-1)
                exit()
            if d < t:
                ans += d

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    m = [list(map(int, input().split())) for _ in range(n)]

    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            d = m[i][j]
            for k in range(n):
                if k in (i, j):
                    continue
                t = m[i][k] + m[k][j]
                if t < d:
                    print(-1)
                    exit()
                if t == d:
                    break
            else:
                ans += d
    else:
        print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
c = 0 
for _ in range(n):
  n,m = map(int,input().split())
  c += m-n+1
print(count)

Fixed submission:
n = int(input())
c = 0 
for _ in range(n):
  n,m = map(int,input().split())
  c += m-n+1
print(c)

Buggy python submission (verdict: Runtime Error):
n = int(input())
c = 0 
for _ in range(n):
  n,m = map(int,input().split())
  count += m-n+1
print(count)

Fixed submission:
n = int(input())
c = 0 
for _ in range(n):
  n,m = map(int,input().split())
  c += m-n+1
print(c)

Buggy python submission (verdict: Runtime Error):
n = input()
c = 0 
for _ in range(n):
  n,m = map(int,input().split())
  count += m-n+1
print(count)

Fixed submission:
n = int(input())
c = 0 
for _ in range(n):
  n,m = map(int,input().split())
  c += m-n+1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, *a = map(int, open(0).read().split())
    b = set(a)
    c = list(b)
    ans = 0
    for i in c:
        ans += a.count(i) % 2 == 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    b = Counter(a)
    ans = sum(v%2==1 for v in b.values())
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    b = Counter(a)
    c = [[k, v] for k, v in b.items()]
    c.sort(key=lambda x: x[1], reverse=True)
    x = c[0][0]
    al, ar = c[0][1], c[0][1]
    if b.get(x - 1) is not None:
        al += b.get(xl - 1)
    if b.get(x - 2) is not None:
        al += b.get(xl - 2)
    if b.get(x + 1) is not None:
        al += b.get(x + 1)
    if b.get(x + 2) is not None:
        al += b.get(x + 2)

    print(max(al, ar))


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    b = Counter(a)
    c = [(k, v) for k, v in b.items()]
    c.sort(key=lambda x: x[0])
    ans = 0
    c = [c[0]] + c + [c[-1]]
    for x, y, z in zip(c, c[1:], c[2:]):
        v = y[0]
        tmp = y[1]
        if v - x[0] == 1:
            tmp += x[1]
        if v - z[0] == -1:
            tmp += z[1]
        ans = max(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    from math import gcd
    from functools import reduce
    from operator import mul
    n, *t = map(int, open(0).read().split())
    g = reduce(gcd, t)
    ans = reduce(mul, t) // g
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from fractions import gcd
    from functools import reduce

    def cal(a, b):
        t = a * b // gcd(a, b)
        return t

    n, *t = map(int, open(0).read().split())
    ans = reduce(cal, t)
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n, *a = map(int, open(0).read().split())

    o = sum([i % 2 == 1 for i in a])
    p = sum([i % 4 == 0 for i in a])
    q = sum([i % q == 0 for i in a]) - p
    
    if p + 1 >= o and not q:
        print("Yes")
    elif p >= 0 and q:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, *a = map(int, open(0).read().split())

    o = sum([i % 2 == 1 for i in a])
    p = sum([i % 4 == 0 for i in a])
    q = sum([i % 2 == 0 for i in a]) - p

    if p + 1 >= o and not q:
        print("Yes")
    elif p >= o and q:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
b,i,c=10**9,1,True
while(i<n and c):
  p=sum(l[:i])
  q=sum(l[i:])
  if min(b,abs(p-q))!=abs(p-q):
    break
  else:
    b=min(b,abs(p-q))
    i+=1
print(b)

Fixed submission:
a,b=map(int,input().split())
f=a%3==0 or b%3==0 or (a+b)%3==0
print("Possible" if f==True else "Impossible")

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
b,i,c=10**9,1,True
while(i<n and c):
  p=sum(l[:i])
  q=sum(l[i:])
  c=min(b,abs(p-q))==abs(p-q)
  b=min(b,abs(p-q))
  i+=1
print(b)

Fixed submission:
a,b=map(int,input().split())
f=a%3==0 or b%3==0 or (a+b)%3==0
print("Possible" if f==True else "Impossible")
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
b,i=l10**9,1
while(i<n):
  p=sum(l[:i])
  q=sum(l[i:])
  b=min(b,abs(p-q))
  i+=1
print(b)

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
a,b=x[0],sum(x)-x[0]
c=abs(a-b)
for i in range(1,n-1):
  a+=x[i]
  b-=x[i]
  c=min(c,abs(a-b))
print(c)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
print(*A[::-2],*A[N%2::2])

Fixed submission:
n,p=int(input()),list(map(int,input().split()))
k= n//2 if n%2==0 else n//2+1
a,b=list(range(0,k)),list(range(k-1,n))[::-1]
c=[]
for x,y in zip(a,b):
  c.append(x)
  c.append(y)
c= c if n%2==0 else c[:-1]
c=c[::-1]
l=list([])
for x,y in zip(c,list(range(n))):
  l.append([x,y])
l=sorted(l)
for i in range(n):
  print(p[l[i][1]],end=" ")
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    s = input()
    t = s.split(')(')
    if len(t) == 1:
        u = t[0].split('()')
        print(u)
        v = max(len(u[0]), len(u[1])) + 1
        ans = v * '(' + v * ')'
        print(ans)
        exit()

    ans = ''
    for x in t:
        l = len(x) + 1
        ans += l * '(' + l * ')'

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    s = input()

    l, r = 0, 0

    for i in s:
        if i == ")":
            if l:
                l -= 1
            else:
                r += 1
        else:
            l += 1

    print(r * "(" + s + ")" * l)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
x = a%b
print("Yes" if c%x==0 else "No")

Fixed submission:
a,b,c=map(int,input().split())
x = any((a*i)%b==c for i in range(1,b+1))
print("YES" if x else "NO")
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a>b:
  print("GREATER")
elif a<b:
  print("LESS")
else:
  print("EQUAL")

Fixed submission:
a,b=int(input()),int(input())
if a>b:
  print("GREATER")
elif a<b:
  print("LESS")
else:
  print("EQUAL")
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
c,f=0,l[0]/abs(l[0])
s=l[0]
for i in range(1,n):
  t=s+l[i]
  if s*t>=0:
    s=-1*f
    c+=abs(t)+1
  else:
    f=-1*f
    s=s+l[i]
print(int(c))

Fixed submission:
n=input()
a=[int(i) for i in input().split()]
def chk(a,t):
    ans=0
    x=0
    for i in a:
        x+=i
        if t==True and x<1:
            ans+=1-x
            x=1
        elif t==False and x>-1:
            ans+=x+1
            x=-1
        t=not t
    return ans
print(min(chk(a,True),chk(a,False)))

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
c,f=0,l[0]/abs(l[0])
s=l[0]
for i in range(1,n,1):
  t=s+l[i]
  if s*t>0:
    s=-1*f
    c+=abs(t-s+1)
  else:
    f=-1*f
    s=s+l[i]
print(int(c))

Fixed submission:
n=input()
a=[int(i) for i in input().split()]
def chk(a,t):
    ans=0
    x=0
    for i in a:
        x+=i
        if t==True and x<1:
            ans+=1-x
            x=1
        elif t==False and x>-1:
            ans+=x+1
            x=-1
        t=not t
    return ans
print(min(chk(a,True),chk(a,False)))
Buggy python submission (verdict: Runtime Error):
def main():
    from itertools import accumulate
    x = int(input())
    l = list(range(0, x + 1))
    r = accumulate(l)

    for i, p in enumerate(r):
        if p == x:
            print(i)
            break
        if p + (i + 2) == x:
            print(i + 2)
            break


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    x = int(input())
    k = int(x ** .5)

    i = 0
    while True:
        p = i * (i + 1) // 2
        if p >= x:
            print(i)
            break
        i += 1


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    x = int(input())

    i = 1
    p = 0
    while True:
        if i == (x - p):
            print(i)
            break
        if i + 1 == (x - p):
            print(i + 1)
            break
        else:
            p += i
            i += 1


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    x = int(input())
    k = int(x ** .5)

    i = 0
    while True:
        p = i * (i + 1) // 2
        if p >= x:
            print(i)
            break
        i += 1


if __name__ == '__main__':
    main()