#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int t, n, ans[N], l[3][N], a[3][N];
long long int pre[3][N];
vector<pair<pair<int, int>, int> > v[N];
map<long long int, int> mpx;
void calc(long long int *pre, int *l) {
  int lst = -1;
  auto mini = [&](int &x, int y) { x = (x == -1 ? y : min(x, y)); };
  t++;
  mpx.clear();
  for (int i = n; i >= 1; i--) {
    mpx[pre[i]] = i;
    if (mpx.count(pre[i - 1])) mini(lst, mpx[pre[i - 1]]);
    l[i] = lst;
  }
}
void push(int up, int down, int dist) {
  if (up == 0 || down == 0) return;
  ans[max(up, down)] = max(ans[max(up, down)], dist);
  v[min(up, down)].push_back({{up, down}, dist});
}
void f(int up, int down, int dist) {
  if (up <= n) {
    push(up + 1, down, dist);
    push(l[0][up] + 1, down, dist + 1);
  }
  if (down <= n) {
    push(up, down + 1, dist);
    push(up, l[1][down] + 1, dist + 1);
  }
  if (up == down && up <= n) push(l[2][up] + 1, l[2][down] + 1, dist + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < 2; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
      pre[i][j] = pre[i][j - 1] + a[i][j];
    }
  }
  for (int j = 1; j <= n; j++) {
    a[2][j] = a[1][j] + a[0][j];
    pre[2][j] = pre[2][j - 1] + a[2][j];
  }
  for (int i = 0; i < 3; i++) calc(pre[i], l[i]);
  for (int i = 1; i <= n; i++) {
    f(i, i, ans[i]);
    auto mini = [&](int &x, int y) { x = (x == -1 ? y : min(x, y)); };
    int lup = -1, ldwn = -1;
    for (auto j : v[i]) {
      if (j.first.second == i && j.second == ans[i] + 1)
        mini(lup, j.first.first);
      if (j.first.first == i && j.second == ans[i] + 1)
        mini(ldwn, j.first.second);
    }
    if (lup != -1) f(lup, i, ans[i] + 1);
    if (ldwn != -1) f(i, ldwn, ans[i] + 1);
  }
  cout << ans[n + 1] << endl;
}
