#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int main() {
  long long int sum_a = 0;
  long long int sum_b = 0;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
  }
  cin >> m;
  long long int b[m];
  for (int i = 0; i < m; i++) {
    scanf("%lld", b + i);
  }
  if (sum_a != sum_b) {
    cout << -1 << endl;
    return 0;
  }
  sum_a = 0;
  sum_b = 0;
  int i = 0;
  int j = 0;
  int k = 0;
  while (i < n || j < m) {
    if (sum_a < sum_b) {
      sum_a += a[i];
      i++;
    } else if (sum_b < sum_a) {
      sum_b += b[j];
      j++;
    } else {
      sum_a += a[i];
      sum_b += b[j];
      i++;
      j++;
      k++;
    }
  }
  if (sum_a != sum_b)
    cout << -1 << endl;
  else
    cout << k << endl;
  return 0;
}
