#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  long long *A, *B;
  scanf("%d", &n);
  A = (long long *)malloc(n * sizeof(long long));
  for (int i = 0; i < n; i++) scanf("%I64d", A + i);
  scanf("%d", &m);
  B = (long long *)malloc(m * sizeof(long long));
  for (int i = 0; i < m; i++) scanf("%I64d", B + i);
  int len = 0;
  long long subsum = 0;
  int pivot = 0;
  int i, j;
  for (i = 0, j = 0; i < n && j < m;) {
    if (pivot == 0) {
      if (A[i] + subsum < B[j]) {
        subsum += A[i];
        i++;
      } else if (A[i] + subsum == B[j]) {
        subsum = 0;
        i++;
        j++;
        len++;
        if (A[i] < B[j])
          pivot = 0;
        else
          pivot = 1;
      } else {
        A[i] = A[i] + subsum;
        subsum = B[j++];
        pivot = 1;
      }
    } else {
      if (B[j] + subsum < A[i]) {
        subsum += B[j];
        j++;
      } else if (B[j] + subsum == A[i]) {
        subsum = 0;
        i++;
        j++;
        len++;
        if (A[i] < B[j])
          pivot = 0;
        else
          pivot = 1;
      } else {
        B[j] = B[j] + subsum;
        subsum = A[i++];
        pivot = 0;
      }
    }
  }
  if (i == n && j == m)
    printf("%d", len);
  else
    printf("-1");
  return 0;
}
