// C - Numbers on a Circle
#include <iostream>
#include <set>
#include <vector>

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  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.insert(std::make_pair(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[(i - 1 + n) % n];
    if (d != 0 && d < t) {
      ans = -1;
      break;
    }
    ans += d / t;
    b[i] -= d / t * t;
    if (b[i] != a[i])
      s.insert(std::make_pair(b[i], i));
  }

  std::cout << ans << std::endl;

  return 0;
}