#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> a(n + 1);
  a[n] = 10000000000L;
  long long tot = 0;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    tot += a[i];
  }
  long long m;
  cin >> m;
  vector<long long> b(m + 1);
  b[m] = 100000000000L;
  for (long long i = 0; i < m; ++i) {
    cin >> b[i];
    tot -= b[i];
  }
  if (tot != 0) {
    cout << -1 << "\n";
    return 0;
  }
  long long i = 0, j = 0;
  long long ans = 0;
  while (i < n && j < m) {
    ++ans;
    long long asum = a[i++], bsum = b[j++];
    while (asum != bsum) {
      if (asum < bsum)
        asum += a[i++];
      else
        bsum += b[j++];
    }
  }
  cout << ans << "\n";
}
