#include <bits/stdc++.h>
using namespace std;
inline int Read() {
  char c = getchar();
  int num = 0, f = 1;
  while ('0' > c || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') num = num * 10 + c - '0', c = getchar();
  return (num * f);
}
map<long long, int> mp;
int nx[3][400010], n;
long long p[400010], a[3][400010];
inline void Get(int x) {
  mp.clear();
  for (int i = 1; i <= n; i++) p[i] = p[i - 1] + a[x][i];
  for (int i = n; i >= 1; i--) {
    mp[p[i]] = i;
    if (!mp[p[i - 1]])
      nx[x][i] = n + 1;
    else
      nx[x][i] = mp[p[i - 1]];
  }
  for (int i = n - 1; i >= 1; i--) nx[x][i] = min(nx[x][i], nx[x][i + 1]);
}
pair<int, int> f[400010], g[400010];
inline pair<int, int> Max(pair<int, int> a, pair<int, int> b) {
  if (a.first < b.first) return (b);
  if (a.first > b.first) return (a);
  return (make_pair(a.first, min(a.second, b.second)));
}
inline pair<int, int> Go(int d, int x, int p) {
  int l = 0;
  while (nx[d][p + 1] <= x) p = nx[d][p + 1], l++;
  return (make_pair(p, l));
}
int main() {
  n = Read();
  for (int i = 1; i <= n; i++) a[0][i] = Read();
  for (int i = 1; i <= n; i++) a[1][i] = Read(), a[2][i] = a[0][i] + a[1][i];
  for (int i = 0; i < 3; i++) Get(i);
  nx[1][n + 2] = nx[0][n + 2] = n + 2;
  nx[0][n + 1] = nx[1][n + 1] = nx[2][n + 1] = n + 1;
  for (int i = 0; i <= n; i++) {
    if (i == 1) int deb = 0;
    f[i] = Max(f[i], f[i - 1]);
    g[i] = Max(g[i], g[i - 1]);
    pair<int, int> nw = Go(0, nx[1][f[i].second + 1], i);
    g[nx[1][f[i].second + 1]] =
        Max(g[nx[1][f[i].second + 1]],
            make_pair(f[i].first + nw.second + 1, nw.first));
    nw = Go(1, nx[0][i + 1], f[i].second);
    f[nx[0][i + 1]] =
        Max(f[nx[0][i + 1]], make_pair(f[i].first + nw.second + 1, nw.first));
    nw = Go(1, nx[0][g[i].second + 1], i);
    f[nx[0][g[i].second + 1]] =
        Max(f[nx[0][g[i].second + 1]],
            make_pair(g[i].first + nw.second + 1, nw.first));
    nw = Go(0, nx[1][i + 1], g[i].second);
    g[nx[1][i + 1]] =
        Max(g[nx[1][i + 1]], make_pair(g[i].first + nw.second + 1, nw.first));
    int j_ = nx[2][i + 1];
    f[j_] = Max(f[j_], make_pair(max(f[i].first, g[i].first) + 1, j_));
    g[j_] = Max(g[j_], make_pair(max(f[i].first, g[i].first) + 1, j_));
  }
  printf("%d\n", max(f[n].first, g[n].first));
}
