#include <bits/stdc++.h>
using namespace std;
int N;
long A[2 << 17], B[2 << 17];
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  long ans = 0;
  for (int t = 0; t < 400; t++) {
    for (int i = t & 1; i < N; i += 2) {
      long s = B[(i + N - 1) % N] + B[(i + 1) % N];
      long t = (B[i] - A[i]) / s;
      ans += t;
      B[i] -= t * s;
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i] != B[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}
