#include <bits/stdc++.h>
using namespace std;
const int N = 300300;
int a[N];
int b[N];
long long pa[N];
long long push_back[N];
int dp[N];
int ul[N];
int dl[N];
map<long long, int> ff, fa, fb;
map<int, int> dm[N];
int solve(int u, int d) {
  if (u == d) return dp[u];
  if (dm[u].count(d)) return dm[u][d];
  int& res = dm[u][d];
  res = dp[min(u, d)];
  if (u < d) {
    if (dl[d] != -1) res = max(res, solve(u, dl[d]) + 1);
  } else {
    if (ul[u] != -1) res = max(res, solve(ul[u], d) + 1);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pa[i] = pa[i - 1] + a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    push_back[i] = push_back[i - 1] + b[i];
  }
  ff[0] = 0;
  fa[0] = 0;
  fb[0] = 0;
  ul[0] = -1;
  dl[0] = -1;
  for (int i = 1; i <= n; i++) {
    dp[i] = dp[i - 1];
    long long cf = pa[i] + push_back[i];
    if (ff.count(cf)) {
      dp[i] = max(dp[i], 1 + dp[ff[cf]]);
    }
    ff[cf] = i;
    ul[i] = ul[i - 1];
    dl[i] = dl[i - 1];
    if (fa.count(pa[i])) {
      if (ul[i] < fa[pa[i]]) {
        ul[i] = fa[pa[i]];
      }
    }
    if (fb.count(push_back[i])) {
      if (dl[i] < fb[push_back[i]]) {
        dl[i] = fb[push_back[i]];
      }
    }
    if (ul[i] != -1) dp[i] = max(dp[i], solve(ul[i], i) + 1);
    if (dl[i] != -1) dp[i] = max(dp[i], solve(i, dl[i]) + 1);
    fa[pa[i]] = i;
    fb[push_back[i]] = i;
  }
  cout << dp[n] << endl;
  return 0;
}
