#include <bits/stdc++.h>
using namespace std;
void MI(int &a, int v) { a = min(a, v); }
void MA(int &a, int v) { a = max(a, v); }
const int N = 300003, INF = 1e9;
array<int, N> a, b, c, na, nb, nc, best;
int n;
struct st {
  int i, j, v;
};
vector<st> ext[N];
void prec(array<int, N> &val, array<int, N> &nval) {
  nval.fill(INF);
  long long cur = 0;
  map<long long, int> nxt;
  nxt[0] = n;
  for (int i = (int)(n); --i >= 0;) {
    cur += val[i];
    if (nxt.count(cur)) nval[i] = nxt[cur];
    MI(nval[i], nval[i + 1]);
    nxt[cur] = i;
  }
}
void remember(st s) {
  MA(best[max(s.i, s.j)], s.v);
  ext[min(s.i, s.j)].push_back(s);
}
void develop(st s) {
  if (s.i == s.j && nc[s.i] != INF) remember({nc[s.i], nc[s.i], s.v + 1});
  if (na[s.i] != INF) remember({na[s.i], s.j, s.v + 1});
  if (nb[s.j] != INF) remember({s.i, nb[s.j], s.v + 1});
}
signed main() {
  cin >> n;
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  for (int i = 0; i < (int)(n); i++) {
    cin >> b[i];
    c[i] = a[i] + b[i];
  }
  prec(a, na), prec(b, nb), prec(c, nc);
  for (int i = 0; i < (int)(n); i++) {
    develop({i, i, best[i]});
    st mii{INF, INF, 0}, mij = mii;
    for (st s : ext[i]) {
      if (s.v == best[i] + 1) {
        if (s.j == i && s.i < mii.i) mii = s;
        if (s.i == i && s.j < mij.j) mij = s;
      }
    }
    for (st s : {mii, mij})
      if (s.i < INF) develop(s);
  }
  int ans = 0;
  for (int i = 0; i < (int)(n + 1); i++) MA(ans, best[i]);
  cout << ans << endl;
}
