#include <bits/stdc++.h>
using namespace std;
char B[1 << 26], *S = B, C;
long long X, F;
inline long long read() {
  for (F = 1; (C = *S++) < '0' || C > '9';)
    if (C == '-') F = -1;
  for (X = C - '0'; (C = *S++) >= '0' && C <= '9';)
    X = (X << 3) + (X << 1) + C - '0';
  return X * F;
}
long long s[300000 + 5][3];
int t[300000 + 5][3], f[300000 + 5];
map<long long, int> mp;
map<pair<int, int>, int> u, ff;
int cal(int x, int y) {
  if (u[make_pair(x, y)]) return ff[make_pair(x, y)];
  return u[make_pair(x, y)] = 1, ff[make_pair(x, y)] = max(
                                     f[min(x, y)], t[x][0] > t[y][1]
                                                       ? cal(t[x][0], y) + 1
                                                       : cal(x, t[y][1]) + 1);
}
int main() {
  fread(B, 1, 1 << 26, stdin);
  int n = read() + 1, i, j, k, l;
  for (i = 2; i <= n; ++i) s[i][0] = s[i - 1][0] + read();
  for (i = 2; i <= n; ++i)
    s[i][1] = s[i - 1][1] + read(), s[i][2] = s[i][0] + s[i][1];
  for (l = 0; l < 3; ++l)
    for (mp.clear(), i = 1; i <= n; ++i)
      t[i][l] = max(t[i - 1][l], mp[s[i][l]]), mp[s[i][l]] = i;
  f[0] = t[0][0] = t[0][1] = -1;
  u[make_pair(0, 0)] = 1;
  ff[make_pair(0, 0)] = -2;
  for (i = 2; i <= n; ++i)
    f[i] = max(f[t[i][2]] + 1, cal(i, i)), ff[make_pair(i, i)] = f[i];
  printf("%d", f[n]);
}
