#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
const long long N = 1e6 + 10;
long long solve(vector<long long> arr, vector<long long> brr) {
  long long i1 = 0, i2 = 0;
  long long n = arr.size();
  long long m = brr.size();
  long long sz = 0;
  long long sum1 = 0;
  long long sum2 = 0;
  while (i1 < n && i2 < m) {
    sum1 += arr[i1++];
    while (i2 < m && sum2 + brr[i2] <= sum1) {
      sum2 += brr[i2];
      i2++;
    }
    while (i1 < n && sum1 + arr[i1] <= sum2) {
      sum1 += arr[i1++];
    }
    if (sum1 == sum2) {
      sz++;
      sum1 = 0;
      sum2 = 0;
    }
  }
  return sz;
}
void peace() {
  long long n, m;
  cin >> n;
  vector<long long> arr(n);
  long long sum1 = 0, sum2 = 0;
  for (auto &x : arr) {
    cin >> x;
    sum1 += x;
  }
  cin >> m;
  vector<long long> brr(m);
  for (auto &x : brr) {
    cin >> x;
    sum2 += x;
  }
  if (sum1 != sum2) {
    cout << -1 << endl;
    return;
  }
  long long ans = solve(arr, brr);
  reverse(arr.begin(), arr.end());
  reverse(brr.begin(), brr.end());
  ans = max(ans, solve(arr, brr));
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  t = 1;
  while (t--) peace();
}
