#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, a, sum = 0;
  cin >> n;
  vector<long long int> N, M;
  for (long long int i = 0; i < n; i++) {
    cin >> a;
    N.push_back(a);
    sum += a;
  }
  cin >> m;
  for (long long int i = 0; i < m; i++) {
    cin >> a;
    M.push_back(a);
    sum -= a;
  }
  if (sum) {
    cout << "-1\n";
    return 0;
  }
  long long int np = 0, make_pair = 0, ans = 0;
  while (np < n) {
    ans++;
    long long int sumn = N[np++], summ = M[make_pair++];
    while (sumn != summ) summ > sumn ? sumn += N[np++] : summ += M[make_pair++];
  }
  cout << ans << endl;
  return 0;
}
