#include <bits/stdc++.h>
using namespace std;
const long long Maxn = 3e5 + 10;
const long long Inf = 0x7f7f7f7f;
const long long Inf_ll = 1ll * Inf * Inf;
const long long Mod = 1e9 + 7;
const double eps = 1e-7;
long long dp[Maxn][4], las[Maxn][4];
long long a[Maxn][2];
long long s1, s2, s3;
map<long long, long long> m1, m2, m3;
map<pair<long long, long long>, long long> Map;
long long dfs(long long x, long long y) {
  if (x == 0) return dp[y][2];
  if (y == 0) return dp[x][1];
  if (Map.count(make_pair(x, y))) return Map[make_pair(x, y)];
  long long ans = 0;
  if (las[x][1] > las[y][2])
    ans = max(dfs(las[x][1], y) + 1, ans);
  else if (las[y][2] != -1)
    ans = max(dfs(x, las[y][2]) + 1, ans);
  if (las[min(x, y)][3] != -1)
    ans = max(dfs(las[min(x, y)][3], las[min(x, y)][3]) + 1, ans);
  return Map[make_pair(x, y)] = ans;
}
signed main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i][0]);
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i][1]);
  m1[0] = m2[0] = m3[0] = 0;
  long long las1, las2, las3;
  las1 = las2 = las3 = -1;
  for (long long i = 1; i <= n; i++) {
    s1 += a[i][0], s2 += a[i][1], s3 += a[i][0] + a[i][1];
    long long p1 = las1, p2 = las2, p3 = las3;
    if (m1.count(s1)) p1 = m1[s1];
    if (m2.count(s2)) p2 = m2[s2];
    if (m3.count(s3)) p3 = m3[s3];
    if (p1 != -1) dp[i][1] = dp[p1][1] + 1;
    if (p2 != -1) dp[i][2] = dp[p2][2] + 1;
    dp[i][1] = max(dp[i - 1][1], dp[i][1]);
    dp[i][2] = max(dp[i - 1][2], dp[i][2]);
    m1[s1] = i, m2[s2] = i, m3[s3] = i;
    if (p1 == -1)
      las[i][1] = -1;
    else
      las[i][1] = max(las[i - 1][1], p1);
    if (p2 == -1)
      las[i][2] = -1;
    else
      las[i][2] = max(las[i - 1][2], p2);
    if (p3 == -1)
      las[i][3] = -1;
    else
      las[i][3] = max(las[i - 1][3], p3);
    las1 = p1, las2 = p2, las3 = p3;
  }
  printf("%lld\n", dfs(n, n));
  return 0;
}
