#include <bits/stdc++.h>
using namespace std;
template <class T>
T inline sqr(T x) {
  return x * x;
}
const long double pi = 3.1415926535897932384626433832795;
const long double eps = 1e-8;
const int N = 300500;
const int inf = 1e9;
vector<long long> a[2];
vector<int> suff[2];
int n;
vector<int> f(const vector<long long>& a) {
  vector<int> ans(n);
  long long s = 0;
  map<long long, int> last;
  int l = inf;
  last[0] = n;
  for (int i = n - 1; i >= 0; --i) {
    s += a[i];
    auto it = last.find(s);
    ans[i] = l;
    if (it != last.end()) {
      if (l > it->second) ans[i] = l = it->second;
      it->second = i;
    } else {
      last[s] = i;
    }
  }
  ans.push_back(inf);
  return ans;
}
pair<int, int> d[2][N];
bool operator<(const pair<int, int>& a, const pair<int, int>& b) {
  if (a.first != b.first) return a.first < b.first;
  return a.second > b.second;
}
bool uax(pair<int, int>& a, pair<int, int> b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
void pr(const pair<int, int>& a) { cerr << a.first << " " << a.second << endl; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  scanf("%d", &n);
  for (int t = 0; t < (int)(2); ++t) {
    a[t].resize(n);
    int x;
    for (int i = 0; i < (int)(n); ++i) {
      scanf("%d", &x);
      a[t][i] = x;
    }
  }
  for (int t = 0; t < (int)(2); ++t) suff[t] = f(a[t]);
  vector<long long> sum(n);
  for (int i = 0; i < (int)(n); ++i) sum[i] = a[0][i] + a[1][i];
  vector<int> ssuf = f(sum);
  for (int t = 0; t < (int)(2); ++t) d[t][0] = make_pair(0, 0);
  for (int l = 0; l < (int)(n + 1); ++l) {
    for (int t = 0; t < (int)(2); ++t) {
      int val = d[t][l].first, mpos = d[t][l].second;
      while (suff[t ^ 1][mpos] <= l) {
        mpos = suff[t ^ 1][mpos];
        val++;
      }
      d[t][l] = make_pair(val, mpos);
      uax(d[t][l + 1], d[t][l]);
      if (suff[t][l] != inf) uax(d[t][suff[t][l]], make_pair(val + 1, mpos));
      if (suff[t ^ 1][mpos] != inf)
        uax(d[t ^ 1][suff[t ^ 1][mpos]], make_pair(val + 1, l));
      if (ssuf[l] != inf) {
        for (int nt = 0; nt < (int)(2); ++nt)
          uax(d[nt][ssuf[l]], make_pair(val + 1, ssuf[l]));
      }
    }
  }
  int ans = 0;
  for (int l = 0; l < (int)(n + 1); ++l)
    for (int t = 0; t < (int)(2); ++t) ans = max(ans, d[t][l].first);
  cout << ans << "\n";
  return 0;
}
