#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7, INF = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
  long long r = 1 % P;
  for (a %= P; n; a = a * a % P, n >>= 1)
    if (n & 1) r = r * a % P;
  return r;
}
long long inv(long long first) {
  return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;
}
inline int rd() {
  int first = 0;
  char p = getchar();
  while (p < '0' || p > '9') p = getchar();
  while (p >= '0' && p <= '9') first = first * 10 + p - '0', p = getchar();
  return first;
}
const int N = 1e6 + 10;
int n, a[2][N], pos[3][N], ans[N];
long long s[3][N];
map<long long, int> v[3];
pair<int, int> ext[2][N];
void chkmax(int &a, int b) {
  if (a < b) a = b;
}
void chkmax(pair<int, int> &a, pair<int, int> b) {
  if (b.second > a.second || b.second == a.second && b.first < a.first) a = b;
}
void upd(int first, int second, int s) {
  if (first < second)
    chkmax(ans[second], s), chkmax(ext[0][first], pair<int, int>(second, s));
  else
    chkmax(ans[first], s), chkmax(ext[1][second], pair<int, int>(first, s));
}
void extend(int first, int second, int s) {
  upd(first + 1, second, s), upd(first, second + 1, s);
  if (pos[0][first]) upd(pos[0][first], second, s + 1);
  if (pos[1][second]) upd(first, pos[1][second], s + 1);
  if (first == second && pos[2][first])
    upd(pos[2][first], pos[2][first], s + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i <= 1; ++i)
    for (int j = 1; j <= n; ++j) scanf("%d", a[i] + j);
  for (int i = 0; i <= 1; ++i)
    for (int j = n; j >= 1; --j) {
      s[i][j] = s[i][j + 1] + a[i][j];
      s[2][j] += s[i][j];
    }
  for (int i = 0; i <= 2; ++i)
    for (int j = n + 1; j >= 1; --j) {
      pos[i][j] = v[i][s[i][j]];
      v[i][s[i][j]] = j;
    }
  for (int i = 1; i <= n; ++i) {
    extend(i, i, ans[i]);
    if (ext[0][i].second) extend(i, ext[0][i].first, ext[0][i].second);
    if (ext[1][i].second) extend(ext[1][i].first, i, ext[1][i].second);
  }
  printf("%d\n", ans[n + 1]);
}
