#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  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];
  }
  set <pair <int, int> > q;
  for (int i = 0; i < n; i++) {
    q.insert({b[i], i});
  }
  ll ans = 0;
  while (!q.empty()) {
    int i = q.rbegin()->second;
    q.erase(--q.end());
    if (a[i] == b[i]) {
      continue;
    }
    int delta = b[(i - 1 + n) % n] + b[(i + 1) % n];
    int grab = (b[i] - a[i]) / delta;
    b[i] -= grab * delta;
    ans += grab;
    if (!grab) {
      cout << -1 << '\n';
      return 0;
    }
    q.insert({b[i], i});
  }
  cout << ans << '\n';
}
