#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
map<long long, int> mp;
map<pair<int, int>, int> mpf;
int n, a[3][N];
int p[3][N], f[N];
long long b[N];
void init(int *a, int *p) {
  mp.clear();
  mp[0] = 0;
  for (int i = (int)(1); i <= (int)(n); i++) {
    b[i] = b[i - 1] + a[i];
    p[i] = p[i - 1];
    if (mp.find(b[i]) != mp.end()) p[i] = max(p[i], mp[b[i]] + 1);
    mp[b[i]] = i;
  }
}
int F(int x, int y) {
  if (x < 0 || y < 0) return -(1 << 30);
  if (x == y) return f[x];
  if (mpf.find(pair<int, int>(x, y)) != mpf.end())
    return mpf[pair<int, int>(x, y)];
  if (x > y)
    return mpf[pair<int, int>(x, y)] = max(f[y], F(p[0][x] - 1, y) + 1);
  return mpf[pair<int, int>(x, y)] = max(f[x], F(x, p[1][y] - 1) + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &a[0][i]);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &a[1][i]);
  for (int i = (int)(1); i <= (int)(n); i++) a[2][i] = a[0][i] + a[1][i];
  for (int i = (int)(0); i <= (int)(2); i++) init(a[i], p[i]);
  for (int i = (int)(1); i <= (int)(n); i++) {
    f[i] = f[i - 1];
    if (p[2][i]) f[i] = max(f[i], f[p[2][i] - 1] + 1);
    f[i] = max(f[i], F(p[0][i] - 1, i) + 1);
    f[i] = max(f[i], F(i, p[1][i] - 1) + 1);
  }
  printf("%d\n", f[n]);
}
