#include <bits/stdc++.h>
template <class T = int>
std::vector<T> ReadVector(size_t size) {
  std::vector<T> vector(size);
  for (int i = 0; i < size; ++i) {
    std::cin >> vector[i];
  }
  return vector;
}
class Graph {
 public:
  std::vector<std::vector<int>> children;
  std::vector<bool> used;
  Graph() = default;
  explicit Graph(size_t vertices) : children(vertices), used(vertices) {}
  void add_edge(int from, int to) {
    children[from].push_back(to);
    children[to].push_back(from);
  }
  void bfs(int root) {
    std::queue<int> to_observe({root});
    used.assign(children.size(), false);
    while (!to_observe.empty()) {
      auto vertex = to_observe.front();
      to_observe.pop();
      used[vertex] = true;
      for (auto child : children[vertex]) {
        if (!used[child]) {
          to_observe.push(child);
        }
      }
    }
  }
  void dfs(int root) {
    used.assign(children.size(), false);
    dfs_rec(root);
  }
  void dfs_rec(int root) {
    used[root] = true;
    for (auto child : children[root]) {
      if (!used[child]) {
        dfs_rec(child);
      }
    }
  }
};
struct Point {
  int x;
  int y;
};
int md(const Point& p, int x) { return p.y + std::abs(x - p.x); }
int64_t gcd(int64_t a, int64_t b) {
  while (b) {
    a %= b;
    std::swap(a, b);
  }
  return a;
}
class Solver {
 public:
  int count;
  Solver() {}
  void solve() {
    int n, m;
    std::cin >> n;
    auto a = ReadVector<int64_t>(n);
    std::cin >> m;
    auto b = ReadVector<int64_t>(m);
    std::partial_sum(a.begin(), a.end(), a.begin());
    std::partial_sum(b.begin(), b.end(), b.begin());
    int i = 0;
    int j = 0;
    int count = 0;
    while (i < a.size() && j < b.size()) {
      if (a[i] == b[j]) {
        ++count;
        ++i;
        ++j;
      } else if (a[i] < b[j]) {
        ++i;
      } else {
        ++j;
      }
    }
    if (b[b.size() - 1] != a[a.size() - 1])
      std::cout << -1 << std::endl;
    else
      std::cout << count << std::endl;
  }
  std::vector<int64_t> prefix(std::vector<int64_t> a) {
    std::vector<int64_t> pa(a.size(), 0);
    pa[0] = a[0];
    for (int i = 1; i < a.size(); ++i) pa[i] = pa[i - 1] + a[i];
    return pa;
  }
};
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  Solver solver;
  solver.solve();
  return 0;
}
