#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int maxn = 305000;
long long n, m;
long long suma, sumb;
long long a[maxn], b[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> b[i];
  int i = 1, j = 1;
  suma = a[1];
  sumb = b[1];
  long long ans = 0;
  for (; i <= n && j <= m;) {
    if (suma > sumb) {
      sumb += b[++j];
    } else if (suma < sumb) {
      suma += a[++i];
    }
    if (suma == sumb) {
      sumb = b[++j];
      suma = a[++i];
      ans++;
    }
  }
  if (suma != sumb) {
    cout << "-1" << endl;
  } else {
    for (; i <= n;) {
      suma += a[++i];
    }
    for (; j <= m;) {
      sumb += b[++j];
    }
    if (suma == sumb) {
      cout << ans << endl;
    } else {
      cout << "-1" << endl;
    }
  }
  return 0;
}
