#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 1000;
long long a[maxn], b[maxn];
int main() {
  int n, m;
  while (scanf("%d", &n) != EOF) {
    long long sum1 = 0, sum2 = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
      sum1 += a[i];
    }
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) {
      scanf("%lld", &b[i]);
      sum2 += b[i];
    }
    if (sum1 != sum2) {
      puts("-1\n");
      continue;
    }
    sum1 = 0;
    sum2 = 0;
    int i = 1;
    int j = 1;
    int lala = 0;
    while (1) {
      sum1 = sum2 = 0;
      if (i >= n + 1 && j >= m + 1) break;
      while (1) {
        if (sum1 == sum2 && sum1 != 0) {
          lala++;
          break;
        }
        if (sum1 > sum2) {
          sum2 += b[j];
          j++;
        } else {
          sum1 += a[i];
          i++;
        }
      }
    }
    cout << lala << endl;
  }
  return 0;
}
