#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
T gcd(T a, T b) {
  return ((b == 0) ? a : gcd(b, a % b));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  long long sum = 0;
  for (int i = 0; i < (int)(n); i++) cin >> a[i], sum += a[i];
  int m;
  cin >> m;
  vector<long long> b(m);
  for (int i = 0; i < (int)(m); i++) cin >> b[i], sum -= b[i];
  if (sum != 0) {
    cout << -1 << endl;
    return 0;
  }
  int x = 0, y = 0;
  long long x1 = 0LL, y1 = 0LL;
  int ans = 0;
  while (x < n || y < m) {
    if (x1 == y1) ans++;
    if (x1 < y1 && x < n)
      x1 += a[x], x++;
    else if (y < m)
      y1 += b[y], y++;
  }
  cout << ans << endl;
  return 0;
}
