qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
fact_l=[1]*(N+10)
mod = 10**9+7
for i in range(2,N+1):
  fact_l[i]=(fact_l[i-1]*i)%mod
  
fact_inv_l = [1]*(N+10)
for i in range(2,N+1):
  fact_inv_l[i]=pow(fact_l[i],mod-2,mod)
ans = 0
for i in range(N-K+1):
  for j in range(1,N-K+2):
    b = N-j-i-1
    c = K-2
    a = A[-j]-A[i]
    ans += a*fact_l[b]%mod*fact_inv_l[b-c]%mod*fact_inv_l[c]%mod
    
print(ans%mod)

Fixed code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
fact_l=[1]*(N+10)
mod = 10**9+7
for i in range(2,N+1):
  fact_l[i]=(fact_l[i-1]*i)%mod
  
fact_inv_l = [1]*(N+10)
for i in range(2,N+1):
  fact_inv_l[i]=pow(fact_l[i],mod-2,mod)
ans = 0
for i in range(1,N-K+2):
  b = N-i
  c = K-1
  ans -= A[i-1]*fact_l[b]%mod*fact_inv_l[b-c]%mod*fact_inv_l[c]%mod
  ans += A[-i]*fact_l[b]%mod*fact_inv_l[b-c]%mod*fact_inv_l[c]%mod
    
print(ans%mod)
Buggy code:
import math
denom = int(1e9+7)

def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


def combi2(n,k,p,f):
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=fact_mod[n]
  b=fact_mod[k]
  c=fact_mod[n-k]
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p


N, K = map(int, input().split())
A = [int(i)%denom for i in input().split()]
A.sort(reverse = True)

fact_mod = [1]
current = 1
for i in range(1,N+1):
    current = (current * i) % denom
    fact_mod.append(current)

max_tot = 0
min_tot = 0
for i in range(N-K+1):
    max_tot += (A[i] * combi2(N-i-1, K-1, denom, fact_mod)) % denom
    min_tot += (A[N-i-1] * combi2(N-i-1, K-1, denom, fact_mod)) % denom
    
print((max_tot - min_tot)%denom)

Fixed code:
import math
denom = int(1e9+7)

def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


def combi2(n,k,p,f,pow_fun):
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=fact_mod[n]
  b=fact_mod[k]
  c=fact_mod[n-k]
  return (a*pow_fun[b]*pow_fun[c])%p


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

fact_mod = [1]
current = 1
for i in range(1,N+1):
    current = (current * i) % denom
    fact_mod.append(current)

pow_fun = {}
for i in fact_mod:
    pow_fun[i]=power_func(i,denom-2,denom)

max_tot = 0
min_tot = 0
for i in range(N-K+1):
    max_tot += (A[i] * combi2(N-i-1, K-1, denom, fact_mod,pow_fun)) % denom
    min_tot += (A[N-i-1] * combi2(N-i-1, K-1, denom, fact_mod,pow_fun)) % denom
    
print((max_tot - min_tot)%denom)
Buggy code:
n, k = map(int,input().split())
a = sorted(list(map(int,input().split())))
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
ans = 0
for i in range(N-K+1):
  ans += (a[n-1-i]-a[i])*cmb(n-1-i,k-1,mod)
  ans %=  mod
print(ans)

Fixed code:
n, k = map(int,input().split())
a = sorted(list(map(int,input().split())))
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
N = 10**5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
ans = 0
for i in range(n-k+1):
  ans += (a[n-1-i]-a[i])*cmb(n-1-i,k-1,mod)
  ans %=  mod
print(ans)
Buggy code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
mod=10**9+7
ans=0
fac=[1]
for i in range(n):
	p=fac[-1]*(i+1)%mod
	fac.append(p)
def comb(a,b):
	if a-b<0:
		return 0
	else:
		r=pow(fac[b]*fac[a-b]%mod,mod-2,mod)
		return r*fac[a]%mod
for i in range(n):
	ans-=comb(n-i-1,k-1)*a[i]
	ans+=comb(i,k-1)*a[i]
print(ans)

Fixed code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
mod=10**9+7
ans=0
fac=[1]
for i in range(n):
	p=fac[-1]*(i+1)%mod
	fac.append(p)
