qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
import sys

n,a,b = map(int, input().split())

if n == 1:
	if a == b:
		print(1)
	else:
		print(0)
		sys.exit()
if a > b:
	print(0)
	sys.exit()

maximum = (a+b) + b*(n-2)
minimum = (a+b) + a*(n-2)

print(maximum-minimum+1)

# Fixed code:
import sys

n,a,b = map(int, input().split())

if n == 0:
	print(0)
	sys.exit()
if n == 1:
	if a == b:
		print(1)
		sys.exit()
	else:
		print(0)
		sys.exit()
if a > b:
	print(0)
	sys.exit()

maximum = (a+b) + b*(n-2)
minimum = (a+b) + a*(n-2)

print(maximum-minimum+1)
# Buggy code:
n,a,b = [int(i) for i in input().split()]
if n == 1:
    print(0)
elif a > b:
    print(0)
else:    
    ans = b*(n-2)-a*(n-2)+1
    print(ans)

# Fixed code:
n, a, b = [int(i) for i in input().split()]
if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
elif a > b:
    print(0)
else:
    top = a + b + (n-2)*b
    bottom = a + b + (n-2)*a
    print(top-bottom+1)
# Buggy code:
N, A, B = list(map(int,input().split()))
if A > B:
  print(0)
elif A == B:
  print(1)
else:
  print((B * (N-1) + A) - (B + (N-1) * A))

# Fixed code:
N, A, B = list(map(int, input().split()))

if A > B:
    print(0)

elif N == 1 and A!= B:
    print(0)
    
else:
    print(B*(N-1) + A - A*(N-1) - B + 1)
# Buggy code:
n, a, b = [ int(v) for v in input().split() ]
if n == 1:
    if a != b:
        ans = 1
    else:
        ans = 0
else:
    if a <= b:
        maxsum = a + b*(n+1)
        minsum = a*(n+1) + b
        ans = maxsum - minsum + 1

    else:
        ans = 0
print(ans)


# Fixed code:
n, a, b = [ int(v) for v in input().split() ]
if n == 1:
    if a != b:
        ans = 0
    else:
        ans = 1
else:
    if a <= b:
        maxsum = a + b*(n-1)
        minsum = a*(n-1) + b
        ans = maxsum - minsum + 1

    else:
        ans = 0
print(ans)
# Buggy code:
n, a, b = (int(x) for x in input().split())
if n == 1 or a > b: print(0)
else: print((a + b * (n - 1) - (a * (n - 1) + b) + 1))

# Fixed code:
n, a, b = (int(x) for x in input().split())
if n == 1:
    if a == b: print(1)
    else: print(0)
elif a > b: print(0)
else: print((a + b * (n - 1) - (a * (n - 1) + b) + 1))
# Buggy code:
n, a, b = map(int, input().split())
tmp = abs(b-a)+1
if b < a or (n == 1 and b-a > 1):
    print(0)
else:
    if n == 1:
        print(1)
    else:
        print(tmp**(n-2) - tmp**2)

# Fixed code:
n, a, b = map(int, input().split())
if a>b or (n==1 and a<b):
    print(0)
else:
    print((n-2)*b-(n-2)*a+1)
# Buggy code:
s = input().split(" ");
n = s[0];
a = s[1];
b = s[2];
if a > b :
  print(0);
else
  if n = 1 or n = 2:
    print(1);
  else
    ans = (b - a)*(n - 2)+1;
    print(ans);

# Fixed code:
s = input().split(" ");
n = int(s[0]);
a = int(s[1]);
b = int(s[2]);
if a > b :
  print(0);
else :
  if n == 1 :
    if a==b :
      print(1);
    else :
      print(0);
  else :
    ans = (b - a)*(n - 2)+1;
    print(ans);
# Buggy code:
N,A,B=map(int,input().split())
if A>B:
  print(0)
if B-A>=1 and N==1:
  print(0)
else:
  print((B-A)**N+1)

# Fixed code:
N, A, B = map(int, input().split())
if A > B or (N == 1 and A != B):
    print(0)
else:
    print((B*(N-1)+A)-(A*(N-1)+B)+1)
# Buggy code:
N, K = [int(x) for x in input().split(" ")]
 
placed = 0
elm = []
for i in range(N):
  a, b = input().split(" ")
  elm.append({
    "order": i + 1,
    "element": int(a),
    "count": int(b)
  })

