#include <bits/stdc++.h>
using namespace std;
long long sa[300005], sb[300005];
set<long long> s;
int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int main() {
  sa[0] = 0, sb[0] = 0;
  int n = read();
  for (int i = 1; i <= n; i++) {
    int a = read();
    sa[i] = sa[i - 1] + a;
  }
  int m = read();
  for (int i = 1; i <= m; i++) {
    int b = read();
    sb[i] = sb[i - 1] + b;
    s.insert(sb[i]);
  }
  if (sa[n] == sb[m]) {
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (s.find(sa[i]) != s.end()) {
        ++ans;
      }
    }
    printf("%d\n", ans);
  } else
    printf("-1\n");
  return 0;
}