def comb(a,b):
	if a-b<0:
		return 0
	else:
		r=pow(fac[b]*fac[a-b]%mod,mod-2,mod)
		return r*fac[a]%mod
for i in range(n):
	ans-=comb(n-i-1,k-1)*a[i]
	ans+=comb(i,k-1)*a[i]
	ans%=mod
print(ans)
Buggy code:
n=int(input())
p=[input().split() for _ in range(n)]
x=input()
ans=0
flag=False
for i in p:
    if i[1]==x:
        flag=True
        continue
    if flag:
        ans+=int(i[0])
print(ans)

Fixed code:
n=int(input())
p=[input().split() for _ in range(n)]
x=input()
ans=0
flag=False
for i in p:
    if i[0]==x:
        flag=True
        continue
    if flag:
        ans+=int(i[1])
print(ans)
Buggy code:
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(str,input().split())))
x=input()
ans=0
f=0
for i in l:
    if f==1:
        ans+=int(l[1])
    if i[0]==x:
        f=1
print(ans)

Fixed code:
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(str,input().split())))
x=input()
ans=0
f=0
for i in l:
    if f==1:
        ans+=int(i[1])
    if i[0]==x:
        f=1
print(ans)
Buggy code:
n = int(input())

s = ['']*n
t = ['']*n
for i in range(n):
    s[i], t[i] = input().split()
    
    
x = input()

p = s.index(x)
total = 0
for i in range(p, n):
    total += int(t[i])
print(total)

Fixed code:
n = int(input())

s = ['']*n
t = ['']*n
for i in range(n):
    s[i], t[i] = input().split()
    
    
x = input()

p = s.index(x)
total = 0
for i in range(p+1, n):
    total += int(t[i])
print(total)
Buggy code:
import sys
#input = sys.stdin.buffer.readline
input = sys.stdin.buffer.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	n=int(input())
	s=[]
	t=[]
	for i in range(n):
		a,b=input().split()
		s.append(a)
		t.append(int(b))
	x=input()

	for i in range(n):
		if x==s[i]:
			print(sum(t[i+1:]))













if __name__ == "__main__":
	main()


Fixed code:
#import sys
#input = sys.stdin.buffer.readline
#input = sys.stdin.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	n=int(input())
	s=[]
	t=[]
	for i in range(n):
		a,b=input().split()
		s.append(a)
		t.append(int(b))
	x=input()
	for i in range(n):
		if x==s[i]:
			ans=sum(t[i+1:])
			print(ans)
			exit(0)


if __name__ == "__main__":
	main()
Buggy code:
N=int(input())
s=[]
t=[]
for i range(N):
    s_tmp,t_tmp=map(str,input().split())
    s.append(s_tmp)
    t.append(int(t_tmp))
X=input() 

# N=3
# s=["dwango","sixth","prelims"]
# t=[ 2, 5,25]
# X="prelims"

print(sum(t[s.index(X)+1:]))





Fixed code:
N=int(input())
s=[]
t=[]
for i in range(N):
    s_tmp,t_tmp=map(str,input().split())
    s.append(s_tmp)
    t.append(int(t_tmp))
X=input() 

# N=3
# s=["dwango","sixth","prelims"]
# t=[ 2, 5,25]
# X="prelims"

print(sum(t[s.index(X)+1:]))
Buggy code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
n = ii()
music = []
length = []
for i in range(n):
    ti,leng = map(str,input().split())
    music.append(ti)
    length.append(leng)
x = input()

num = music.index(x)
print(sum(length[x::]))

Fixed code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
n = ii()
music = []
length = []
for i in range(n):
    ti,leng = map(str,input().split())
    music.append(ti)
    length.append(int(leng))
x = input()

num = music.index(x)
print(sum(length[num+1::]))
Buggy code:
N = int(input())
S, T = [0]*N, [0]*N
for i in range(N):
  S[i], T[i] = input().split()
X = input()

print(sum(T[S.index(X)+1:]))

Fixed code:
N = int(input())
S, T = [0]*N, [0]*N
for i in range(N):
  s, t = input().split()
  S[i], T[i] = s, int(t)
