#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cout.tie(0);
  cout.sync_with_stdio(0);
  int n, m;
  cin >> n;
  vector<long long> a(n);
  long long sum1 = 0;
  long long sum2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum1 += a[i];
  }
  cin >> m;
  vector<long long> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    sum2 += b[i];
  }
  if (sum2 != sum1) {
    cout << -1;
    return 0;
  }
  long long uk1 = 0, uk2 = 0;
  int d = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    uk1 += a[i];
    while (uk1 > uk2) {
      uk2 += b[d];
      if (d == m - 1) {
        cout << ++ans;
        return 0;
      }
      d++;
    }
    if (uk1 == uk2) ans++;
  }
  cout << ans;
  return 0;
}