elm.sort(key=lambda e: (e["element"], e["order"]))
for i in range(len(elm)):
  placed = e["count"]
  if placed >= K:
    print(e["element"])
    break


# Fixed code:
N, K = [int(x) for x in input().split(" ")]
 
placed = 0
elm = []
for i in range(N):
  a, b = input().split(" ")
  elm.append({
    "order": i + 1,
    "element": int(a),
    "count": int(b)
  })

elm.sort(key=lambda e: (e["element"], e["order"]))
for i in range(len(elm)):
  e = elm[i]
  placed += e["count"]
  if placed >= K:
    print(e["element"])
    break
# Buggy code:
n  k = map(int, input().split())
ab = [[map(int, input().split())] for _ in range(n)]

count = 0
for x in ab:
    count += x[1]
    if k <= count:
        print(x[0])
        break


# Fixed code:
n, k = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)])

count = 0
for x in ab:
    count += x[1]
    if k <= count:
        print(x[0])
        break
# Buggy code:
N, K = map(int,input().split())
AB = sorted([[list(map(int,input().split())) for _ in range(N)]])
cnt = 0
for a, b in AB:
  if(cnt < K - b)
    cnt += b
  else:
    print(a)
    break


# Fixed code:
N, K = map(int,input().split())
AB = sorted([list(map(int,input().split())) for _ in range(N)])
cnt = 0
for a, b in AB:
  if(cnt < K - b):
    cnt += b
  else:
    print(a)
    break
# Buggy code:
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    ab = sorted([ist(map(int, input().rstrip('\n').split())) for _ in range(n)])
    t = 0
    for a, b in ab:
        t += b
        if t >= k:
            print(a)
            exit()


if __name__ == '__main__':
    slove()


# Fixed code:
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    ab = sorted([list(map(int, input().rstrip('\n').split())) for _ in range(n)])
    t = 0
    for a, b in ab:
        t += b
        if t >= k:
            print(a)
            exit()


if __name__ == '__main__':
    slove()
# Buggy code:
	n, k = map(int, input().split())
a = [0] * n
b = [0] * n
sum = 0
arr = []
for i in range(n):
    a[i], b[i] = map(int, input().split())
arr_list = list(zip(a, b))
arr_list = sorted(arr_list)
# print(arr_list)
for i in range(n):
    sum += arr_list[i][1]
    # print(sum, arr_list[i])
    if sum >= k:
        answer = arr_list[i]
        break

print(answer)


# Fixed code:
n, k = map(int, input().split())
a = [0] * n
b = [0] * n
sum = 0
arr = []
for i in range(n):
    a[i], b[i] = map(int, input().split())
arr_list = list(zip(a, b))
arr_list = sorted(arr_list)
# print(arr_list)
for i in range(n):
    sum += arr_list[i][1]
    # print(sum, arr_list[i])
    if sum >= k:
        answer = arr_list[i][0]
        break

print(answer)
# Buggy code:
from collections import defaultdict
n, k = map(int, input().split())
dic = defaultdict(int)
for _ in range(n):
  a, b = map(int, input().split())
  dic[a] += b
dic = sorted(dic, key = lambda x: x[0])
cnt = 0
for key in dic:
  if cnt + dic[key] < k:
    cnt += dic[key]
  else:
    print(key)
    break
    

# Fixed code:
from collections import defaultdict
n, k = map(int, input().split())
dic = defaultdict(int)
for _ in range(n):
  a, b = map(int, input().split())
  dic[a] += b
cnt = 0
for key in sorted(dic):
  if cnt + dic[key] < k:
    cnt += dic[key]
  else:
    print(key)
    break
# Buggy code:

n,k=map(int,input().split())
ab=[[int(i) for i in input().split()]for j in range(n)]
dic={}
for a,b in ab:
    if a in dic:
        dic[a]+=j
    else:
        dic[a]=j
dic=sorted(dic.items() , key=lambda x:x[0])
check=0
for i,j in dic:
    check+=j
    if check>=k
    print(i)
    break

# Fixed code:
n,k=map(int,input().split())
ab=[[int(i) for i in input().split()]for j in range(n)]
dic={}
for a,b in ab:
    if a in dic:
        dic[a]+=b
    else:
        dic[a]=b
dic=sorted(dic.items() , key=lambda x:x[0])
check=0
for i,j in dic:
    check+=j
    if check>=k:
        print(i)
        break
