#include <bits/stdc++.h>
using namespace std;
const long long int inf = (long long int)1e18 + 10;
const int maxn = 500;
const int maxl = 500;
priority_queue<pair<int, int> > pq;
int a[200005], b[200005];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, x, y, val, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    pq.push(make_pair(b[i], i));
  }
  int cnt = 0;
  while (pq.size() > 0) {
    pair<int, int> p = pq.top();
    pq.pop();
    x = p.second;
    val = p.first;
    if (val == a[x]) continue;
    y = b[(x - 1 + n) % n] + b[(x + 1) % n];
    int r = (val - a[x]) / y;
    if (r <= 0) {
      ans = -1;
      break;
    }
    ans += r;
    b[x] -= r * y;
    if (b[x] > a[x]) pq.push(make_pair(b[x], x));
  }
  cout << ans << endl;
}
