QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 1024 MB

#23921. Score

Statistiques

An integer sequence $A = (A_1, A_2, \dots, A_N)$ of length $N$ and an integer sequence $B = (B_1, B_2, \dots, B_M)$ of length $M$ are given.

You play a game using these sequences. Initially, the score of this game is $0$.

In this game, $N$ rounds are played. The $i$-th round ($1 \le i \le N$) proceeds as follows:

  1. Add $A_i$ to the current score.
  2. If the score after addition is equal to any of $B_1, B_2, \dots, B_M$, set the score to $0$.

Output the score of this game at the end of the last round.

Constraints

  • $1 \le N \le 100$.
  • $1 \le M \le 100$.
  • $1 \le A_i \le 10$ ($1 \le i \le N$).
  • $1 \le B_j \le 1000$ ($1 \le j \le M$).
  • $B_j \ne B_k$ ($1 \le j < k \le M$).
  • All input values are integers.

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

Output the score of this game at the end of the last round.

Examples

Input 1

4
3 1 4 1
4
2 7 1 8

Output 1

0

Note

  • Initially, the score of this game is $0$.
  • In the $1$-st round, $3$ is added to the score. Since the score $3$ after addition is different from all of $B_1 = 2, B_2 = 7, B_3 = 1, B_4 = 8$, the score at the end of this round is $3$.
  • In the $2$-nd round, $1$ is added to the score. Since the score $4$ after addition is different from all of $B_1, B_2, B_3, B_4$, the score at the end of this round is $4$.
  • In the $3$-rd round, $4$ is added to the score. Since the score $8$ after addition is equal to $B_4$, the score at the end of this round is $0$.
  • In the $4$-th round, $1$ is added to the score. Since the score $1$ after addition is equal to $B_3$, the score at the end of this round is $0$.
  • Since the score of this game at the end of the last round is $0$, output $0$.

Input 2

5
1 4 1 4 2
3
1 3 5

Output 2

6

Note

  • Initially, the score of this game is $0$.
  • In the $1$-st round, $1$ is added to the score. Since the score $1$ after addition is equal to $B_1$, the score at the end of this round is $0$.
  • In the $2$-nd round, $4$ is added to the score. Since the score $4$ after addition is different from all of $B_1 = 1, B_2 = 3, B_3 = 5$, the score at the end of this round is $4$.
  • In the $3$-rd round, $1$ is added to the score. Since the score $5$ after addition is equal to $B_3$, the score at the end of this round is $0$.
  • In the $4$-th round, $4$ is added to the score. Since the score $4$ after addition is different from all of $B_1, B_2, B_3$, the score at the end of this round is $4$.
  • In the $5$-th round, $2$ is added to the score. Since the score $6$ after addition is different from all of $B_1, B_2, B_3$, the score at the end of this round is $6$.
  • Since the score of this game at the end of the last round is $6$, output $6$.

Input 3

2
10 10
3
1 11 111

Output 3

20

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.