#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<long long int> a, b, pre;
int n, m, ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  a.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  cin >> m;
  b.resize(m + 1);
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  if (a[n] != b[m]) {
    cout << "-1\n";
    return 0;
  }
  int x = 1;
  for (int i = 1; i <= m; i++) {
    while (x < n && a[x] < b[i]) x++;
    if (a[x] == b[i]) ans++;
  }
  cout << ans << endl;
}
