#include <bits/stdc++.h>
using namespace std;
long long n, a[3][333333], x, y, sum[4][333333], r[4][333333];
set<pair<long long, long long> > s[333333];
map<pair<long long, long long>, long long> d;
map<long long, long long> last[4];
void read(long long &x) { scanf("%lld", &x); }
int main() {
  cin >> n;
  for (long long i = 1; i <= 2; i++)
    for (long long j = 1; j <= n; j++) read(a[i][j]);
  for (long long i = 1; i <= 2; i++)
    for (long long j = n; j >= 1; j--) {
      sum[i][j] = sum[i][j + 1] + a[i][j];
      sum[3][j] += sum[i][j];
    }
  last[1][0] = last[2][0] = last[3][0] = n + 1;
  r[1][n + 1] = r[2][n + 1] = r[3][n + 1] = n + 1;
  for (long long i = 1; i <= 3; i++)
    for (long long j = n; j >= 1; j--) {
      r[i][j] = r[i][j + 1];
      if (last[i].count(sum[i][j]))
        r[i][j] = min(r[i][j], last[i][sum[i][j]] - 1);
      last[i][sum[i][j]] = j;
    }
  s[0].insert(make_pair(0, 0));
  d[make_pair(0, 0)] = 0;
  for (long long i = 0; i < n; i++) {
    for (pair<long long, long long> cur : s[i]) {
      x = cur.first;
      y = cur.second;
      if (x <= y) {
        s[min(x + 1, y)].insert(make_pair(x + 1, y));
        d[make_pair(x + 1, y)] =
            max(d[make_pair(x + 1, y)], d[make_pair(x, y)]);
        s[min(r[1][x + 1], y)].insert(make_pair(r[1][x + 1], y));
        d[make_pair(r[1][x + 1], y)] =
            max(d[make_pair(r[1][x + 1], y)], d[make_pair(x, y)] + 1);
      }
      if (y <= x) {
        s[min(x, y + 1)].insert(make_pair(x, y + 1));
        d[make_pair(x, y + 1)] =
            max(d[make_pair(x, y + 1)], d[make_pair(x, y)]);
        s[min(r[2][y + 1], x)].insert(make_pair(x, r[2][y + 1]));
        d[make_pair(x, r[2][y + 1])] =
            max(d[make_pair(x, r[2][y + 1])], d[make_pair(x, y)] + 1);
      }
      if (x == y) {
        s[r[3][x + 1]].insert(make_pair(r[3][x + 1], r[3][x + 1]));
        d[make_pair(r[3][x + 1], r[3][x + 1])] =
            max(d[make_pair(r[3][x + 1], r[3][x + 1])], d[make_pair(x, y)] + 1);
      }
      d.erase(make_pair(x, y));
    }
    s[i].clear();
  }
  assert(d.size() <= 4 * n);
  cout << d[make_pair(n, n)];
}
