#include <bits/stdc++.h>
using namespace std;
inline void cmax(int &x, int y) {
  if (y > x) x = y;
}
const int N = 300006;
map<long long, int> mp, hsh;
long long sum;
int n, h, i, a[3][N], pr[3][N], dp[N];
int inline read() {
  char ch = getchar();
  int z = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    z = z * 10 + ch - '0';
    ch = getchar();
  }
  return z * f;
}
int dfs(int i, int j) {
  if (i == -1 || j == -1) return -INT_MAX;
  if (i == j) return dp[i];
  long long x = (long long)n * i + j;
  if (mp.count(x)) return mp[x];
  int ans = dp[min(i, j)];
  if (i > j)
    cmax(ans, dfs(pr[0][i], j) + 1);
  else
    cmax(ans, dfs(i, pr[1][j]) + 1);
  return mp[x] = ans;
}
int main() {
  n = read();
  for ((h) = (0); (h) <= (1); ++h)
    for ((i) = (1); (i) <= (n); ++i) a[h][i] = read();
  for ((i) = (1); (i) <= (n); ++i) a[2][i] = a[0][i] + a[1][i];
  for ((h) = (0); (h) <= (2); ++h)
    for ((i) = (1); (i) <= (n); ++i) pr[h][i] = -1;
  dp[0] = 0;
  for ((h) = (0); (h) <= (2); ++h) {
    hsh.clear();
    sum = hsh[0] = 0;
    for ((i) = (1); (i) <= (n); ++i) {
      sum += a[h][i];
      if (hsh.count(sum)) pr[h][i] = hsh[sum];
      hsh[sum] = i;
    }
    for ((i) = (2); (i) <= (n); ++i) cmax(pr[h][i], pr[h][i - 1]);
  }
  for ((i) = (1); (i) <= (n); ++i) {
    dp[i] = dp[i - 1];
    if (~pr[2][i]) cmax(dp[i], dp[pr[2][i]] + 1);
    cmax(dp[i], dfs(pr[0][i], i) + 1);
    cmax(dp[i], dfs(i, pr[1][i]) + 1);
  }
  printf("%d\n", dp[n]);
  return 0;
}
