#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5 + 10;
long long t[3][maxn], sit[3][maxn], dp[maxn];
long long n;
long long pre[3][maxn];
map<long long, long long> par;
map<pair<long long, long long>, long long> ans;
long long solve(long long x, long long y) {
  if (ans.count({x, y})) {
    return ans[{x, y}];
  }
  long long ret = dp[min(x, y)];
  if (x == y) {
    return dp[x];
  }
  if (x > y && ~sit[0][x]) {
    ret = max(ret, solve(sit[0][x], y) + 1);
  }
  if (x < y && ~sit[1][y]) {
    ret = max(ret, solve(x, sit[1][y]) + 1);
  }
  return ans[{x, y}] = ret;
}
int32_t main() {
  memset(sit, -1, sizeof(sit));
  cin >> n;
  for (long long i = 0; i < 2; i++) {
    for (long long j = 1; j <= n; j++) {
      cin >> t[i][j];
      if (i) {
        t[2][j] = t[0][j] + t[1][j];
      }
    }
  }
  for (long long i = 0; i < 3; ++i) {
    par.clear();
    par[0] = 0;
    for (long long j = 1; j <= n; ++j) {
      pre[i][j] = pre[i][j - 1] + t[i][j];
      if (par.count(pre[i][j])) {
        sit[i][j] = par[pre[i][j]];
      }
      if (~sit[i][j - 1]) {
        sit[i][j] = max(sit[i][j], sit[i][j - 1]);
      }
      par[pre[i][j]] = j;
    }
  }
  for (long long i = 1; i <= n; ++i) {
    dp[i] = dp[i - 1];
    if (~sit[2][i]) {
      dp[i] = max(dp[i], dp[sit[2][i]] + 1);
    }
    if (~sit[0][i]) {
      dp[i] = max(dp[i], solve(sit[0][i], i) + 1);
    }
    if (~sit[1][i]) {
      dp[i] = max(dp[i], solve(i, sit[1][i]) + 1);
    }
  }
  cout << dp[n] << endl;
}
