#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
  os << "[";
  for (T &i : v) os << i << ",";
  os << "]";
  return os;
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cout << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cout << *sdbg++;
  cout << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
int N;
vector<long long> A, B;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> N;
  for (int i = 0; i < N; i++) {
    long long x;
    cin >> x;
    A.push_back(x);
  }
  for (int i = 0; i < N; i++) {
    long long x;
    cin >> x;
    B.push_back(x);
  }
  priority_queue<pair<long long, long long> > pq;
  for (int i = 0; i < N; i++)
    if (A[i] != B[i]) pq.push(pair<long long, long long>(B[i], i));
  long long cnt = 0;
  while (pq.size()) {
    pair<long long, long long> val = pq.top();
    pq.pop();
    int l = (val.second + N - 1) % N;
    int r = (val.second + 1) % N;
    int mid = val.second;
    if (B[mid] < B[l] + B[r]) {
      cout << -1 << '\n';
      return 0;
    }
    cnt += B[mid] / (B[l] + B[r]);
    B[mid] %= B[l] + B[r];
    (l, r, mid, B[mid], A[mid]);
    if (B[mid] < A[mid]) {
      cout << -1 << '\n';
      return 0;
    }
    if (B[mid] != A[mid]) pq.push(pair<long long, long long>(B[mid], mid));
  }
  cout << cnt << '\n';
  return 0;
}
