Problem:


Score : 200 points

Problem Statement

Niwango created a playlist of N songs.
The title and the duration of the i-th song are s_i and t_i seconds, respectively.
It is guaranteed that s_1,\ldots,s_N are all distinct.

Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.)
However, he fell asleep during his work, and he woke up after all the songs were played.
According to his record, it turned out that he fell asleep at the very end of the song titled X.

Find the duration of time when some song was played while Niwango was asleep.

Constraints

1 \leq N \leq 50

s_i and X are strings of length between 1 and 100 (inclusive) consisting of lowercase English letters.

s_1,\ldots,s_N are distinct.

There exists an integer i such that s_i = X.

1 \leq t_i \leq 1000

t_i is an integer.

Input

Input is given from Standard Input in the following format:

N
s_1 t_1
\vdots
s_{N} t_N
X

Output

Print the answer.

Sample Input 1

3
dwango 2
sixth 5
prelims 25
dwango

Sample Output 1

30

While Niwango was asleep, two songs were played: sixth and prelims.

The answer is the total duration of these songs, 30.

Sample Input 2

1
abcde 1000
abcde

Sample Output 2

0

No songs were played while Niwango was asleep.

In such a case, the total duration of songs is 0.

Sample Input 3

15
ypnxn 279
kgjgwx 464
qquhuwq 327
rxing 549
pmuduhznoaqu 832
dagktgdarveusju 595
wunfagppcoi 200
dhavrncwfw 720
jpcmigg 658
wrczqxycivdqn 639
mcmkkbnjfeod 992
htqvkgkbhtytsz 130
twflegsjz 467
dswxxrxuzzfhkp 989
szfwtzfpnscgue 958
pmuduhznoaqu

Sample Output 3

6348



Sample input:
3
dwango 2
sixth 5
prelims 25
dwango


Sample output:
30

Submission status: Accepted

Solution code:
n=int(input())
a=[]
b=[]
for i in range(0,n):
    s,t=[x for x in input().split()]
    t=int(t)
    a.append(s)
    b.append(t)
x=input()
pos=a.index(x)
print( sum(b[pos+1:]) )

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline().rstrip()) 
s, t = [], []
for _ in range(n):
    si, ti = sys.stdin.readline().split()
    s.append(si); t.append(int(ti))
x = sys.stdin.readline().rstrip()

def main():
    cum_t = t[1:n] + [0]
    for i in range(n-1, 0, -1):
        cum_t[i-1] += cum_t[i]
    
    return cum_t[s.index(x)]

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
st = [list(map(str, input().split())) for _ in range(n)]
x = input()
ans = 0
sleep = 0
for i in range(n):
    if sleep == 1:
        ans += int(st[i][1])
    if st[i][0] == x:
        sleep = 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[input().split() for _ in range(n)]
x=input()
ans=0
for i in range(n):
  if x==s[i][0]:
    for a in range(i+1,n):
      ans+=int(s[a][1])
    break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = []
T = []
ans = 0
for _ in range(N):
  s, t = input().split()
  t = int(t)
  S.append(s)
  T.append(t)
X = input()
index = S.index(X)
for i in range(index+1,N):
  ans += T[i]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
'''
lst = {}
for i in range(n):
    s, t = map(str, input().split())
    lst[s] = int(t)
print(lst)
'''
lst = []
for i in range(n):
    s, t = map(str, input().split())
    lst.append([s, int(t)])
title = input()
#print(lst)
for i in range(n):
    if title == lst[i][0]:
        id = i
        break
#print("id",id)
time_cnt = 0
for i in range(id+1, n):
    time_cnt+=lst[i][1]
print(time_cnt)

Submission status: Accepted

Solution code:


def main():
    n = int(input())
    s = [0] * n
    t = [0] * n
    all_time_count = 0

    for i in range(n):
        s[i],t[i] = input().split()
        t[i] = int(t[i])
        all_time_count += t[i]
    x = input()
    time_count = 0
    for i in range(n):
        time_count += t[i]
        if s[i] == x:
            break
    print(all_time_count - time_count)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution 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()

