http://codeforces.com/problemset/problem/950/B

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 l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), 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 nm (1 ≤ n, m ≤ 105) — the number of blocks in the first and in the second messages.

The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 106) — the length of the blocks that form the first message.

The third line contains m integers y1, y2, ..., ym (1 ≤ yi ≤ 106) — the length of the blocks that form the second message.

It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≤ 106.

Output

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

Examples
input

Copy
7 6
2 5 3 1 11 4 4
7 8 2 4 1 8
output
3
input

Copy
3 3
1 10 100
1 100 10
output
2
input

Copy
1 4
4
1 1 1 1
output
1
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.

// 去吧!皮卡丘! 把AC带回来!
// へ     /|
//   /\7    ∠_/
//   / │   / /
//  │ Z _,< /   /`ヽ
//  │     ヽ   /  〉
//  Y     `  /  /
//  イ● 、 ●  ⊂⊃〈  /
//  ()  へ    | \〈
//   >ー 、_  ィ  │ //
//   / へ   / ノ<| \\
//   ヽ_ノ  (_/  │//
//    7       |/
//    >―r ̄ ̄`ー―_
//**************************************
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); }
template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
template <class T> inline T min(T a, T b, T c, T d) {
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d) {
return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int maxn = 1e8 + ;
const int maxx = 1e6 + ;
// name*******************************
bool vis[maxn];
int sum=;
int n,m;
int x;
int ans=;
// function****************************** //***************************************
int main() {
// ios::sync_with_stdio(0); cin.tie(0);
// freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout);
cin>>n>>m;
For(i,,n)
{
cin>>x;
sum+=x;
vis[sum]=;
}
sum=;
For(i,,m){
cin>>x;
sum+=x;
if(vis[sum])ans++;
}
cout<<ans; return ;
}

最新文章

  1. MVC思想
  2. OC-protocol
  3. 攻城狮在路上(叁)Linux(十五)--- 文件与目录的默认权限与隐藏权限
  4. 清空select内容
  5. JLINK SWD下载模式引脚
  6. Android findBugs
  7. [Papers]NSE, $\pi$, Lorentz space [Suzuki, NA, 2012]
  8. MFC下MCI的使用播放音乐
  9. path和classpath细节
  10. jenkins构建个人github上的项目
  11. Chrome开发者控制台操作教程
  12. [No0000146]深入浅出图解C#堆与栈 C# Heap(ing) VS Stack(ing)理解堆与栈3/4
  13. 《剑指offer》第五十八题(左旋转字符串)
  14. 互换元素(swap,swap_ranges)
  15. C# mvc 500 内部服务器访问异常
  16. 断开网络连接的dos命令
  17. uva 1025 A Spy in the Metro 解题报告
  18. cocos代码研究(24)Widget子类PageView学习笔记
  19. script标签的crossorigin属性
  20. iOS开发 - CALayer图层

热门文章

  1. SQL NVARCHAR和VARCHAR限制
  2. js判断移动端页面按home键切换到桌面事件
  3. linux 网络命令last、lastlog、traceroute、netstat
  4. 如何drop大表的中不用的字段 set unused column
  5. 【Redis】Linux下Redis安装与redis-desktop-manager使用(无法连接Redis服务器解决方法)
  6. 能力成熟度模型(CMM)
  7. [UI] Pull menu interaction concept - 下拉菜单交互
  8. 测试TextKit渲染大文本的效率
  9. Word、rss、HTML解析等dll
  10. spark-submit提交参数设置