#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0;
  long long sum_a = 0, sum_b = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum_a += a[i];
  }
  cin >> m;
  vector<int> b(m);
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
    sum_b += b[i];
  }
  int i = 0, j = 0;
  if (sum_a != sum_b) {
    cout << -1;
    return 0;
  } else {
    sum_a = a[0];
    sum_b = b[0];
    while (j < m && i < n) {
      if (sum_a > sum_b) {
        j++;
        sum_b += b[j];
      } else if (sum_a < sum_b) {
        i++;
        sum_a += a[i];
      } else {
        ans++;
        i++;
        j++;
        sum_a = a[i];
        sum_b = b[j];
      }
    }
  }
  cout << ans;
}