X = input()

print(sum(T[S.index(X)+1:]))
Buggy code:
N = input()
s, t = [0]*N, [0]*N
for i in range(N):
  s[i], t[i] = map(int, input().split())
X = input()

ans = 0
flag = False
for i in range(N):
  if flag:
    ans += t[i]
  if s[i] == X:
    flag = True

print(ans)

Fixed code:
N = int(input())
s, t = [0]*N, [0]*N
for i in range(N):
  s[i], t[i] = input().split()
X = input()

ans = 0
flag = False
for i in range(N):
  if flag:
    ans += int(t[i])
  if s[i] == X:
    flag = True

print(ans)
Buggy code:
n = int(input())
l = {}
for i in range(0,n):
    #print (i)
    line = input()
    l[i] = line.strip().split()
x = str(input())
time = 0

for i in range(0,n):
    print (str(l[i][0]), x)
    if l[i][0] == x:
        l.pop(i)
        break
    l.pop(i)

for i in l:
    time += int((l[i][1]))

print (time)

Fixed code:
n = int(input())
l = {}
for i in range(0,n):
    #print (i)
    line = input()
    l[i] = line.strip().split()
x = str(input())
time = 0

for i in range(0,n):
    if l[i][0] == x:
        l.pop(i)
        break
    l.pop(i)

for i in l:
    time += int((l[i][1]))

print (time)
Buggy code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    playlist = dict()
    time = [0] * (N + 1)
    for i in range(N):
        s, t = map(str, input().split())
        playlist[s] = i
        time[i + 1] = time[i] + int(t)
    print(time[N] - time[playlist[input()] + 1])


    return 0

if __name__ == "__main__":
    solve()

Fixed code:
import sys

def solve():
    N = int(input())
    playlist = dict()
    time = [0] * (N + 1)
    for i in range(N):
        s, t = map(str, input().split())
        playlist[s] = i
        time[i + 1] = time[i] + int(t)
    w = input()

    print(time[N] - time[playlist[w] + 1])


    return 0

if __name__ == "__main__":
    solve()
Buggy code:
N=int(input())
ST=[list(map(int,input().split())) for i in range(N)]
X=input()
ans=-1
for s,t in ST:
  if s !=X and ans==-1:
    continue
  else:
    if ans==-1:
      ans=0
    else:
      ans+=t
print(ans)


Fixed code:

N=int(input())
ST=[list(input().split()) for i in range(N)]
X=input()
ans=-1
for s,t in ST:
  if s !=X and ans==-1:
    continue
  else:
    if ans==-1:
      ans=0
    else:
      ans+=int(t)
print(ans)
Buggy code:
N = int(input())

P = []

for _ in range(N):
    s,t = input().split()
    t = int(t)
    P.append([s,t])

X = input()

end_index = 0

for i in range(N):
    p = P[i]

    if p[0]==X:
        end_index = i
        break

count = 0

for i in range(end_index, N, 1):
    count = count + P[i][1]
print(count)


Fixed code:
N = int(input())

P = []

for _ in range(N):
    s,t = input().split()
    t = int(t)
    P.append([s,t])

X = input()

end_index = -1

for i in range(N):
    p = P[i]

    if p[0]==X:
        end_index = i
        break

count = 0

for i in range(end_index+1, N, 1):
    count = count + P[i][1]
print(count)
Buggy code:
N = int(input())

ST_list = []
for i in range(N):
  s, t = map(str, input().split())
  ST_list.append([
    s ,int(t)
  ])
  
X = str(input())
  
cnt = sum(list( node[1] for node in ST_list ))
for node in ST_list:
  cnt -= node[1]
  if X == node[0]:
    break
  cnt -= node[1]
  



print(cnt)

Fixed code:
N = int(input())

ST_list = []
for i in range(N):
  s, t = map(str, input().split())
  ST_list.append([
    s ,int(t)
  ])
  
X = str(input())
  
cnt = sum(list( node[1] for node in ST_list ))

for node in ST_list:
  cnt -= node[1]
  if X == node[0]:
    break
  
print(cnt)
Buggy code:

N = int(input())
i = 0
songs = []
result = 0

