// Code by H~$~C
#warning "Code by H~$~C, don't copy it!"

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h> // assume the OJ isn't POJ
#define __str__(...) #__VA_ARGS__
#define __cat__(x, y) x##y
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = (1); i <= (n); ++i)
#define Rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, n) for (int i = ((n) - 1); ~i; --i)
#define per1(i, n) for (int i = (n); i; --i)
#define Per(i, a, b) for (int i = (a); i >= (b); --i)
#define repit(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eprintf(...) (fprintf(stderr, __VA_ARGS__) & fflush(stderr))
#define scanfstr(s, len, ...) { static char _str[len + 1]; scanf(__VA_ARGS__, _str); s = _str; }
#define rdstr(s, len) { static char _str[len + 1]; scanf("%s", _str); s = _str; }
#define getstr(s, len) { static char _str[len + 1]; fgets(_str, len, stdin); s = _str; s.pop_back(); }
#define scanfignore() scanf(" ")
#define fillset(a, val) memset(a, val, sizeof(a))
#define All(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define pf push_front
#define y0 y19260817
#define y1 y19268107
#define j0 j19260817
#define j1 j19268107
#define x0 x19260817
#define x1 x19268107
using namespace std;
#ifndef LOCAL_JUDGE
#define Debug(...)
#else
template <typename T> inline void _debug(const char *names, T &&t) {
(cerr << names << " = " << t << endl).flush();}
template <typename T1, typename ...T>
inline void _debug(const char *names, T1 &&t1, T &&... t) {
const char *comma = strchr(names, ',');
(cerr.write(names, comma - names) << " = " << t1 << ", ").flush();
_debug(comma + 1, t ...);}
#define Debug(...) _debug(#__VA_ARGS__, __VA_ARGS__)
#endif
struct __STARTER_OF_PROGRAM__ { __STARTER_OF_PROGRAM__() {
  cerr << "Code by H~$~C: \n" << flush;
} } __starter_of_program__;
struct __ENDDER_OF_PROGRAM__ { ~__ENDDER_OF_PROGRAM__() {
#ifdef LOCAL_JUDGE
  cerr << fixed << setprecision(3);
  cerr << "\n\nTime elapsed: " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" << flush;
#endif
} } __endder_of_program__;

template <typename T> using min_queue = priority_queue <T, vector <T>, greater <T> >;
template <typename T> using max_queue = priority_queue <T>;
#if __cplusplus <= 201403L
template <typename ...T> using void_t = void;
#endif
template <typename T> inline T chmax(T &x, T y) { return x = max(x, y); }
template <typename T> inline T chmin(T &x, T y) { return x = min(x, y); }
template <typename T> inline T chmax(T &x, initializer_list <T> i) { return x = max(x, max(i)); }
template <typename T> inline T chmin(T &x, initializer_list <T> i) { return x = min(x, min(i)); }
template <typename T> inline void reinit(T &t) { t.~T(); new (&t) T(); }
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
const double EPS = 1e-9, PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const ll lnf = 0x3f3f3f3f3f3f3f3f;

int n; ll ans;
ll a[200005], b[200005];

int main(int argc, const char *argv[]) {
  scanf("%d", &n);
  rep1(i, n) scanf("%lld", a + i);
  rep1(i, n) scanf("%lld", b + i);
  set <pli, greater <pli> > st;
  rep1(i, n) if (b[i] != a[i])
    st.insert({b[i], i});
  while (!st.empty()) {
    pii u = *st.begin();
    st.erase(st.begin());
    ll v = u.fi; int pos = u.se;
    int l = (pos == 1 ? n : pos - 1);
    int r = (pos == n ? 1 : pos + 1);
    ll sum = b[l] + b[r];
    ll dif = max({a[pos], b[l], b[r]});
    ll cnt = max((b[pos] - dif) / sum, 1LL);
    b[pos] -= sum * cnt, ans += cnt;
    if (b[pos] < a[pos]) return puts("-1") & 0;
    if (b[pos] != a[pos]) st.insert({b[pos], pos});
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 15872