#include <bits/stdc++.h>
using namespace std;
int numa[300010], numb[300010];
long long sa, sb;
int lena, lenb, ant = 0;
long long suma = 0, sumb = 0;
int main() {
  cin >> lena;
  for (int i = 0; i < lena; i++) {
    scanf("%d", &numa[i]);
    suma += numa[i];
  }
  cin >> lenb;
  for (int i = 0; i < lenb; i++) {
    scanf("%d", &numb[i]);
    sumb += numb[i];
  }
  if (suma != sumb) {
    cout << "-1";
    return 0;
  }
  int j = 0;
  for (int i = 0; i < lena; i++) {
    sa += numa[i];
    while (sa > sb) sb += numb[j++];
    if (sa == sb) ant++;
  }
  cout << ant;
}
