#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
long long a[3][N];
int p[3][N];
int n;
map<long long, int> mp;
map<pair<int, int>, int> f;
int solve(int x, int y) {
  if (p[0][x] == -1 && p[1][y] == -1 && p[2][min(x, y)] == -1) return 0;
  pair<int, int> cnt(x, y);
  if (f.count(cnt)) return f[cnt];
  int ret = 0;
  if (p[0][x] != -1 && p[0][x] >= p[1][y])
    ret = max(ret, solve(p[0][x], y) + 1);
  else if (p[1][y] != -1)
    ret = max(ret, solve(x, p[1][y]) + 1);
  int z = min(x, y);
  if (p[2][z] != -1) ret = max(ret, solve(p[2][z], p[2][z]) + 1);
  return f[cnt] = ret;
}
int main() {
  scanf("%d", &n);
  for (int i(1); i <= (n); ++i) scanf("%lld", &a[0][i]);
  for (int i(1); i <= (n); ++i) scanf("%lld", &a[1][i]);
  for (int i(1); i <= (n); ++i) a[2][i] = a[0][i] + a[1][i];
  for (int i(0); i <= (2); ++i)
    for (int j(1); j <= (n); ++j) a[i][j] += a[i][j - 1];
  for (int i(0); i <= (2); ++i) {
    mp.clear();
    mp[0] = 0;
    p[i][0] = -1;
    for (int j(1); j <= (n); ++j) {
      p[i][j] = mp.count(a[i][j]) ? mp[a[i][j]] : -1;
      p[i][j] = max(p[i][j], p[i][j - 1]);
      mp[a[i][j]] = j;
    }
  }
  return 0 * printf("%d\n", solve(n, n));
}
