Score
InterviewTime limit2sMemory limit1024 MB
Simulate a score that adds A_i each round and resets to 0 whenever it equals a value in B, then print the final score.
- Level
Easy2 of 10
- Topics
- Simulation, Hash map
- Solved
- No attempts yet
Problem
You are given an integer sequence of length and an integer sequence of length . The score of the game starts at 0. The game has rounds. Round () proceeds as follows.
- Add to the current score.
- If the score after the addition equals one of , set the score to
0.
Print the score at the end of the last round.
Input
The input is given from Standard Input in the following format.
N
A_1 A_2 … A_N
M
B_1 B_2 … B_M
Output
Print the score at the end of the last round.
Constraints
- .
- .
- ().
- ().
- ().
- All input values are integers.