#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, a[N], b[N];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  for (int i = 0; i < n; ++i) scanf("%d", b + i);
  auto cmp = [&](int i, int j) { return b[i] < b[j]; };
  priority_queue<int, vector<int>, decltype(cmp)> q(cmp);
  for (int i = 0; i < n; ++i) q.push(i);
  int ans = 0;
  while (q.size()) {
    int t = q.top();
    q.pop();
    if (b[t] == a[t])
      continue;
    else if (b[t] < a[t])
      break;
    int lt = (t - 1 + n) % n, rt = (t + 1) % n;
    int x = b[lt] + b[rt], y = b[t] - max(b[rt], max(a[t], b[lt])),
        m = (y + x - 1) / x;
    ans += m;
    b[t] -= m * x;
    if (b[t] > a[t])
      q.push(t);
    else if (b[t] < a[t])
      break;
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] != b[i]) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", ans);
  return 0;
}
