#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
signed main() {
  long long n;
  cin >> n;
  vector<long long> a(n), b(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  priority_queue<pair<long long, long long>> q;
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    q.push({b[i], i});
  }
  long long ans = 0;
  while (!q.empty()) {
    auto p = q.top();
    q.pop();
    long long idx = p.second;
    long long left = (idx - 1 + n) % n, right = (idx + 1) % n;
    long long diff = (b[idx] - a[idx]) / (b[left] + b[right]);
    long long val = b[idx] - (b[left] + b[right]) * diff;
    if (diff == 0 || val <= a[idx]) continue;
    b[idx] = val;
    q.push({val, idx});
    ans += diff;
  }
  if (a != b) ans = -1;
  cout << ans << endl;
  return 0;
}