while N-i:
    songs.append(input().split())
    i+=1
X = input()
point = len(songs)

for i in range(N):
    if songs[0]==X:
        point = i+1
        break

for i in range(point, N):
    result += songs[1]

print(result)


Fixed code:
N = int(input())

songs = []
result = 0

for i in range(N):
    songs.append(input().split())

X = input()
point = len(songs)

for j in range(N):
    if songs[j][0] == X:
        point = j+1
        break

for i in range(point, N):
    result += int(songs[i][1])


print(result)
Buggy code:
N=int(input())
s=[0]*N
t=[0]*N
for i in range(N):
  s[i],t[i] = input().split()
  t[i]=int(t[i])
X=input()

j= s.index(X)
if X==s[-1]:
  ans=0
else:
  ans= t[j+1:]

print(sum(ans))

Fixed code:
N=int(input())
s=[0]*N
t=[0]*N
for i in range(N):
  s[i],t[i] = input().split()
  t[i]=int(t[i])
X=input()

j= s.index(X)
if X==s[-1]:
  ans=0
else:
  ans= sum(t[j+1:])

print(ans)
Buggy code:
n = int(input())
ans = 0
s = [list(map(str(input().split()))) for i in range(n)]
key_s = str(input())
key = 0
for _ in range(n):
  for t,tt in s:
    if key == 1:
      ans += int(tt)
    if t == key_s:
      key = 1
print(ans)
    

Fixed code:
n = int(input())
ans = 0
s = [list(map(str,input().split())) for i in range(n)]
key_s = str(input())
key = 0
for t,tt in s:
  if key == 1:
    ans += int(tt)
  if t == key_s:
    key = 1
print(ans)
Buggy code:
n=int(input())
s=['']*n
a=[0]*n
for i in range(n):
  s[i],v=input().split()
  a[i]=int(v)
x=input()
flg=False
ans=0
for i in range(n):
  if flg:
    ans+=a[i]
  if s[i]==x
    flg=True
print(ans)

Fixed code:
n=int(input())
s=['']*n
a=[0]*n
for i in range(n):
  s[i],v=input().split()
  a[i]=int(v)
x=input()
flg=False
ans=0
for i in range(n):
  if flg:
    ans+=a[i]
  if s[i]==x:
    flg=True
print(ans)
Buggy code:
N = int(input())
A = [list(map(str, input().split())) for i in range(N)]
S = input()
i = 0
while A[i][0] != S:
  i += 1