sleep = False
time = 0
for i in range(n):
  if sleep:
    time += t[i]
  elif s[i] == x:
    sleep = True

print(time)

Submission status: Accepted

Solution code:
import numpy as np

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

    idx = S.index(X)
    cumsum = np.cumsum(np.array(T))
    time = cumsum[-1] - cumsum[idx]
    print(time)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n=int(input())
s=[]
t=[]
for i in range(n):
    a,b=map(str,input().split())
    s.append(a)
    t.append(int(b))
x=str(input())
for i in range(n):
    if s[i]==x:
        print(sum(t[i+1:]))

Submission status: Accepted

Solution code:
#ドワンゴ

N=int(input())
pl=[]
tl=[]
for i in range(N):
    songname,time=input().split()
    pl.append(songname)
    tl.append(int(time))
    
X=input()

ind=pl.index(X)

if ind!=N:
    print(sum(tl[ind+1:]))
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
#A,B,K= map(int,input().split())
#v =list(map(int,input().split()))
L = [list(map(str,input().split())) for i in range(N)]
Last = input()
flag = 0
answer  =0
for j in L:
    if flag == 1:
        answer += int(j[1])
    if j[0] == Last:
        flag = 1
print(answer)

Submission status: Accepted

Solution code:
N=int(input())
music=[['', 0] for j in range(N)]
for i in range(N):
  s, t = map(str, input().split())
  music[i][0] = s
  music[i][1] = int(t)
X = input()

count = 0
flag=False
for i in range(N):
  if flag:
    count+=music[i][1]
  if music[i][0]==X:
    flag=True
print(count)

Submission status: Accepted

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

for i in range(n):
    if x==l[i][0]:
        a=i
m=0
for i in range(a+1,n):
    m+=int(l[i][1])
print(m)

Submission status: Accepted

Solution code:
n = int(input())
lis = []
a = 0
b = 0
for _ in range(n):
  x,y = input().split()
  a += int(y)
  lis.append((x, int(y)))
x = input()
cnt = 0
for i in range(n):
    b += lis[i][1]
    if lis[i][0] == x:
        break
print(a-b)

Submission status: Accepted

Solution code:
N=int(input())
S=[]
T=[]
for i in range(N):
  s,t=map(str,input().split())
  t=int(t)
  S.append(s)
  T.append(t)
X=input()
num=None
for i in range(N):
  if S[i]==X:
    num=i
    break
print(sum(T[(num+1):]))

Submission status: Accepted

Solution code:
#coding UTF-8
N=int(input())
L=[]
for i in range(N):
    a,b=map(str,input().split())
    L.append([a,int(b)])
#print(L)

X=input()

for i in range(N):
    if L[i][0]==X:
        flg=i
ans=0
for i in range(flg+1,N):
    ans+=L[i][1]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
  l.append(input().split())
last=input()
ind=0
for i in range(n):
  if l[i][0]==last:
    ind=i
sum=0    
for i in range(ind+1,n):
  sum+=int(l[i][1])
print(sum)

Submission status: Accepted

Solution code:
n = int(input())
st = []
for i in range(n):
    st.append(list(map(str, input().split())))

x = input()

ans = 0
isSleep = False

for _st in st:
    # print(_st[0])
    if _st[0] == x:
        isSleep = True
        continue
    
    if isSleep==True:
        ans += int(_st[1])

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ST = []
for i in range(N):
    ST.append(input().split())
    ST[i][1] = int(ST[i][1])
X = input()

pt = 0
for i in range(N):
    if X == ST[i][0]:
        pt = i
        break

sum = 0
for i in range(pt+1,N):
    sum += ST[i][1]

print(sum)

Submission status: Accepted

