#include <iostream>
#include <set>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    std::cin >> B[i];
  }
  std::set<std::pair<int, int>, std::greater<std::pair<int, int>>> s;

  for (int i = 0; i < N; i++) {
    s.emplace(B[i], i);
  }

  long long ans = 0;
  while (!s.empty()) {
    int i = s.begin()->second;
    s.erase(s.begin());

    int d = B[i] - A[i], t = B[(i + 1) % N] + B[(N + i - 1) % N];
    if (d != 0 && d < t) {
      ans = -1;
      break;
    }
    ans += d / t;
    B[i] -= d / t * t;

    if (B[i] != A[i])
      s.emplace(B[i], i);
  }

  std::cout << ans;

  return 0;
}