#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void io() {}
long long fast_exp(long long base, int exp, int m) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) {
      res = (res * base) % m;
    }
    base = (base * base) % m;
    exp /= 2;
  }
  return res % m;
}
long long arr[100005];
long long brr[100005];
long long crr[100005];
map<long long, long long> mp;
long long ans = 0;
long long vis[100005];
vector<long long> adj[100005];
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int main() {
  io();
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n;
  vector<long long> suma;
  vector<long long> sumb;
  long long sum1 = 0;
  for (int i = 0; i < int(n); ++i) {
    long long ab;
    cin >> ab;
    sum1 += ab;
    suma.push_back(sum1);
  }
  long long sum2 = 0;
  cin >> m;
  for (int i = 0; i < int(m); ++i) {
    long long ab;
    cin >> ab;
    sum2 += ab;
    sumb.push_back(sum2);
  }
  if (sum1 != sum2) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    int k = binary_search(sumb.begin(), sumb.end(), suma[i]);
    ans += k;
  }
  cout << ans;
}
