#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline void add(T& a, T b) {
  a = ((a + b) % 1000000007 + 1000000007) % 1000000007;
};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<long long> a(N), b(N);
  priority_queue<pair<long long, int>> pq;
  for (int i = 0; i < N; i++) cin >> a[i];
  for (int i = 0; i < N; i++) {
    cin >> b[i];
    pq.push({b[i], i});
  }
  int ans = 0;
  while (!pq.empty()) {
    long long now = pq.top().first;
    int idx = pq.top().second;
    pq.pop();
    if (now == a[idx])
      continue;
    else if (a[idx] > now) {
      cout << -1 << endl;
      return 0;
    } else {
      if ((b[idx] - a[idx]) / (b[(idx - 1 + N) % N] + b[(idx + 1) % N]) <= 0) {
        cout << -1 << endl;
        return 0;
      }
      ans += (b[idx] - a[idx]) / (b[(idx - 1 + N) % N] + b[(idx + 1) % N]);
      b[idx] -= (b[idx] - a[idx]) / (b[(idx - 1 + N) % N] + b[(idx + 1) % N]) *
                (b[(idx - 1 + N) % N] + b[(idx + 1) % N]);
      pq.push({b[idx], idx});
    }
  }
  for (int i = 0; i < N; i++)
    if (a[i] != b[i]) {
      cout << -1 << endl;
      return 0;
    }
  cout << ans << endl;
}
