#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <class T>
ostream& prnt(ostream& out, T v) {
  out << v.size() << '\n';
  for (auto e : v) out << e << ' ';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, vector<T> v) {
  return prnt(out, v);
}
template <class T>
ostream& operator<<(ostream& out, set<T> v) {
  return prnt(out, v);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, map<T1, T2> v) {
  return prnt(out, v);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  return out << '(' << p.first << ' ' << p.second << ')';
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
const int N = 200100;
int n, a[N], b[N], ans;
priority_queue<pair<int, int> > pq;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] != a[i]) pq.push({b[i], i});
  }
  while (!pq.empty()) {
    auto p = pq.top();
    pq.pop();
    int nxt = a[p.second];
    int dif = p.first - nxt;
    dif /= (b[(n + p.second - 1) % n] + b[(p.second + 1) % n]);
    dif = max(dif, 1);
    ans += dif;
    p.first -= dif * (b[(n + p.second - 1) % n] + b[(p.second + 1) % n]);
    if (p.first != a[p.second]) pq.push(p);
    if (p.first < a[p.second]) return cout << "-1\n", 0;
    b[p.second] = p.first;
  }
  cout << ans << '\n';
}
