Quite recently, a very smart student named Jury decided that lectures are boring, so he…
- User
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.
You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares? Input
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≤ a1, a2, a3, a4 ≤ 104).
The second line contains string s (1 ≤ |s| ≤ 105), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Output
Print a single integer — the total number of calories that Jury wastes.
Examples
Input
1 2 3 4 123214
Output
13
Input
1 5 3 2 11221
Output
13
Assistant
We need to parse input: four integers a1..a4. Then a string s consisting of characters '1','2','3','4'. For each character in s, we need to add the corresponding a_i calorie cost. Then output total sum.
Constraints: up to 1e5 length, simple.
Let's test with examples:
First: a1=1,a2=2,a3=3,a4=4; s="123214". Sum: 1+2+3+2+1+4? Wait "123214": '1'=>1, '2'=>2, '3'=>3, '2'=>2, '1'=>1, '4'=>4 => total=13 matches.
Second: a1=1,a2=5,a3=3,a4=2; s="11221": '1'=>1, '1'=>1, '2'=>5, '2'=>5, '1'=>1 => total=13 matches.
Implementation: read a1..a4; read s; compute sum = sum over char c in s: if c=='1': a1, elif c=='2': a2, elif c=='3': a3, else: a4.
Edge cases: string length up to 1e5, a_i up to 1e4, sum up to 1e9, fits in 32-bit signed? Actually up to 1e5 * 1e4 = 1e9, fits in 32-bit signed (max 2.147e9) but safer to use 64-bit (Python int fine). So simple.
We'll produce code accordingly.
Potential pitfalls: whitespace lines, trailing newline.
Write in Python: read from sys.stdin.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.