#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 10;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, a, b, m;
  long long s1, s2;
  s1 = 0;
  s2 = 0;
  a = 0;
  b = 0;
  cin >> n;
  vector<long long> arr(N + 5);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  cin >> m;
  vector<long long> brr(N + 5);
  for (int i = 0; i < m; i++) {
    cin >> brr[i];
  }
  long long count = -1;
  while (a <= n && b <= m) {
    if (s1 == s2) {
      count++;
      s1 = s1 + arr[a++];
      s2 = s2 + brr[b++];
    } else if (s1 < s2) {
      s1 = s1 + arr[a++];
    } else {
      s2 = s2 + brr[b++];
    }
  }
  if (a > n && b > m)
    cout << count << endl;
  else
    cout << -1 << endl;
  return 0;
}
