#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 100005;
long long a[3 * MAXN], b[3 * MAXN];
long long n, m, d = 0;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0, ThxDem = n; i < ThxDem; i++) cin >> a[i];
  cin >> m;
  for (long long j = 0, ThxDem = m; j < ThxDem; j++) cin >> b[j];
  long long i = 0, j = 0, ti = a[0], tj = b[0];
  while (i < n || j < m) {
    if (ti == tj) {
      d++;
      i++;
      j++;
      ti = a[i];
      tj = b[j];
    } else if (ti < tj) {
      i++;
      ti += a[i];
    } else if (tj < ti) {
      j++;
      tj += b[j];
    }
  }
  if (n != i || m != j)
    cout << -1;
  else
    cout << d;
  return 0;
}
