#include <bits/stdc++.h>
using namespace std;
int n, a[2][300010], l1[2][300010], l2[300010], pre1[2][300010], pre2[300010],
    f[300010];
map<int, int> g[300010];
long long s1[2][300010], s2[300010];
int wk(int x, int y) {
  if (x == y) return f[x];
  if (g[x].count(y)) return g[x][y];
  g[x][y] = f[min(x, y)];
  if (x < y && ~pre1[1][y])
    g[x][y] = max(g[x][y], wk(x, pre1[1][y]) + 1);
  else if (x > y && ~pre1[0][x])
    g[x][y] = max(g[x][y], wk(pre1[0][x], y) + 1);
  return g[x][y];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < 2; i++)
    for (int j = 1; j <= n; j++) {
      scanf("%d", &a[i][j]);
      s1[i][j] = s1[i][j - 1] + a[i][j];
    }
  for (int i = 1; i <= n; i++) s2[i] = s2[i - 1] + a[0][i] + a[1][i];
  map<long long, int> mp;
  for (int i = 0; i < 2; i++) {
    mp[0] = 0;
    pre1[i][0] = -1;
    for (int j = 1; j <= n; j++) {
      if (!mp.count(s1[i][j]))
        pre1[i][j] = -1;
      else
        pre1[i][j] = mp[s1[i][j]];
      pre1[i][j] = max(pre1[i][j], pre1[i][j - 1]);
      mp[s1[i][j]] = j;
    }
    mp.clear();
  }
  mp[0] = 0;
  pre2[0] = -1;
  for (int i = 1; i <= n; i++) {
    if (!mp.count(s2[i]))
      pre2[i] = -1;
    else
      pre2[i] = mp[s2[i]];
    pre2[i] = max(pre2[i - 1], pre2[i]);
    mp[s2[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    f[i] = f[i - 1];
    if (~pre2[i]) f[i] = max(f[i], f[pre2[i]] + 1);
    if (~pre1[0][i]) f[i] = max(f[i], wk(pre1[0][i], i) + 1);
    if (~pre1[1][i]) f[i] = max(f[i], wk(i, pre1[1][i]) + 1);
  }
  printf("%d\n", f[n]);
}