Solution code:
n = int(input())
st = []
for _ in range(n):
    a = input().split()
    a[1] = int(a[1])
    st.append(a)
x = input()

res = 0
s = False
for i in st:
    if i[0] == x:
        s = True
    elif s:
        res += i[1]

print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
dict_name = {}
name_list = []
for i in range(0, n):
    name, t = input().split()
    dict_name[name] = int(t)
    name_list.append(name)
x = input()
flag = 0
total = 0
for i in range(0, n):
    if flag == 1:
        total += dict_name[name_list[i]]
    if name_list[i] == x:
        flag = 1
print(total)

Submission status: Accepted

Solution code:
num_input = int(input())

names = []
minutes = []

for _ in range(0, num_input):
    name, minute = input().split()
    minute = int(minute)
    names.append(name)
    minutes.append(minute)

fall = input().strip()

i = names.index(fall)
print(sum(minutes[i+1:]))

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

def solve(n, s, t, x):
    ans = 0
    slept = False
    for i in range(n):
        if slept:
            ans += t[i]
        if s[i] == x:
            slept = True
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    s = [""] * n
    t = [0] * n
    for i in range(n):
        s[i], tmp = sys.stdin.readline().strip().split(" ")
        t[i] = int(tmp)
    x = sys.stdin.readline().strip()
    solve(n, s, t, x)

Submission status: Accepted

Solution code:
N = int(input())
S = [0]*N
T = [0]*N
for _ in range(N):
    S[_],T[_] = input().split()
X = input()

print(sum(map(int,T[S.index(X)+1::]+['0'])))

Submission status: Accepted

Solution code:
N = int(input())
s = []
t = []
for i in range(N):
    st = [c for c in input().split()]
    s.append(st[0])
    t.append(int(st[1]))
X = input()
print(sum(t[s.index(X)+1:]))

Submission status: Accepted

Solution code:
N= int(input())
plList=['' for i in range(N)]
tmList=[0 for i in range(N)]

for i in range(N):
    pl,tm=input().split()
    plList[i]=pl
    tmList[i]=int(tm)

i=plList.index(input())
print(sum(tmList[i+1:]))

Submission status: Accepted

Solution 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)
X = input()

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

Submission status: Accepted

Solution code:
n = int(input())
st = []
for _ in range(n):
    temp = input().split()
    s = temp[0]
    t = int(temp[1])
    st.append((s,t))
x = input()

ans = 0
flag = True
for y in st:
    if flag:
        if y[0] == x:
            flag = False
    else:
        ans += y[1]

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
ST=[]
for i in range(n):
  s,t=map(str,input().split())
  ST.append((s,t))
chk=False
x=input()
ans=0
for s,t in ST:
  if chk:
    ans+=int(t)
  else:
    if s==x:
      chk=True
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    ST = [tuple(input().split()) for _ in [0] * N]
    X = input()

    ans = 0
    for s, t in ST:
        ans += int(t)
    for s, t in ST:
        ans -= int(t)
        if s == X:
            print(ans)
            break


main()

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
  a,b=input().split()
  l.append([a,int(b)])
x=input()
s=0
cnt=0
for i in range(n):
  s+=l[i][1]
for i in range(n):
  if l[i][0]==x:
    print(s-cnt-l[i][1])
    exit()
  cnt+=l[i][1]

Submission status: Accepted

Solution code:
N = int(input())
S = list()
T = list()
for _ in range(N):
    s, t = input().split()
    S.append(s)
    T.append(int(t))
X = input()
ans = 0
flag = False
for i in range(N):
    if flag:
        ans += T[i]
    if S[i] == X:
        flag = True
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
music = []

for i in range(N):
    s, t = input().split()
    t = int(t)

    music.append((s, t))

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

ans = 0
for i in music:
    ans += i[1]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
