#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  int ans = 0;
  while (true) {
    bool found = false;
    for (int i = 0; i < n; i++) {
      int x = b[(i - 1 + n) % n], &y = b[i], z = b[(i + 1) % n];
      assert(x > 0 && y > 0 && z > 0);
      if (y < (x + z)) {
        continue;
      }
      int l = 0, r = 1e9;
      while (r - l > 1) {
        int mid = (l + r) >> 1;
        if (y - (x + z) * mid >= a[i]) {
          l = mid;
        } else {
          r = mid;
        }
      }
      ans += l;
      y -= l * (x + z);
      found |= (bool)l;
    }
    if (!found) {
      break;
    }
  }
  cout << (a == b ? ans : -1) << '\n';
  return 0;
}

