#include <bits/stdc++.h>
using namespace std;
const int nsz = 2e5;
int n, a[nsz + 5], b[nsz + 5], ans;
priority_queue<pair<int, int>> q;
bool inline chk() {
  for (int i = 1; i <= n; ++i) {
    if (a[i] != b[i]) return 0;
  }
  return 1;
}
int inline pre(int id) { return id != 1 ? id - 1 : n; }
int inline nxt(int id) { return id != n ? id + 1 : 1; }
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
    if (a[i] != b[i]) {
      q.push(make_pair(b[i], i));
    }
  }
  for (; !q.empty();) {
    int cur = q.top().first, id = q.top().second;
    q.pop();
    int del = b[pre(id)] + b[nxt(id)],
        cnt = max(1, (cur - max(b[pre(id)], b[nxt(id)])) / del);
    ans += cnt;
    b[id] = cur - cnt * del;
    if (a[id] > b[id]) {
      ans = -1;
      break;
    } else if (a[id] != b[id]) {
      q.push(make_pair(b[id], id));
    }
  }
  cout << ans << '\n';
}
