#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
using ll = long long;
using ld = long double;
constexpr int nax = 300 * 1000 + 105;
constexpr int infty = 1000 * 1000 * 1000 + 5;
constexpr int mod = 1000 * 1000 * 1000 + 7;
int n;
ll tab[2][nax];
int C[nax];
int dp[2][nax];
int poprz[3][nax];
int najpoprz[3][nax];
bool WynikWiekszyRownyDeep(int a, int b, int v) {
  debug() << "WynikWiekszyRownyDepp("
             " ["
          << "a"
             ": "
          << (a)
          << "] "
             " ["
          << "b"
             ": "
          << (b)
          << "] "
             " ["
          << "v"
             ": "
          << (v)
          << "] "
             ") = ?";
  if (C[min(a, b)] >= v) return true;
  if (a <= b and C[a] >= v - 1 and b >= dp[1][a]) return true;
  if (b <= a and C[b] >= v - 1 and a >= dp[0][b]) return true;
  debug() << "WynikWiekszyRownyDepp("
             " ["
          << "a"
             ": "
          << (a)
          << "] "
             " ["
          << "b"
             ": "
          << (b)
          << "] "
             " ["
          << "v"
             ": "
          << (v)
          << "] "
             ") = false";
  return false;
}
bool WynikWiekszyRowny(int a, int b, int v) {
  if (najpoprz[0][a] != -1 and
      WynikWiekszyRownyDeep(najpoprz[0][a] - 1, b, v - 1))
    return true;
  if (najpoprz[1][b] != -1 and
      WynikWiekszyRownyDeep(a, najpoprz[1][b] - 1, v - 1))
    return true;
  debug() << "WynikWiekszyRowny("
             " ["
          << "a"
             ": "
          << (a)
          << "] "
             " ["
          << "b"
             ": "
          << (b)
          << "] "
             " ["
          << "v"
             ": "
          << (v)
          << "] "
             ") = false";
  return false;
}
void SzukajDziobek(int x, int kto) {
  int args[2];
  args[kto ^ 1] = x;
  int a = x + 1, b = n + 1;
  while (a < b) {
    const int c = (a + b) / 2;
    args[kto] = c;
    if (WynikWiekszyRowny(args[0], args[1], C[x] + 1)) {
      b = c;
    } else {
      a = c + 1;
    }
  }
  dp[kto][x] = a;
  debug() << "dp["
             " ["
          << "kto"
             ": "
          << (kto)
          << "] "
             "]["
             " ["
          << "x"
             ": "
          << (x)
          << "] "
             "] = "
          << a;
}
int Maxi(int& x, int a) { x = max(x, a); }
void SzukajSyf(int x) {
  debug() << "SzukajSyf("
             " ["
          << "x"
             ": "
          << (x)
          << "] "
             ")";
  C[x] = C[x - 1];
  debug() << "Mam 0 "
             " ["
          << "C[x]"
             ": "
          << (C[x]) << "] ";
  if (najpoprz[2][x] != -1) {
    Maxi(C[x], C[najpoprz[2][x] - 1] + 1);
  }
  debug() << "Mam 1 "
             " ["
          << "C[x]"
             ": "
          << (C[x]) << "] ";
  for (int j = 0; j < 2; j++) {
    const int A = najpoprz[j][x];
    if (A != -1) {
      if (dp[j ^ 1][A - 1] <= x) {
        debug() << "dorzucam "
                   " ["
                << "j"
                   ": "
                << (j)
                << "] "
                   " ["
                << "A"
                   ": "
                << (A)
                << "] "
                   " ["
                << "C[A - 1] + 2"
                   ": "
                << (C[A - 1] + 2) << "] ";
        Maxi(C[x], C[A - 1] + 2);
      } else {
        debug() << "dorzucam "
                   " ["
                << "j"
                   ": "
                << (j)
                << "] "
                   " ["
                << "A"
                   ": "
                << (A)
                << "] "
                   " ["
                << "C[A - 1] + 1"
                   ": "
                << (C[A - 1] + 1) << "] ";
        Maxi(C[x], C[A - 1] + 1);
      }
    }
  }
}
void Algos() {
  for (int i = 0; i <= n; i++) {
    if (i == 0) {
      C[i] = 0;
    } else {
      SzukajSyf(i);
    }
    debug() << "C["
               " ["
            << "i"
               ": "
            << (i)
            << "] "
               "] = "
            << C[i];
    for (int j = 0; j < 2; j++) {
      dp[j][i] = infty;
    }
    for (int j = 0; j < 2; j++) {
      SzukajDziobek(i, j);
    }
  }
  printf("%d\n", C[n]);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < 2; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%lld", &tab[i][j]);
      tab[i][j] += tab[i][j - 1];
    }
  }
  map<ll, int> s[3];
  s[0][0] = 0;
  s[1][0] = 0;
  s[2][0] = 0;
  poprz[0][0] = najpoprz[0][0] = -1;
  poprz[1][0] = najpoprz[1][0] = -1;
  poprz[2][0] = najpoprz[2][0] = -1;
  for (int i = 1; i <= n; i++) {
    ll war[3] = {tab[0][i], tab[1][i], tab[0][i] + tab[1][i]};
    for (int j = 0; j < 3; j++) {
      auto it = s[j].find(war[j]);
      if (it == s[j].end()) {
        poprz[j][i] = -1;
      } else {
        poprz[j][i] = it->second + 1;
      }
      s[j][war[j]] = i;
      if (poprz[j][i] == -1) {
        najpoprz[j][i] = najpoprz[j][i - 1];
      } else {
        najpoprz[j][i] = max(najpoprz[j][i - 1], poprz[j][i]);
      }
    }
  }
  debug() << range(&najpoprz[0][0], &najpoprz[0][n + 1]);
  debug() << range(&najpoprz[1][0], &najpoprz[1][n + 1]);
  debug() << range(&najpoprz[2][0], &najpoprz[2][n + 1]);
  Algos();
  return 0;
}