# Buggy code:
n, k = map(int, input().split(" "))
a = [list(map(int, input().split(" "))) for i in range(n)]
count = 0
for x, y in a:
  count += y
  if k >= y:
    print(x)
    break
else:
  print("None")

# Fixed code:
n, k = map(int, input().split(" "))
a = sorted([list(map(int, input().split(" "))) for i in range(n)])
count = 0
for x, y in a:
  count += y
  if k <= count:
    print(x)
    break
else:
  print("None")
# Buggy code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

N,K = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()

cnt = 0
for a,b in A:
    cnt += b
    if cnt >= K:
        print(a)

# Fixed code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

N,K = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()

cnt = 0
for a,b in A:
    cnt += b
    if cnt >= K:
        print(a)
        break
# Buggy code:
N,K=map(int,input().split())
A_B=[list(map(int,input().split())) for _ in range(N)]
ans=0
for i in range(N):
    ans+=A_B[0][1]
    if ans>=K:
        print(A_B[0][0])
print(ans)



# Fixed code:
N,K=map(int,input().split())
A_B=[list(map(int,input().split())) for _ in range(N)]
ans=0
A_B.sort()
for i in range(N):
    ans+=A_B[i][1]
    if ans>=K:
        print(A_B[i][0])
        break
# Buggy code:
from sys import stdin, stdout
from collections import defaultdict
def readLine_int_list():return list(map(int, stdin.readline().split()))
def main():
	n,k = readLine_int_list()
	_k = 0
	l = defaultdict(lambda: 0)
	for i in range(n):
	    a,b =readLine_int_list()
	    l[a] += b
	
	cnt = 0
	for key in sorted(l.keys()):
	    val = l[key]
	    cnt += val
	    if cnt >= k:
	        print(key)


if __name__ == "__main__":
    main()


# Fixed code:
from sys import stdin, stdout
from collections import defaultdict
def readLine_int_list():return list(map(int, stdin.readline().split()))
def main():
    n,k = readLine_int_list()
    
    l = defaultdict(lambda: 0)
    for i in range(n):
        a,b =readLine_int_list()
        l[a] += b
    
    cnt = 0
    for key in sorted(l.keys()):
        val = l[key]
        cnt += val
        if cnt >= k:
            print(key)
            break


if __name__ == "__main__":
    main()
# Buggy code:
n, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
print(ab)
total = 0
for i in range(n):
    total += ab[i][1]
    if total >= k:
        print(ab[i][0])
        exit()


# Fixed code:
n, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
total = 0
for i in range(n):
    total += ab[i][1]
    if total >= k:
        print(ab[i][0])
        exit()
# Buggy code:
n,k=map(int,input().split())
num=[list(map(int,input().split()))for _ in range(n)]
p=0
num.sort()
for i in range(n):
    p+=num[i][1]
    if k<=p:
        ans=num[i][0]
        exit()
print(ans)


# Fixed code:
n,k=map(int,input().split())
num=[list(map(int,input().split()))for _ in range(n)]
p=0
num.sort()
for i in range(n):
    p+=num[i][1]
    if k<=p:
        ans=num[i][0]
        break
print(ans)
# Buggy code:
n,k=map(int,input().split())
lists=[0]*n
for i in range(n):
    lists[i]=tuple(map(int,input().split()))
lists=sorted(lists,key=lambda x: x[0])
print(lists)
count=0
num=0
for j in range(n):
    if count<k:
        count+=lists[j][1]*lists[j][0]
    else:
        num+=lists[j][0]
        break
print(num)

# Fixed code:
n,k=map(int,input().split())
lists=[0]*n
for i in range(n):
    lists[i]=tuple(map(int,input().split()))
lists=sorted(lists,key=lambda x: x[0])

count=0
num=0
for j in range(n):
    if count<k:
        count=count+lists[j][1]
        num=lists[j][0]

    else:
        break
print(num)
# Buggy code:
import sys
from collections import deque

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, K = MAP()
A = [MAP() for _ in range(N)]

tmp = []
cur = 0
for a in A:
	tmp.append(a)
	cur += a[1]
	if cur >= K-1:
		tmp.sort()
		print(tmp[-1][0])
		break

# Fixed code:
import sys
from collections import deque

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, K = MAP()
A = [MAP() for _ in range(N)]

A.sort()
cur = 0
for a in A:
	cur += a[1]
	if cur >= K:
		print(a[0])
		break
# Buggy code:
n,k=map(int,input().split())

