#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int t[4][maxn];
int n;
void calc(int *t, int *rg) {
  static long long sum[maxn];
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + t[i];
  map<long long, int> M;
  M[0] = 0;
  for (int i = 1; i <= n; i++) {
    if (M.count(sum[i])) {
      rg[i] = max(M[sum[i]] + 1, rg[i - 1]);
    } else
      rg[i] = rg[i - 1];
    M[sum[i]] = i;
  }
}
int rg[4][maxn];
map<pair<int, int>, int> M;
int dp[maxn];
int DP(int x, int y) {
  if (x == -1 || y == -1) return int(-1e9);
  if (x == y) return dp[x];
  if (M.count({x, y})) return M[{x, y}];
  int &ans = M[{x, y}];
  ans = dp[min(x, y)];
  if (x > y) {
    return ans = max(ans, DP(rg[1][x] - 1, y) + 1);
  } else {
    return ans = max(ans, DP(x, rg[2][y] - 1) + 1);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &t[1][i]);
  for (int i = 1; i <= n; i++) scanf("%d", &t[2][i]);
  for (int i = 1; i <= n; i++) t[3][i] = t[1][i] + t[2][i];
  for (int i = 1; i <= 3; i++) calc(t[i], rg[i]);
  auto up = [](int &x, int y) { x = max(x, y); };
  for (int i = 1; i <= n; i++) {
    dp[i] = dp[i - 1];
    if (rg[3][i]) dp[i] = max(dp[i], dp[rg[3][i] - 1] + 1);
    dp[i] = max(dp[i], DP(rg[1][i] - 1, i) + 1);
    dp[i] = max(dp[i], DP(i, rg[2][i] - 1) + 1);
  }
  cout << dp[n] << endl;
  return 0;
}
