#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n;
  long long a1[n];
  for (long long i = 0; i < n; i++) cin >> a1[i];
  cin >> m;
  long long a2[m];
  for (long long i = 0; i < m; i++) cin >> a2[i];
  long long ans = 0;
  long long i = n - 1, j = m - 1;
  long long s1 = 0, s2 = 0;
  while (i >= 0 && j >= 0) {
    if (s1 + a1[i] > s2 + a2[j]) {
      s2 += a2[j];
      j--;
    } else if (s1 + a1[i] < s2 + a2[j]) {
      s1 += a1[i];
      i--;
    } else {
      ans++;
      s1 = 0;
      s2 = 0;
      i--;
      j--;
    }
  }
  if (i < 0 && j < 0)
    cout << ans << endl;
  else
    cout << "-1" << endl;
}