l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
    
l.sort()

i=n-1
ans=0
while k>0:
    k=k-l[i][1]
    ans=l[i][0]
    i=i-1
print(ans)

# Fixed code:
n,k=map(int,input().split())

l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
    
l.sort()

i=0
ans=0
while k>0:
    k=k-l[i][1]
    ans=l[i][0]
    i=i+1
print(ans)
# Buggy code:
f = lambda: list(map(int,input().split()))
f_ = lambda: [int(x)-1 for x in input().split()]

n,k = f()
d = []
for _ in range(n):
    a,b = f()
    d.append((a,b))
d.sort(key=lambda x: x[0])
count = 0
for x,y in d:
    count += x
    if count >= k:
        break
print(y)

# Fixed code:
f = lambda: list(map(int,input().split()))
f_ = lambda: [int(x)-1 for x in input().split()]

n,k = f()
d = []
for _ in range(n):
    a,b = f()
    d.append((a,b))
d.sort(key=lambda x: x[0])
count = 0
for x,y in d:
    count += y
    if count >= k:
        break
print(x)
# Buggy code:
N,K =  list(map(int,input().split()))
listA = []
for i in range(N):
    listA.append(list(map(int,input().split())))
now = 0
listA.sort()
print(listA)
for i in range(N):
    if now <= K <= now+listA[i][1]:
        print(listA[i][0])
        exit()
    else:
        now += listA[i][1]

# Fixed code:
N,K =  list(map(int,input().split()))
listA = []
for i in range(N):
    listA.append(list(map(int,input().split())))
now = 0
listA.sort()
for i in range(N):
    if now <= K <= now+listA[i][1]:
        print(listA[i][0])
        exit()
    else:
        now += listA[i][1]
# Buggy code:
from operator import itemgetter

N, K = [int(x) for x in input().split()]
Array = list()
A = list()
count = 0
ans = 0
for i in range(N):
	A.append([int(x) for x in input().split()])
print(A)

A.sort(key=itemgetter(0))
for i in range(N):
	count += A[i][1]
	if count >= K:
		ans = A[i][0]
		break
		
print(ans)

# Fixed code:
from operator import itemgetter

N, K = [int(x) for x in input().split()]
Array = list()
A = list()
count = 0
ans = 0
for i in range(N):
	A.append([int(x) for x in input().split()])

A.sort(key=itemgetter(0))
for i in range(N):
	count += A[i][1]
	if count >= K:
		ans = A[i][0]
		break
		
print(ans)
# Buggy code:
n,k=map(int,input().split())
L=[]
for i in range(n):
      a,b=map(int,input().split())
      L+=[[a,b]]
L.sort(key=lambda x:x[0])
print(L)


sm=0
for i in range(n):
      sm+=L[i][1]
      if sm>=k:
            print(L[i][0])
            exit()


# Fixed code:
n,k=map(int,input().split())
L=[]
for i in range(n):
      a,b=map(int,input().split())
      L+=[[a,b]]
L.sort(key=lambda x:x[0])

sm=0
for i in range(n):
      sm+=L[i][1]
      if sm>=k:
            print(L[i][0])
            exit()
# Buggy code:
n, k = map(int, input().split())
a_list = []
for i in range(n):
	a, b = map(int, input().split())
	a_list.append([a, b])
a_list.sort(key=lambda x: x[0])
for i in range(n):
	k -= a_list[i][1]
	if k <= 0:
		print(a_list[i][0])

# Fixed code:
n, k = map(int, input().split())
a_list = []
for i in range(n):
	a, b = map(int, input().split())
	a_list.append([a, b])
a_list.sort(key=lambda x: x[0])
for i in range(n):
	k -= a_list[i][1]
	if k <= 0:
		print(a_list[i][0])
		break
# Buggy code:
N,K = map(int,input().split())
C = {}
A = []
for _ in range(N):
    a,b = map(int,input().split())
    if a not in C:
        C[a] = 0
    C[a] += b
    A.append(a)
A = sorted(list(set(A)))
cnt = 0
for i in range(len(A)):
    cnt += C[i]
    if cnt>=K:
        print(i)
        break


# Fixed code:
N,K = map(int,input().split())
C = {}
A = []
for _ in range(N):
    a,b = map(int,input().split())
    if a not in C:
        C[a] = 0
    C[a] += b
    A.append(a)
