#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9, N = 300000;
const double eps = 1e-6, phi = acos(-1);
long long mod(long long a, long long b) {
  if (a >= b || a < 0) a %= b;
  if (a < 0) a += b;
  return a;
}
long long read() {
  long long x = 0;
  int zf = 1;
  char ch;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') zf = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * zf;
}
void write(long long y) {
  if (y < 0) putchar('-'), y = -y;
  if (y > 9) write(y / 10);
  putchar(y % 10 + '0');
}
map<long long, int> Derec;
map<pair<int, int>, int> F;
int Pre[3][N + 5];
long long T[3][N + 5];
int Solve(int n, int m) {
  if (!~Pre[1][n] && !~Pre[2][m] && !~Pre[0][min(n, m)]) return 0;
  pair<int, int> P(n, m);
  if (F.count(P)) return F[P];
  int ans = 0;
  if (Pre[1][n] > Pre[2][m])
    ans = max(ans, Solve(Pre[1][n], m) + 1);
  else if (~Pre[2][m])
    ans = max(ans, Solve(n, Pre[2][m]) + 1);
  if (~Pre[0][min(n, m)])
    ans = max(ans, Solve(Pre[0][min(n, m)], Pre[0][min(n, m)]) + 1);
  return F[P] = ans;
}
int main() {
  int n = read();
  for (register int i = 1; i <= n; i++) T[0][i] += (T[1][i] = read());
  for (register int i = 1; i <= n; i++) T[0][i] += (T[2][i] = read());
  for (register int i = 0; i <= 2; i++)
    for (register int j = 1; j <= n; j++) T[i][j] = T[i][j - 1] + T[i][j];
  for (register int i = 0; i <= 2; i++) {
    Derec.clear();
    Derec[0] = 0;
    Pre[i][0] = -1;
    for (register int j = 1; j <= n; j++) {
      Pre[i][j] =
          max(Pre[i][j - 1], Derec.count(T[i][j]) ? Derec[T[i][j]] : -1);
      Derec[T[i][j]] = j;
    }
  }
  printf("%d\n", Solve(n, n));
}
