#include <bits/stdc++.h>
using namespace std;
int find_d(int n) {
  int l = 0, r = n + 1;
  while (l < r - 1) {
    int m = (l + r) / 2;
    if (1ll * m * m <= n) {
      l = m;
    } else {
      r = m;
    }
  }
  return l;
}
const int MAXN = 300000;
const int MAXD = 200;
int n, d;
int arr[3][MAXN];
int pval[3][MAXN + 1];
int pblock[2][MAXN + 1];
int pblock_cnt[2][MAXN + 1];
int dp[MAXN + 1][MAXD];
void find_bords(int* vals, int* prev, int sz) {
  map<long long, int> psum_idx;
  long long cur_psum = 0ll;
  psum_idx[cur_psum] = 0;
  memset(prev, -1, sz * sizeof(*prev));
  for (int i = 0; i < sz; ++i) {
    prev[i + 1] = prev[i];
    cur_psum += vals[i];
    auto it = psum_idx.find(cur_psum);
    if (it != psum_idx.end()) {
      prev[i + 1] = max(prev[i + 1], it->second);
    }
    psum_idx[cur_psum] = i + 1;
  }
}
void find_blocks(int* prev, int* pblock, int* pcnt, int sz) {
  memset(pblock, -1, sz * sizeof(*pblock));
  memset(pcnt, 0, sz * sizeof(*pcnt));
  for (int i = 1; i <= sz; ++i) {
    int bl_i = i / d;
    int pr = prev[i];
    if (pr != -1 && pr / d == bl_i) {
      pblock[i] = pblock[pr];
      pcnt[i] = pcnt[pr] + 1;
    } else {
      pblock[i] = i;
      pcnt[i] = 0;
    }
  }
}
int calc_ans(int x, int y);
int calc_ans_local(int x, int y, int y_local) {
  if (dp[x][y_local] == -1) {
    int ans = 0;
    if (x > y) {
      int px = pval[0][x];
      if (px == -1) {
        ans = calc_ans_local(y, y, y_local);
      } else if (px >= y) {
        ans = calc_ans_local(px, y, y_local) + 1;
      } else {
        ans = max(calc_ans_local(y, y, y_local), calc_ans(px, y) + 1);
      }
    } else if (x < y) {
      int py = pval[1][y];
      int x_local = y_local - (y - x), py_local = y_local - (y - py);
      if (py == -1) {
        ans = calc_ans_local(x, x, x_local);
      } else if (py >= x) {
        ans = calc_ans_local(x, py, py_local) + 1;
      } else {
        ans = max(calc_ans_local(x, x, x_local), calc_ans(x, py) + 1);
      }
    } else {
      int px = pval[0][x], py = pval[1][x], pt = pval[2][x];
      if (pt != -1) {
        ans = calc_ans_local(pt, pt, pt % d) + 1;
      }
      if (px > -1 || py > -1) {
        if (px >= py) {
          ans = max(ans, calc_ans(px, y) + 1);
        } else {
          ans = max(ans, calc_ans(x, py) + 1);
        }
      }
    }
    dp[x][y_local] = ans;
  }
  return dp[x][y_local];
}
int calc_ans(int x, int y) {
  int bl_x = x / d, bl_y = y / d;
  int add = 0;
  while (bl_x > bl_y && pval[0][pblock[0][x]] >= y) {
    add += pblock_cnt[0][x] + 1;
    x = pval[0][pblock[0][x]];
    bl_x = x / d;
  }
  if (pblock[0][x] >= y) {
    add += pblock_cnt[0][x];
    x = pblock[0][x];
  }
  while (bl_y > bl_x && pval[1][pblock[1][y]] >= x) {
    add += pblock_cnt[1][y] + 1;
    y = pval[1][pblock[1][y]];
    bl_y = y / d;
  }
  if (pblock[1][y] >= x) {
    add += pblock_cnt[1][y];
    y = pblock[1][y];
  }
  if (bl_x > bl_y) {
    int ans = calc_ans_local(y, y, y % d);
    if (pval[0][x] != -1) {
      ans = max(ans, calc_ans(pval[0][x], y) + 1);
    }
    return ans + add;
  } else if (bl_x < bl_y) {
    int ans = calc_ans_local(x, x, x % d);
    if (pval[1][y] != -1) {
      ans = max(ans, calc_ans(x, pval[1][y]) + 1);
    }
    return ans + add;
  } else {
    return calc_ans_local(x, y, y % d) + add;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  d = min(find_d(n), MAXD);
  for (int r = 0; r < 2; ++r) {
    for (int c = 0; c < n; ++c) {
      cin >> arr[r][c];
    }
  }
  for (int c = 0; c < n; ++c) {
    arr[2][c] = arr[0][c] + arr[1][c];
  }
  for (int r = 0; r < 3; ++r) {
    find_bords(arr[r], pval[r], n);
  }
  for (int r = 0; r < 2; ++r) {
    find_blocks(pval[r], pblock[r], pblock_cnt[r], n);
  }
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    calc_ans_local(i, i, i % d);
  }
  cout << calc_ans_local(n, n, n % d) << '\n';
  return 0;
}
