#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9) + int(1e5);
const long long INFL = long long(2e18) + long long(1e10);
const unsigned int MOD = 1E9 + 7;
const double EPS = 1e-9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  set<pair<int, int>, greater<pair<int, int>>> B;
  for (int i = 0; i < (n); ++i) cin >> a[i];
  for (int i = 0; i < (n); ++i) {
    cin >> b[i];
    B.emplace(b[i], i);
  }
  auto it = B.begin();
  bool ret = true;
  int op = 0;
  while (!B.empty()) {
    if (it->first < a[it->second]) {
      ret = false;
      break;
    }
    if (it->first > a[it->second]) {
      int i = (it->second + 1 == n ? 0 : it->second + 1);
      int j = (it->second == 0 ? n - 1 : it->second - 1);
      int k = max(1, (b[it->second] - max(a[it->second], max(b[i], b[j]))) /
                         (b[i] + b[j]));
      b[it->second] -= (b[i] + b[j]) * k;
      op += k;
      if (b[it->second] > a[it->second])
        B.emplace(b[it->second], it->second);
      else if (b[it->second] < a[it->second]) {
        ret = false;
        break;
      }
    }
    it = B.erase(it);
  }
  cout << (ret ? op : -1);
}