st = [input().split() for _ in range(N)]
X = input()
ans = 0
flg = 0
for i, ST in enumerate(st):
    s, t = ST

    if s == X:
        flg = 1
        continue

    if flg == 1:
        ans += int(t)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = ["a" for i in range(N)]
t = [0 for i in range(N)]

for i in range(N):
    s[i],t[i] = input().split(" ")

X = input()

p = s.index(X)

T=0
for i in range(p+1,N):
    T += int(t[i])

print(T)

Submission status: Accepted

Solution code:
N=int(input())
S,T=[None]*N,[None]*N
for i in range(N):
    s,t=input().split()
    S[i]=s
    T[i]=int(t)
X=input()
for i in range(N):
    if S[i]==X:
        a=i
        break
print(sum(T[a+1:]))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
#from itertools import permutations

def gcd(a: int, b: int):
    while b: a, b = b, a%b
    return a

def lcm(a: int, b: int):
    return a * b // gcd(a, b)


def main():
    N = int(input())
    mT = [tuple(input().decode().split()) for _ in [0,]*N]
    #N,M = map(int, input().split())
    X = input().decode().rstrip()

    p = 0
    res = 0
    for s,t in mT:
        nt = int(t)
        if p:
            res += nt
        if s==X:
            p = 1

    print(res)
    #vP = tuple(map(int, input().split()))
    #vA = set(map(int, input().split()))
    
    #print(lcm(N,M))
    #print(l, file=sys.stderr)
    #print("Yes" if X<=500*K else "No")
    #print(S.count("ABC"))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
playlist = []
for i in range(n):
    playlist.append(input().split(" "))
    playlist[i][1] = int(playlist[i][1])

# print(playlist)
x = input()
s = 0

for i, p in enumerate(playlist):
    if p[0] == x:
        s = i
        break

sm = 0
for i in range(s+1, n):
    sm += playlist[i][1]

print(sm)

Submission status: Accepted

Solution code:
N = int(input())
st = [list(map(str,input().split())) for i in range(N)]
X = input()
ans = 0
for i in range(N):
    if st[i][0] == X:
        for l in range(i+1,N):
            ans += int(st[l][1])
print(ans)

Submission status: Accepted

Solution 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)

Submission status: Accepted

Solution code:
n = int(input())
s = []
t = []
for i in range(n):
    S,T = map(str,input().split())
    s.append(S)
    t.append(int(T))
x = str(input())
Sum = 0
for i in range(n):
    if s[i] == x:
        ind = i
for i in range(ind+1,n):
    Sum += t[i]
print(Sum)

Submission status: Accepted

Solution code:
N = int(input())
music_list = []
for _ in range(N):
    title,time = input().split()
    music_list.append([title,int(time)])

last_music = input()

ans = 0
sleep_flg = False
for music in music_list:
    if(sleep_flg):
        ans += music[1]

    if(music[0] == last_music):
        sleep_flg = True

print(ans)

Submission status: Accepted

Solution code:
import collections as c
ip = lambda : map(int, input().split())
# ##############
N = int(input())
l = [[],[]]
for i in range(N):
    s,t = input().split()
    l[0].append(s)
    l[1].append(int(t))
X = input()
ix = l[0].index(X)
# print(ix)
print(sum(l[1][ix+1:]))

Submission status: Accepted

Solution code:
N=int(input())
kyoku=list(input().split() for i in range(N))
X=input()
time = 0
sousuu= 0
for i in range(N):
    sousuu += int(kyoku[i][1])

    if kyoku[i][0]==X:
        for j in range(i+1):
            time += int(kyoku[j][1])
print(sousuu-time)

Submission status: Accepted

Solution code:
n=int(input())
song=[]
time=[]
song_t=""
time_t=0
ans=0
for i in range(n):
    song_t,time_t=input().split()
    time_t=int(time_t)
    song.append(song_t)
    time.append(time_t)
ref=str(input())
judge=False
for i in range(n):
    if(judge):
        ans+=time[i]
    else:
        if(song[i]==ref):
            judge=True