A = sorted(list(set(A)))
cnt = 0
for i in range(len(A)):
    cnt += C[A[i]]
    if cnt>=K:
        print(A[i])
        break
# Buggy code:
# input
N, K = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(M)]

count = 0

for i in range(N):
    count += A[i][1]
    if count >= K:
        print(A[i][0])
        break

# Fixed code:
# input
N, K = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]

A = sorted(A)

count = 0

for i in range(N):
    count += A[i][1]
    if count >= K:
        print(A[i][0])
        break
# Buggy code:
N, K = map(int, input().strip().split())
ab = []
for _ in range(N):
  ab.append(tuple(map(int, input().strip())))

kc = 0
for a, b in sorted(ab, key=lambda x: x[0]):
  if kc + b >= K:
    break
  kc += b

print(a)


# Fixed code:
N, K = map(int, input().strip().split())
ab = []
for _ in range(N):
  ab.append(tuple(map(int, input().strip().split())))

kc = 0
for a, b in sorted(ab, key=lambda x: x[0]):
  if kc + b >= K:
    break
  kc += b

print(a)
# Buggy code:
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(N)]
P1 = P.sort()
a = 0
for i in range(N):
    if M < P[i][1]:
        break
    M = M-P[i][1]
    a += 1

print(P[a][0])

# Fixed code:
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(N)]
P.sort()
a = 0
for i in range(N):
    if M <= P[i][1]:
        break
    M = M-P[i][1]
    a += 1


print(P[a][0])
# Buggy code:
n,k = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l.sort()
count = 0
for i,j in l:
  if j < count:
    count += j
  else:
    print(i)
    exit()

# Fixed code:
n,k = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l.sort()
count = 0
for i,j in l:
  if j < k:
    k -= j
  else:
    print(i)
    exit()
# Buggy code:
n,k=map(int,input().split())
li = [list(map(int, input().split())) for i in range(n)]
li.sort()
c=0
for i in range(n):
  c+=li[i][0]*li[i][1]
  if c>=k:
    print(li[i][0])
    
    break
    

# Fixed code:
n,k=map(int,input().split())
li = [list(map(int, input().split())) for i in range(n)]
li.sort()
c=0
for i in range(n):
  c+=li[i][1]
  if c>=k:
    print(li[i][0])
    
    break
# Buggy code:
N, K = map(int, input().split())
a_b = [list(input().split()) for i in range(N)]
a_b.sort()
index = 0
print(a_b)
for i in range(N):
    index += int(a_b[i][1])
    if index >= K:
        print(a_b[i][0])
        break

# Fixed code:
N, K = map(int, input().split())
a_b = [list(map(int, input().split())) for i in range(N)]
a_b.sort()
index = 0

for i in range(N):
    index += a_b[i][1]
    if index >= K:
        print(a_b[i][0])
        exit()
# Buggy code:
ma = lambda:map(int,input().split())
n,k = ma()
ab = []
for i in range(n):
    ab.append((list(ma)))
ab.sort()
c  = 0
for a,b in ab:
    c+=b
    if c>=k:print(a) 


# Fixed code:
ma = lambda:map(int,input().split())
n,k = ma()
ab = []
for i in range(n):
    ab.append((list(ma())))
ab.sort()
c  = 0
for a,b in ab:
    c+=b
    if c>=k:
        print(a)
        break
# Buggy code:
N, K = map(int, input().split())
nums = []
for _ in range(N):
    nums.append(list(map(int, input().split())))
nums.sort()
print(nums)

sumb = 0
for n in nums:
    sumb += n[1]
    if sumb >= K:
        print(n[0])
        break

# Fixed code:
N, K = map(int, input().split())
nums = []
for _ in range(N):
    nums.append(list(map(int, input().split())))
nums.sort()

sumb = 0
for n in nums:
    sumb += n[1]
    if sumb >= K:
        print(n[0])
        break
# Buggy code:
n = int(input())
a = list(map(int, input().split()))

ans = 10**10

# 1 -1 1 -1...
cost1 = 0
s = 0
for i in range(n):
    t = 1 if i % 2 == 0 else -1
    c = 0
    if i % 2 == 0:
        if s + a[i] > 0:
            s += a[i]
        else:
            c = abs(s - t)
            s += c
            cost1 += abs(c - a[i])
    else:
        if s + a[i] < 0:
            s += a[i]
        else:
            c = abs(s - t)
            s -= c
            cost1 += abs(c - a[i])

