#include <bits/stdc++.h>
using namespace std;
int n, i, j;
long long a[4][300011];
long long sum_up[300011], sum_down[300011], sum[300011];
map<long long, int> M_up, M_down, M;
int next_up[300011], next_down[300011], next_both[300011];
int dp[300011];
pair<int, int> dp_up[300011], dp_down[300011];
pair<int, int> best(pair<int, int> a, pair<int, int> b) {
  if (a.first > b.first) return a;
  if (a.first < b.first) return b;
  if (a.second < b.second) return a;
  return b;
}
void extend(int u, int d, int v) {
  if (u > n || d > n) return;
  if (u == d) {
    dp[u] = max(dp[u], v);
  } else {
    if (u < d) {
      dp_up[u] = best(dp_up[u], make_pair(v, d));
    } else {
      dp_down[d] = best(dp_down[d], make_pair(v, u));
    }
  }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[1][i]);
    sum_up[i] = sum_up[i - 1] + a[1][i];
    sum[i] = sum_up[i];
  }
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[2][i]);
    sum_down[i] = sum_down[i - 1] + a[2][i];
    sum[i] += sum_down[i];
  }
  next_up[n + 1] = next_down[n + 1] = next_both[n + 1] = -1;
  for (i = n; i > 0; i--) {
    next_up[i] = next_up[i + 1];
    next_down[i] = next_down[i + 1];
    next_both[i] = next_both[i + 1];
    M_up[sum_up[i]] = i;
    M_down[sum_down[i]] = i;
    M[sum[i]] = i;
    if (M_up[sum_up[i - 1]]) {
      next_up[i] = M_up[sum_up[i - 1]];
    }
    if (M_down[sum_down[i - 1]]) {
      next_down[i] = M_down[sum_down[i - 1]];
    }
    if (M[sum[i - 1]]) {
      next_both[i] = M[sum[i - 1]];
    }
  }
  for (i = 1; i <= n; i++) {
    dp[i] = 0;
    dp_up[i] = dp_down[i] = make_pair(-1, n + 1);
  }
  for (i = 0; i <= n; i++) {
    if (next_up[i + 1] >= i + 1)
      dp_down[i] = best(dp_down[i], make_pair(dp[i] + 1, next_up[i + 1]));
    if (next_down[i + 1] >= i + 1)
      dp_up[i] = best(dp_up[i], make_pair(dp[i] + 1, next_down[i + 1]));
    extend(i, i + 1, dp[i]);
    extend(i + 1, i, dp[i]);
    extend(i + 1, i + 1, dp[i]);
    if (dp_up[i].first != -1) {
      extend(i + 1, dp_up[i].second, dp_up[i].first);
      extend(i, dp_up[i].second + 1, dp_up[i].first);
      if (next_up[i + 1] >= i + 1)
        extend(next_up[i + 1], dp_up[i].second, dp_up[i].first + 1);
    }
    if (dp_down[i].first != -1) {
      extend(dp_down[i].second + 1, i, dp_down[i].first);
      extend(dp_down[i].second, i + 1, dp_down[i].first);
      if (next_down[i + 1] >= i + 1)
        extend(dp_down[i].second, next_down[i + 1], dp_down[i].first + 1);
    }
    if (next_both[i + 1] >= i + 1)
      extend(next_both[i + 1], next_both[i + 1], dp[i] + 1);
  }
  printf("%d", dp[n]);
  return 0;
}
