#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int &i : a) scanf("%d", &i);
  int m;
  scanf("%d", &m);
  vector<int> b(m);
  for (int &i : b) scanf("%d", &i);
  long long aSum = 0, bSum = 0;
  for (int i = 0; i < n; ++i) aSum += a[i];
  for (int i = 0; i < m; ++i) bSum += b[i];
  if (aSum == bSum) {
    int ans = 0;
    int aCur = 0, bCur = 0;
    long long aTemp = 0, bTemp = 0;
    while (aCur < n || bCur < m) {
      if (aTemp > bTemp) {
        bTemp += b[bCur];
        ++bCur;
      } else {
        aTemp += a[aCur];
        ++aCur;
      }
      if (aTemp == bTemp) ++ans;
    }
    printf("%d", ans);
  } else {
    printf("-1");
  }
  return 0;
}
