#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int grand(int x) { return uniform_int_distribution<int>(0, x - 1)(rng); }
string s = "";
long long arr[1000005] = {0};
long long brr[1000005] = {0};
vector<long long> v;
vector<long long> va, vb;
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n = 0, m = 0, k = 0, q = 0, ans = 0;
  long long x = 0, y = 0, t = 0, sum = 0, sz = 0;
  long long s1 = 0, s2 = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    s1 += arr[i];
    va.push_back(s1);
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> brr[i];
    s2 += brr[i];
    vb.push_back(s2);
  }
  if (s1 != s2) {
    cout << -1 << endl;
    return 0;
  }
  ans = 0;
  for (int i = 0; i < n; i++) {
    x = va[i];
    ans += binary_search(vb.begin(), vb.end(), x);
  }
  cout << ans << endl;
}