print(sum(int(A[j][1]) for j in range(i + 1, N))

Fixed code:
N = int(input())
A = [list(map(str, input().split())) for i in range(N)]
S = input()
i = 0
while A[i][0] != S:
  i += 1
print(sum(int(A[j][1]) for j in range(i + 1, N)))
Buggy code:
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    N = ri()
    S = []
    T = []
    for i in range(N):
        S[i], T[i] = rip()
    X = ri()

    ans = 0
    sleep = False
    for i in range(N):
        if S[i] == X:
            sleep = True
            continue
        if sleep:
            ans += T[i]
    
    print(ans)


if __name__ == "__main__":
    main()


Fixed code:
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    N = ri()
    S = ["a"] * N
    T = [0] * N
    for i in range(N):
        ss = rsa()
        S[i] , T[i] = ss[0], int(ss[1])
    X = rs()

    ans = 0
    sleep = False
    for i in range(N):
        if S[i] == X:
            sleep = True
            continue
        if sleep:
            ans += T[i]
    
    print(ans)


if __name__ == "__main__":
    main()
Buggy code:
n=int(input())
s=list(input().strip().split() for _ in range(n))
x=input().strip()

ans=0
isis=False
for ss,tt in s:
  if isis:
    ans += (tt)
  if ss==x:
    isis=True
print(ans)

Fixed code:
n=int(input())
s=list(input().strip().split() for _ in range(n))
x=input().strip()

ans=0
isis=False
for ss,tt in s:
  if isis:
    ans += int(tt)
  if ss==x:
    isis=True
print(ans)
Buggy code:
t = []
index = {}
for n in range(N):
    si, ti = input().split()
    ti = int(ti)
    index[si] = n
    t.append(ti)

X = input()

ans = 0
for i in range(index[X]+1, N):
    ans += t[i]

print(ans)

Fixed code:
N = int(input())
t = []
index = {}
for n in range(N):
    si, ti = input().split()
    ti = int(ti)
    index[si] = n
    t.append(ti)

X = input()

ans = 0
for i in range(index[X]+1, N):
    ans += t[i]

print(ans)
Buggy code:
n =int(input())
s=[""]*n
t=[0]*n
for i in range(n):
  s[i],t[i] =[s,int(t) for s,t in input().split()]
r = [0] * (n+1)  
for i in range(1,n+1):
  r[i] = r[i-1] + t[i-1]
x=input()
ind = s.index(x)
print(r[n] - r[ind])

Fixed code:
n =int(input())
s=[""]*n
t=[0]*n
for i in range(n):
    s[i],t[i] = input().split()
    t[i] = int(t[i])
r = [0] * (n+1)
for i in range(1,n+1):
  r[i] = r[i-1] + t[i-1]
x=input()
ind = s.index(x)
print(r[n] - r[ind+1])
Buggy code:
def main():
    N = int(input())
    music = []
    m_time = []
    for _ in range(N):
        a, b = input().split()
        music.append(a)
        m_time.append(int(b))
    X = input()
    ans = 0
    for i, a in enumerate(music):
        if a == X:
            for j in range(i, N):
                ans += m_time[j]
    print(ans)
main()

Fixed code:
def main():
    N = int(input())
    music = []
    m_time = []
    for _ in range(N):
        a, b = input().split()
        music.append(a)
        m_time.append(int(b))
    X = input()
    ans = 0
    for i, a in enumerate(music):
        if a == X:
            for j in range(i+1, N):
                ans += m_time[j]
    print(ans)
main()
Buggy code:
n=int(input())
a=[]
for i in range(n):
    st,IN=map(str,input().split())
    a.append([st,IN,i])
f=0
x=input()
for y in a:
    if y[0]==x:
        f=i 
        break 
ss=0
for y in a:
    if y[-1]>f:
        ss+=(int(f[-2]))
print(ss)


Fixed code:
n=int(input())
a=[]
for i in range(n):
    st,IN=map(str,input().split())
    a.append([st,IN])
a=a[::-1]
x=input()
ss=0
for y in a:
    if y[0]==x:
        break
    ss+=int(y[1])
print(ss)
Buggy code:
n=int(input())
l=[input().split() for i in range(n)]
x=input()

ans=0
sum=0
for i,j in l:
 print(i,j)
 if i!=x:
  ans+=int(j)
 else:
  ans+=int(j)
  break
for i,j in l:
 sum+=int(j)
print(sum-ans)

Fixed code:
n=int(input())
l=[input().split() for i in range(n)]
x=input()

ans=0
sum=0
for i,j in l:
 if i!=x:
  ans+=int(j)
 else:
  ans+=int(j)
  break
for i,j in l:
 sum+=int(j)
print(sum-ans)
Buggy code:
n = int(input())
st = [list(input().split()) for nesya in range(n)]
x = input()
c = 0
for a in st:
  if x == st[0]:
    c = 0
  else:
    c += int(st[1])
print(c)

Fixed code:
n = int(input())
st = [list(input().split()) for nesya in range(n)]
x = input()
c = 0
for a in st:
  if x == a[0]:
    c = 0
  else:
    c += int(a[1])
print(c)
Buggy code:
n=int(input())
a=[list(map(input().split())) for _ in range(n)]
x=input()
cnt='x'
for i in a:
  if cnt!='x':
    z=int(i[1])
    cnt+=z
    if i[0]==x:
    cnt=0
print(cnt)

Fixed code:
n=int(input())
a=[(input().split()) for _ in range(n)]
x=input()
cnt='x'
for i in a:
  if cnt!='x':
    z=int(i[1])
    cnt+=z
  if i[0]==x:
    cnt=0
print(cnt)
Buggy code:
N=int(input())
S=[]
T=[]
for i in range(N):
  s,t=input().split()
  S.append(str(s))
  T.append(int(t))
X=str(input())

triger=0
j=0
A=0
for i in S:
  if i==X:
    triger=1
  if triger==1:
    A+=T[j]
  j+=1
print(A)

Fixed code:
N=int(input())
S=[]
T=[]
for i in range(N):
  s,t=input().split()
  S.append(str(s))
  T.append(int(t))
X=str(input())

triger=0
j=0
A=0
for i in S:
  if triger==1:
    A+=T[j]
  if i==X:
    triger=1
  j+=1
print(A)
Buggy code:
n = int(input())
li1 = []
li2 = []
for i in range(n):
    a, b = input().split()
    li1.append(a)
    li2.append(int(b))
x = input()

print(*li1)
print(*li2)

asleep = li1.index(x)
print(sum(li2[asleep+1:]))

Fixed code:
n = int(input())
li1 = []
li2 = []
for i in range(n):
    a, b = input().split()
    li1.append(a)
    li2.append(int(b))
x = input()

asleep = li1.index(x)
print(sum(li2[asleep+1:]))
Buggy code:
N = int(input())
s = ["" for i in range(N)]
t = [0 for i in range(N)]
for i in range(N):
    s_str, t_str = input().split()
    s[i] = s_str
    t[i] = int(t_str)
    
X = input()
ans = 0
count = False
for i in range(X):
    if count:
        ans += t[i]
    if s[i] == X:
        count = True
print(ans)

Fixed code:
N = int(input())
s = ["" for i in range(N)]
t = [0 for i in range(N)]
for i in range(N):
    s_str, t_str = input().split()
    s[i] = s_str
    t[i] = int(t_str)
    
X = input()
ans = 0
count = False
for i in range(N):
    if count:
        ans += t[i]
    if s[i] == X:
        count = True
print(ans)
Buggy code:
n=int(input())
t=[]*n
sec=[]*n
for k in range(n):
  s=input().split()
  t[k]=s[0]
  sec[k]=int(s[1])
x=input()
p=t.index(x)
a=0
if p!=n:
  for l in range(p+1,n):
    a+=sec[l]
print(str(a))

Fixed code:
n=int(input())
t=[""]*n
sec=[0]*n
for k in range(n):
  s=input().split()
  t[k]=s[0]
  sec[k]=int(s[1])
x=input()
p=t.index(x)
a=0
if p!=n:
  for l in range(p+1,n):
    a+=sec[l]
print(str(a))
Buggy code:
n = int(input())
data=[list(inout().split()) for _ in range(n)]
s = input()
ans = 0
c = False
for i in range(n):
  if c:
    ans += int(data[i][1])
  if data[i][0] == s:
    c = True
print(ans)

Fixed code:
n = int(input())
data=[list(input().split()) for _ in range(n)]
s = input()
ans = 0
c = False
for i in range(n):
   if c:
      ans += int(data[i][1])
   if data[i][0] == s:
      c = True
print(ans)
Buggy code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return input().split()
def S(): return input().rstrip()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    st = LSR(n)
    x = S()
    ans = 0
    te = 0
    for s, t in st:
        if te:
            ans += t
        if s == x:
            te = 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Fixed code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return input().split()
def S(): return input().rstrip()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    st = LSR(n)
    x = S()
    ans = 0
    te = 0
    for s, t in st:
        if te:
            ans += int(t)
        if s == x:
            te = 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()
Buggy code:
n=int(input())
s=[]
t=[]
for i in range(n):
	st=list(input())
	s.append(st[0])
	t.append(st[1])
x=input()

print(sum(t[s.index(x):]))


Fixed code:
n=int(input())
s=[]
t=[]
for i in range(n):
	st=list(input().split())
	s.append(st[0])
	t.append(int(st[1]))
x=input()

print(sum(t[s.index(x)+1:]))
Buggy code:
n = int(input())
cum = 0
d = dict()
for _ in range(n):
    a, b = input().split()
    b = int(b)
    cum += b
    d[a] = b
c = input()
print(cum - d[c])

Fixed code:
n = int(input())
cum = 0
d = dict()
for _ in range(n):
    a, b = input().split()
    b = int(b)
    cum += b
    d[a] = cum
c = input()
print(cum - d[c])