#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0;
  char c = getchar();
  bool f = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  if (f) return -sum;
  return sum;
}
const int N = 300005;
int n, a[N], b[N];
map<long long, int> SA, SB, SC;
int pa[N], pb[N], pc[N];
map<long long, int> f;
map<long long, bool> vis;
inline int dp(int x, int y) {
  long long U = (long long)N * x + y;
  if (vis[U]) return f[U];
  vis[U] = 1;
  int r = 0, a;
  if ((a = pc[min(x, y)]) >= 0) r = dp(a, a) + 1;
  if (pa[x] >= 0 || pb[y] >= 0) {
    if (pa[x] > pb[y])
      r = max(r, dp(pa[x], y) + 1);
    else
      r = max(r, dp(x, pb[y]) + 1);
  }
  return f[U] = r;
}
int main() {
  int i, j;
  n = read();
  for (i = 1; i <= n; i++) a[i] = read();
  for (i = 1; i <= n; i++) b[i] = read();
  SA[0] = SB[0] = SC[0] = 1;
  pa[0] = pb[0] = pc[0] = -1;
  long long sa = 0, sb = 0, sc = 0;
  for (i = 1; i <= n; i++) {
    sa += a[i];
    sb += b[i];
    sc += (a[i] + b[i]);
    pa[i] = SA[sa] - 1;
    pb[i] = SB[sb] - 1;
    pc[i] = SC[sc] - 1;
    SA[sa] = SB[sb] = SC[sc] = i + 1;
  }
  for (i = 1; i <= n; i++) {
    pa[i] = max(pa[i], pa[i - 1]);
    pb[i] = max(pb[i], pb[i - 1]);
    pc[i] = max(pc[i], pc[i - 1]);
  }
  printf("%d\n", dp(n, n));
  return 0;
}
