A - Falling Asleep Editorial /

Time Limit: 2.525 sec / Memory Limit: 1024 MB

配点 : 200200

問題文

ニワンゴ君は NN 曲からなるプレイリストを作りました。 ii 番目の曲はタイトルが sis_i で、再生時間が tit_i 秒です。 ここで、s1,,sNs_1,\ldots,s_N が相異なることが保証されます。

ニワンゴ君はこのプレイリストを再生しながら、作業をしていました。(すなわち、プレイリストの全曲が順番通りに 11 回ずつ、間に休止を挟むことなく再生されました。) しかし、作業中に居眠りをしてしまい、全曲の再生が終わったあとに起きました。 記録から、タイトルが XX の曲の再生が終わるタイミングでニワンゴ君が寝てしまったことがわかりました。

ニワンゴ君が寝ている間に曲が再生された時間が何秒あったかを求めてください。

制約

  • 1N501 \leq N \leq 50
  • si,Xs_i,X は英小文字のみからなる長さ 11 以上 100100 以下の文字列
  • s1,,sNs_1,\ldots,s_N は相異なる
  • si=Xs_i = X なる整数 ii が存在する
  • 1ti10001 \leq t_i \leq 1000
  • tit_i は整数

入力

入力は以下の形式で標準入力から与えられる。

NN
s1s_1 t1t_1
\vdots
sNs_{N} tNt_N
XX

出力

答えを出力せよ。


入力例 1Copy

Copy
3
dwango 2
sixth 5
prelims 25
dwango

出力例 1Copy

Copy
30
  • ニワンゴ君が寝ている間に再生された曲は sixthprelims です。
  • これらの再生時間の総和である 3030 が答えです。

入力例 2Copy

Copy
1
abcde 1000
abcde

出力例 2Copy

Copy
0
  • ニワンゴ君が寝ている間に再生された曲はありません。
  • 再生時間の総和は 00 となります。

入力例 3Copy

Copy
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

出力例 3Copy

Copy
6348

Score : 200200 points

Problem Statement

Niwango created a playlist of NN songs. The title and the duration of the ii-th song are sis_i and tit_i seconds, respectively. It is guaranteed that s1,,sNs_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 XX.

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

Constraints

  • 1N501 \leq N \leq 50
  • sis_i and XX are strings of length between 11 and 100100 (inclusive) consisting of lowercase English letters.
  • s1,,sNs_1,\ldots,s_N are distinct.
  • There exists an integer ii such that si=Xs_i = X.
  • 1ti10001 \leq t_i \leq 1000
  • tit_i is an integer.

Input

Input is given from Standard Input in the following format:

NN
s1s_1 t1t_1
\vdots
sNs_{N} tNt_N
XX

Output

Print the answer.


Sample Input 1Copy

Copy
3
dwango 2
sixth 5
prelims 25
dwango

Sample Output 1Copy

Copy
30
  • While Niwango was asleep, two songs were played: sixth and prelims.
  • The answer is the total duration of these songs, 3030.

Sample Input 2Copy

Copy
1
abcde 1000
abcde

Sample Output 2Copy

Copy
0
  • No songs were played while Niwango was asleep.
  • In such a case, the total duration of songs is 00.

Sample Input 3Copy

Copy
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 3Copy

Copy
6348


2025-03-31 (Mon)
15:05:41 +00:00