#include <bits/stdc++.h>
using namespace std;
const int maxn = 300050;
long long a[3][maxn];
int Prev[3][maxn];
int ans[maxn];
map<pair<int, int>, int> gmap;
int findans(int x, int y) {
  if (x < 0 || y < 0)
    return INT_MIN;
  else if (x == y)
    return ans[x];
  if (gmap.count(make_pair(x, y))) return gmap[make_pair(x, y)];
  int temp = ans[min(x, y)];
  if (x > y) temp = max(temp, findans(Prev[0][x], y) + 1);
  if (x < y) temp = max(temp, findans(x, Prev[1][y]) + 1);
  gmap[make_pair(x, y)] = temp;
  return temp;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i <= 1; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    a[2][i] = a[0][i] + a[1][i];
  }
  for (int i = 0; i < 3; i++) {
    map<long long, int> loc;
    loc[0] = 0;
    long long sum = 0;
    for (int j = 1; j <= n; j++) {
      if (!loc.count(sum + a[i][j]))
        Prev[i][j] = -1;
      else
        Prev[i][j] = loc[sum + a[i][j]];
      sum += a[i][j];
      loc[sum] = j;
    }
    Prev[i][0] = -1;
    for (int j = 1; j <= n; j++) {
      Prev[i][j] = max(Prev[i][j], Prev[i][j - 1]);
    }
    loc.clear();
  }
  for (int i = 1; i <= n; i++) {
    ans[i] = ans[i - 1];
    if (Prev[2][i] != -1) ans[i] = max(ans[i], ans[Prev[2][i]] + 1);
    ans[i] = max(ans[i], findans(Prev[0][i], i) + 1);
    ans[i] = max(ans[i], findans(i, Prev[1][i]) + 1);
  }
  cout << ans[n];
  return 0;
}
