#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n;
  cin >> n;
  long long int arr[n + 1];
  for (long long int i = 1; i <= n; i++) cin >> arr[i];
  long long int m;
  cin >> m;
  long long int brr[m + 1];
  for (long long int i = 1; i <= m; i++) cin >> brr[i];
  long long int a = arr[1], b = brr[1];
  long long int ina = 2, inb = 2, ans = 0;
  while (ina <= n and inb <= m) {
    if (a < b) {
      a += arr[ina];
      ina++;
    } else if (b < a) {
      b += brr[inb];
      inb++;
    }
    if (a == b) {
      a = arr[ina];
      b = brr[inb];
      ina++;
      inb++;
      ans++;
    }
  }
  while (ina <= n) {
    a += arr[ina];
    ina++;
  }
  while (inb <= m) {
    b += brr[inb];
    inb++;
  }
  if (a != b)
    ans = -1;
  else
    ans++;
  cout << ans;
}
