#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];
  long long int s = 0;
  for (long long int i = 1; i <= n; i++) cin >> arr[i], s += 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], s -= brr[i];
  if (s != 0) {
    return cout << -1, 0;
  }
  long long int a, b;
  long long int ina = 1, inb = 1, ans = 0;
  while (ina <= n and inb <= m) {
    ans++;
    a = arr[ina++], b = brr[inb++];
    while (a != b) {
      if (a < b)
        a += arr[ina++];
      else
        b += brr[inb++];
    }
  }
  cout << ans;
}
