#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1000 * 100 + 10;
int64_t a[N], b[N];
map<int64_t, int> occ;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
    occ[b[i]] = true;
  }
  if (a[n] != b[m]) return cout << -1 << endl, 0;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (occ.count(a[i])) ans++;
  }
  cout << ans << endl;
  return 0;
}
