#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N;
    vector<ll> A;
    vector<ll> B;

    void solve() {
        cin >> N;
        A.resize(N);
        B.resize(N);
        for (int i = 0; i < N; ++i) {
            cin >> A[i];
        }
        for (int i = 0; i < N; ++i) {
            cin >> B[i];
        }

        ll cnt = 0;
        int lp = 0;
        bool rv = false;
        while (true) {
            lp++;
            bool del = false; // 消せるものがあるか
            bool ok = true; // クリア条件満たしているか
            for (int j = 0; j < N; ++j) {
                int i = j;
                if (rv) {
                    i = N - 1 - j;
                }
                if (A[i] != B[i]) {
                    ok = false;
                    if (A[i] > B[i]) {
                        cout << -1 << endl;
                        return;
                    } else {
                        int a = i;
                        int l = (a - 1 + N) % N;
                        int r = (a + 1) % N;
                        if (B[i] - B[l] - B[r] >= A[i]) {
                            ll div = (B[i] - A[i]) / (B[l] + B[r]);
                            B[i] -= div * (B[l] + B[r]);
                            cnt += div;
                            if (div > 0) del = true;
                        }
                    }
                }
            }
            rv = !rv;
            if (ok) {
                cout << cnt << endl;
                cerr << lp << endl;
                return;
            }
            if (!del) {
                cout << -1 << endl;
                return;
            }
        }


//        jikken();

    }

    void jikken() {
        while (true) {
            for (int i = 0; i < N; ++i) {
                cout << B[i] << " ";
            }
            cout << endl;

            int a;
            cin >> a;
            if (a == -1) break;
            int l = (a - 1 + N) % N;
            int r = (a + 1) % N;
            B[a] -= (B[l] + B[r]);
        }
    }

};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 3328