/
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
高橋君は N 軒の店で買い物をしました。はじめ、高橋君は 10000 円持っていました。
i 軒目の店では A_i 円の商品を買って B_i 円支払いました。ここで A_i \leq B_i が成り立ちます。そして、S_i = keep の時、高橋君はお釣りを受け取らず、S_i = take の場合、お釣りを受け取りました。
高橋君が全ての店でお釣りを受け取っていた場合に比べて損した金額を求めてください。厳密に述べると、
- 高橋君の最終的な所持金を X 円、
- 高橋君が全ての店でお釣りを受け取っていた場合の最終的な所持金を Y 円
とした時、Y - X を求めてください。
制約
- 1 \leq N \leq 100
- 1 \leq A_i \leq B_i \leq 100
- S_i は
keepまたはtake - N, A_i, B_i は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 S_1 A_2 B_2 S_2 \vdots A_N B_N S_N
出力
高橋君が全ての店でお釣りを受け取っていた場合に比べて損した金額を出力せよ。
入力例 1
3 1 2 keep 3 6 take 5 9 keep
出力例 1
5
高橋君の行動を説明すると次の通りです。
- 1 番目の店で 1 円の商品を買い、2 円支払い、お釣りを受け取らなかった。
- 2 番目の店で 3 円の商品を買い、6 円支払い、お釣りを受け取った。
- 3 番目の店で 5 円の商品を買い、9 円支払い、お釣りを受け取らなかった。
入力例 2
8 36 49 take 38 73 keep 27 85 take 65 71 take 52 86 keep 48 60 keep 37 98 keep 5 38 keep
出力例 2
175
Score : 200 points
Problem Statement
Takahashi made purchases at N stores. Initially, he had 10000 yen.
At the i-th store, he bought an item worth A_i yen and paid B_i yen. Here, A_i \leq B_i holds. If S_i = keep, he did not receive the change, and if S_i = take, he received the change.
Find the amount of money he lost compared to the case where he received the change at every store. To be precise,
- let X yen be Takahashi's final amount of money, and
- let Y yen be Takahashi's final amount of money in the case where he received the change at every store.
Find Y - X.
Constraints
- 1 \leq N \leq 100
- 1 \leq A_i \leq B_i \leq 100
- S_i is
keeportake. - N, A_i, B_i are all integers.
Input
The input is given from Standard Input in the following format:
N A_1 B_1 S_1 A_2 B_2 S_2 \vdots A_N B_N S_N
Output
Output the amount of money Takahashi lost compared to the case where he received the change at every store.
Sample Input 1
3 1 2 keep 3 6 take 5 9 keep
Sample Output 1
5
Takahashi's actions are as follows.
- At the first store, he bought an item worth 1 yen, paid 2 yen, and did not receive the change.
- At the second store, he bought an item worth 3 yen, paid 6 yen, and received the change.
- At the third store, he bought an item worth 5 yen, paid 9 yen, and did not receive the change.
Sample Input 2
8 36 49 take 38 73 keep 27 85 take 65 71 take 52 86 keep 48 60 keep 37 98 keep 5 38 keep
Sample Output 2
175