#include <bits/stdc++.h>
using namespace std;
int n;
long long a[200005], b[200005];
priority_queue<pair<long long, int> > pq;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &b[i]);
    pq.push(pair<long long, int>(b[i], i));
  }
  long long ans = 0;
  while (1) {
    pair<long long, int> rpt = pq.top();
    pq.pop();
    int id = rpt.second;
    if (rpt.first == a[id]) break;
    long long sum = b[(id + n - 1) % n] + b[(id + 1) % n];
    long long mx = max(b[(id + n - 1) % n], b[(id + 1) % n]);
    mx = max(mx, a[id]);
    long long t = (b[id] - mx + sum - 1) / sum;
    b[id] -= sum * t;
    ans += t;
    if (b[id] < a[id]) {
      puts("-1");
      return 0;
    }
    pq.push(pair<long long, int>(b[id], id));
  }
  for (int i = 1; i <= n; i++)
    if (b[i] != a[i]) {
      puts("-1");
      return 0;
    }
  printf("%lld\n", ans);
  return 0;
}
