#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 3e5 + 5;
long long n, m, ans, sum, sum2;
void solve() {
  cin >> n;
  vector<long long> a(n + 1);
  map<long long, long long> m1;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    m1[sum] = 1;
  }
  cin >> m;
  vector<long long> b(m + 1);
  for (long long i = 1; i <= m; i++) {
    cin >> b[i];
    sum2 += b[i];
    if (m1[sum2] == 1) ans++;
  }
  if (sum != sum2) {
    cout << "-1"
         << "\n";
    return;
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) solve();
  return 0;
}
