#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  unsigned long long n;
  cin >> n;
  unsigned long long a[n];
  cin >> a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  unsigned long long m;
  cin >> m;
  unsigned long long b[m];
  cin >> b[0];
  for (int i = 1; i < m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  if (a[n - 1] != b[m - 1]) {
    cout << -1;
    return 0;
  }
  unsigned long long rb = 0;
  unsigned long long ans = 1;
  for (int i = 0; i < n - 1; i++) {
    while (b[rb] < a[i]) rb++;
    if (b[rb] == a[i]) ans++;
  }
  cout << ans;
  return 0;
}