print(ans)

Submission status: Accepted

Solution code:
import sys
hyperScan = sys.stdin.readline
n = int(hyperScan())
tSum = 0
tLi = {}
for i in range(n):
    s, t = map(str, hyperScan().strip('\n').split())
    tSum += int(t)
    tLi[s] = tSum

x = hyperScan().strip('\n')
print(tSum - tLi[x])

Submission status: Accepted

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


for i in range(N):
    if s[i] == X:
        ans = t[i+1:]

cnt = 0
for i in range(len(ans)):
    cnt += int(ans[i])

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
a = []
for _ in range(n):
    title, dur = input().split()
    a.append((title, int(dur)))
sleep = input().rstrip()

ret = 0
for i, (title, _) in enumerate(a):
    if sleep == title:
        for j in range(i + 1, n):
            ret += a[j][1]
print(ret)

Submission status: Accepted

Solution code:
N = int(input())

S = list()
T = list()

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

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

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
import itertools
import math
from functools import reduce
n = int(stdin.readline().rstrip())
name = []
span = []
for el in range(n):
    inputter = stdin.readline().rstrip().split()
    name.append(inputter[0])
    span.append(int(inputter[1]))
target = stdin.readline().rstrip()
pos = name.index(target) + 1
res = 0
for el in range(pos, len(span)):
    res += span[el]
print(res)

Submission status: Accepted

Solution code:
n = int(input())
l = []
for i in range(n):
    a,b = input().split()
    l.append((a,b))
x = input()
count = 0
for i in range(n):
  if l[i][0] == x:
    f = i
    break
for i in range(f+1,n):
  count += int(l[i][1])
print(count)

Submission status: Accepted

Solution code:
N=int(input())
S=[]
T=[]

for i in range(N):
   s,t=input().split()
   S.append(s)
   T.append(int(t))

X=input()
count=0

for j in range(N):
   if S[j]==X:
      for k in range(j+1,N):
         count+=T[k]
      break

print(count)

Submission status: Accepted

Solution code:
N = int(input())
s = []
t = []
for i in range(N):
    ss, tt = map(str, input().split())
    s.append(ss)
    t.append(tt)
X = input()

for i in range(N):
    t[i] = int(t[i])

for i in range(N):
    if s[i] == X:
        index = i
        break

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

print(time)

Submission status: Accepted

Solution code:
n = int(input())
s = []
t = []
for i in range(n):
    tmp = input().split()
    s.append(str(tmp[0]))
    t.append(int(tmp[1]))

x = str(input())

index = -1
for i in range(n):
    if s[i] == x:
        index = i
        break

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = []
b = []
for i in range(n):
  x, y = map(str, input().split())
  if(i==0):b.append(int(y))
  else:b.append(b[-1] + int(y))
  a.append(x)
s = input()
print(b[-1] - b[a.index(s)])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
st = []
for _ in range(N):
    st.append(input().rstrip().split())
X = input().rstrip()
s = []
t = []
for i in st:
    s.append(i[0])
    t.append(int(i[1]))
idx = s.index(X)
print(sum(t[idx+1:]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def solve():
    N = int(input())
    d = {}
    T = []
    for i in range(N):
        s, t = input().split()
        d[s] = i
        T.append(int(t))
    X = input()
    return str(sum(T[d[X]+1:]))

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
N=int(input())
st=[input().split() for _ in range(N)]
X=input()
j=0
ans=0
for i in range(N):
  if j==1:
    ans+=int(st[i][1])
  else:
    if st[i][0]==X:
      j=1

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
data = []
for i in range(n):
    s, t = map(str, input().split())
    data.append([s, int(t)])

x = input()
flag = False
ans = 0
for i in range(n):
    if x == data[i][0]:
        flag = True
        continue
    if flag:
        ans += data[i][1]

print(ans)