#include <bits/stdc++.h>
using namespace std;
long long a1[300005], a2[300005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long x, y, i, j, s1 = 0, s2 = 0, l = -1;
  cin >> x;
  for (i = 0; i < x; ++i) cin >> a1[i];
  cin >> y;
  for (i = 0; i < y; ++i) cin >> a2[i];
  i = -1, j = -1, s1 = 0, s2 = 0;
  while (i < x && j < y) {
    if (s1 == s2) {
      i++, j++, l++;
      if (i == x || j == y) break;
      s1 = a1[i];
      s2 = a2[j];
    } else if (s1 > s2) {
      j++;
      if (j == y) break;
      s2 += a2[j];
    } else {
      i++;
      if (i == x) break;
      s1 += a1[i];
    }
    if (i == x || j == y) break;
  }
  s1 = 0, s2 = 0;
  s1 = accumulate(a1, a1 + x, s1);
  s2 = accumulate(a2, a2 + y, s2);
  if (s1 != s2) {
    cout << "-1";
    return 0;
  }
  cout << l;
  return 0;
}
