Codeforces Round 469 (Div. 2)
B
Intercepted Message
Codeforces
1100
原题
← AC →
翻译中…

Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information.

翻译中…

Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of $*k*$ files of sizes $*l*_{1}, *l*_{2}, ..., *l*_{*k*}$ bytes, then the $*i*$-th file is split to one or more blocks $*b*_{*i*, 1}, *b*_{*i*, 2}, ..., *b*_{*i*, *m*_{*i*}}$ (here the total length of the blocks $*b*_{*i*, 1} + *b*_{*i*, 2} + ... + *b*_{*i*, *m*_{*i*}}$ is equal to the length of the file $*l*_{*i*}$), and after that all blocks are transferred through the network, maintaining the order of files in the archive.

翻译中…

Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages.

翻译中…

You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$, $*m*$ ($1 ≤ *n*, *m* ≤ 10^{5}$) — the number of blocks in the first and in the second messages.

翻译中…

The second line contains $*n*$ integers $*x*_{1}, *x*_{2}, ..., *x*_{*n*}$ ($1 ≤ *x*_{*i*} ≤ 10^{6}$) — the length of the blocks that form the first message.

翻译中…

The third line contains $*m*$ integers $*y*_{1}, *y*_{2}, ..., *y*_{*m*}$ ($1 ≤ *y*_{*i*} ≤ 10^{6}$) — the length of the blocks that form the second message.

翻译中…

It is guaranteed that $*x*_{1} + ... + *x*_{*n*} = *y*_{1} + ... + *y*_{*m*}$. Also, it is guaranteed that $*x*_{1} + ... + *x*_{*n*} ≤ 10^{6}$.

翻译中…

Output

翻译中…

Print the maximum number of files the intercepted array could consist of.

翻译中…

Note

翻译中…

In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes $2 + 5 = 7$, $15 = 3 + 1 + 11 = 8 + 2 + 4 + 1$ and $4 + 4 = 8$.

翻译中…

In the second example it is possible that the archive contains two files of sizes $1$ and $110 = 10 + 100 = 100 + 10$. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes $1$, $10$ and $100$.

翻译中…

In the third example the only possibility is that the archive contains a single file of size $4$.

翻译中…

样例

Input #1
7 6
2 5 3 1 11 4 4
7 8 2 4 1 8
Output #1
3
InputCopy OutputCopy
Input #2
3 3
1 10 100
1 100 10
Output #2
2
InputCopy OutputCopy
Input #3
1 4
4
1 1 1 1
Output #3
1
InputCopy OutputCopy
题目信息
题号
950B
时间限制
1 s
内存限制
512 MB
标签
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。