#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n;
    cin >> n;
    vector<long long int> a, b;
    for (long long int i = 0; i < n; i++) {
      long long x;
      cin >> x;
      a.push_back(x);
    }
    priority_queue<pair<long long int, long long int>,
                   std::vector<pair<long long int, long long int> >,
                   std::less<pair<long long int, long long int> > >
        mxheap;
    for (long long int i = 0; i < n; i++) {
      long long x;
      cin >> x;
      b.push_back(x);
      mxheap.push({x, i});
    }
    long long ans = 0;
    while (!mxheap.empty()) {
      pair<long long int, long long int> p = mxheap.top();
      long long i = p.second;
      long long s = b[(p.second + 1) % n] + b[(p.second + n - 1) % n];
      mxheap.pop();
      if ((b[i] - a[i]) % s == 0) {
        ans += (b[i] - a[i]) / s;
        b[i] = a[i];
        continue;
      }
      if (s >= b[i]) {
        cout << -1 << '\n';
        return 0;
      }
      ans += b[i] / s;
      b[i] %= s;
      if (b[i] < a[i]) {
        cout << -1 << '\n';
        return 0;
      }
      mxheap.push({b[i], i});
    }
    cout << ans << '\n';
  }
  return 0;
}
