#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int& i : A) {
    cin >> i;
  }
  for (int& i : B) {
    cin >> i;
  }
  ll res = 0;
  priority_queue<pair<int, int>> Q;
  for (int i = 0; i < N; i++) {
    if (B[i] != A[i]) {
      Q.emplace(B[i], i);
    }
  }
  while (!Q.empty()) {
    int v, p;
    tie(v, p) = Q.top();
    Q.pop();
    int l = B[(p - 1 + N) % N];
    int r = B[(p + 1) % N];
    int w = max(l, r);
    int s = l + r;
    if (A[p] >= w && (B[p] - A[p]) % s == 0) {
      res += (B[p] - A[p]) / s;
      B[p] = A[p];
    } else {
      int x = (v - w) / s + 1;
      B[p] -= x * s;
      res += x;
    }
    if (B[p] < A[p]) {
      return cout << -1 << endl, 0;
    }
    if (B[p] > A[p]) {
      Q.emplace(B[p], p);
    }
  }
  cout << res << endl;

  return 0;
}
