Under construction

Still being built. Things may change

Score

Interview

Time limit2sMemory limit1024 MB

Summary
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 A=(A1,A2,…,AN)A = (A_1, A_2, \ldots, A_N) of length NN and an integer sequence B=(B1,B2,…,BM)B = (B_1, B_2, \ldots, B_M) of length MM. The score of the game starts at 0. The game has NN rounds. Round ii (1≤i≤N1 \le i \le N) proceeds as follows.

  1. Add AiA_i to the current score.
  2. If the score after the addition equals one of B1,B2,…,BMB_1, B_2, \ldots, B_M, 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

  • 1≤N≤1001 \le N \le 100.
  • 1≤M≤1001 \le M \le 100.
  • 1≤Ai≤101 \le A_i \le 10 (1≤i≤N1 \le i \le N).
  • 1≤Bj≤10001 \le B_j \le 1000 (1≤j≤M1 \le j \le M).
  • Bj≠BkB_j \ne B_k (1≤j<k≤M1 \le j < k \le M).
  • All input values are integers.

Examples3

  1. Example 1

    Input
    4
    3 1 4 1
    4
    2 7 1 8
    
    Expected output
    0
    
  2. Example 2

    Input
    5
    1 4 1 4 2
    3
    1 3 5
    
    Expected output
    6
    
  3. Example 3

    Input
    2
    10 10
    3
    1 11 111
    
    Expected output
    20