#include <bits/stdc++.h>
using namespace std;
const int MAX = 300100;
int p[2][MAX];
long long pref[3][MAX];
int kamo[3][MAX];
int n;
map<pair<int, int>, int> dp;
int minpoz[2][MAX];
set<pair<int, int> > Poz;
void ubaci(int a, int b, int val) {
  auto tmp = dp.find({a, b});
  if (tmp == dp.end()) {
    dp[{a, b}] = val;
    Poz.insert({a, b});
  } else
    dp[{a, b}] = max(dp[{a, b}], val);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < 2; i++)
    for (int j = (1); j < (n + 1); j++) scanf("%d", &p[i][j]);
  for (int i = (1); i < (n + 1); i++) {
    for (int j = 0; j < 2; j++) pref[j][i] = pref[j][i - 1] + p[j][i];
    pref[2][i] = pref[0][i] + pref[1][i];
  }
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < MAX; j++) kamo[i][j] = MAX - 3;
  for (int i = 0; i < 3; i++) {
    map<long long, int> M;
    for (int j = n; j; j--) {
      M[pref[i][j]] = j;
      auto it = M.find(pref[i][j - 1]);
      if (it != M.end()) kamo[i][j] = it->second + 1;
      kamo[i][j] = min(kamo[i][j], kamo[i][j + 1]);
    }
  }
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < MAX; j++) minpoz[i][j] = MAX - 3;
  ubaci(1, 1, 0);
  for (; !Poz.empty();) {
    auto tmp = *Poz.begin();
    Poz.erase(Poz.begin());
    if (tmp.first > n + 2 || tmp.second > n + 2) continue;
    int mn = min(tmp.first, tmp.second), st = tmp.first > tmp.second,
        moj = dp[tmp], dpmn = dp[{mn, mn}];
    int mx = max(tmp.first, tmp.second);
    if (moj >= dpmn + 2) continue;
    if (moj >= dpmn + 1 && mx > minpoz[st][mn]) continue;
    if (moj == dpmn + 1) minpoz[st][mn] = min(minpoz[st][mn], mx);
    if (tmp.first != tmp.second)
      ubaci(mx, mx, moj);
    else {
      ubaci(kamo[2][tmp.first], kamo[2][tmp.first], moj + 1);
      ubaci(tmp.first + 1, tmp.first + 1, moj);
    }
    ubaci(kamo[0][tmp.first], tmp.second, moj + 1);
    ubaci(tmp.first, kamo[1][tmp.second], moj + 1);
  }
  printf("%d\n", dp[{n + 1, n + 1}]);
  return 0;
}
