#include <bits/stdc++.h>
using namespace std;
long long int Lpow(long long int a, long long int b, long long int m) {
  long long int ans = 1;
  while (b > 0) {
    if (b % 2) ans = (ans * a) % m;
    a = (a * a) % m;
    b = b / 2;
  }
  return ans;
}
long long int Lpow(long long int a, long long int b) {
  long long int ans = 1;
  while (b > 0) {
    if (b % 2) ans = (ans * a);
    a = (a * a);
    b = b / 2;
  }
  return ans;
}
long long int gcd(long long int a, long long int b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int times = 0;
  long long int sum1 = 0;
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  int m;
  cin >> m;
  set<long long int> brr;
  long long int curr = 0;
  long long int x;
  for (int i = 0; i < m; i++) {
    cin >> x;
    curr += x;
    brr.insert(curr);
  }
  for (int i = 0; i < n; i++) {
    sum1 += arr[i];
    if (*brr.lower_bound(sum1) == sum1) times++;
  }
  if (times && sum1 == curr)
    cout << times << '\n';
  else
    cout << -1 << '\n';
  return 0;
}
