#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int n, m;
int a[N], b[N];
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = (0); i < (m); i++) scanf("%d", &b[i]);
  int pa1 = 0, pa2 = 0;
  int pb1 = 0, pb2 = 0;
  long long suma = a[0], sumb = b[0];
  int ans = 0;
  while (true) {
    while (suma != sumb && pa2 < n && pb2 < m) {
      if (suma < sumb)
        suma += a[++pa2];
      else
        sumb += b[++pb2];
    }
    if (suma == sumb)
      pa1 = ++pa2, pb1 = ++pb2, ans++;
    else
      break;
    if (pa2 >= n || pb2 >= m) break;
    suma = a[pa1];
    sumb = b[pb1];
  }
  if (pa2 >= n && pb2 >= m)
    printf("%d\n", ans);
  else
    printf("-1\n");
  return 0;
}