cost2 = 0
s = 0
for i in range(n):
    t = -1 if i % 2 == 0 else 1
    c = 0
    if i % 2 == 1:
        if s + a[i] > 0:
            s += a[i]
        else:
            c = abs(s - t)
            s += c
            cost2 += abs(c - a[i])
    else:
        if s + a[i] < 0:
            s += a[i]
        else:
            c = abs(s - t)
            s -= c
            cost2 += abs(- c - a[i])

print(cost1, cost2)
print(min(cost1, cost2))
# -1 1 -1 1..


# Fixed code:
n = int(input())
a = list(map(int, input().split()))

ans = 10**10

# 1 -1 1 -1...
cost1 = 0
s = 0
for i in range(n):
    t = 1 if i % 2 == 0 else -1
    c = 0
    if i % 2 == 0:
        if s + a[i] > 0:
            s += a[i]
        else:
            c = abs(s - t)
            s += c
            cost1 += abs(c - a[i])
    else:
        if s + a[i] < 0:
            s += a[i]
        else:
            c = abs(s - t)
            s -= c
            cost1 += abs(- c - a[i])

cost2 = 0
s = 0
for i in range(n):
    t = -1 if i % 2 == 0 else 1
    c = 0
    if i % 2 == 1:
        if s + a[i] > 0:
            s += a[i]
        else:
            c = abs(s - t)
            s += c
            cost2 += abs(c - a[i])
    else:
        if s + a[i] < 0:
            s += a[i]
        else:
            c = abs(s - t)
            s -= c
            cost2 += abs(- c - a[i])

print(min(cost1, cost2))
# -1 1 -1 1..
# Buggy code:
n=int(input())

a=list(map(int,input().split()))

kp=0
asum=0
flag=-1
for i in range(n):
    asum=asum+a[i]
    if flag==-1:
        if asum>=0:
            kp=kp+asum+1
            asum=-1
    else:
        if asum<=0:
            kp=kp+1-asum
            asum=1
    flag=-flag
    print(asum)
print("-----",kp)            
km=0
asum=0
flag=1
for i in range(n):
    asum=asum+a[i]
    if flag==-1:
        if asum>=0:
            km=km+asum+1
            asum=-1
    else:
        if asum<=0:
            km=km+1-asum
            asum=1
    flag=-flag
    print(asum)
print("-----",km)            

print(min(kp,km))
        

# Fixed code:
n=int(input())

a=list(map(int,input().split()))

kp=0
asum=0
flag=-1
for i in range(n):
    asum=asum+a[i]
    if flag==-1:
        if asum>=0:
            kp=kp+asum+1
            asum=-1
    else:
        if asum<=0:
            kp=kp+1-asum
            asum=1
    flag=-flag
#    print(asum)
#print("-----",kp)            
km=0
asum=0
flag=1
for i in range(n):
    asum=asum+a[i]
    if flag==-1:
        if asum>=0:
            km=km+asum+1
            asum=-1
    else:
        if asum<=0:
            km=km+1-asum
            asum=1
    flag=-flag
#    print(asum)
#print("-----",km)            

print(min(kp,km))
# Buggy code:
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 code:
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 code:
n=int(input())
a=list(map(int,input().split()))
b=a[:]

x=0#pmpm
y=0
sum1=0
sum2=0

for i in range(n):
  sum1+=a[i]
  sum2+=b[i]
  if(i%2==0):
    if(sum1<=0):
      x+=1-sum1
      a[i]+=1-sum1
    if(sum2>=0):
      y+=sum2+1
      b[i]-=sum2+1
  else:
    if(sum1>=0):
      x+=sum1+1
      a[i]-=1+sum1
    if(sum2<=0):
      y+=1-sum2
      b[i]+=1-sum2
print(min(x,y))

# Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=a[:]

x=0#pmpm
y=0
sum1=0
sum2=0

for i in range(n):
  sum1+=a[i]
  sum2+=b[i]
  if(i%2==0):
    if(sum1<=0):
      x+=1-sum1
      a[i]+=1-sum1
      sum1+=1-sum1
    if(sum2>=0):
      y+=sum2+1
      b[i]-=sum2+1
      sum2-=sum2+1
  else:
    if(sum1>=0):
      x+=sum1+1
      a[i]-=1+sum1
      sum1-=1+sum1
    if(sum2<=0):
      y+=1-sum2
      b[i]+=1-sum2
      sum2+=1-sum2
print(min(x,y))