import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    auto B = readln.split.map!(to!long).array;

    if (N.iota.map!(i => A[i] > B[i]).any) {
        writeln(-1);
        return;
    }

    auto pq = new BinaryHeap!(Array!(Tuple!(long, int)), "a[0] < b[0]");
    foreach (i; 0..N) pq.insert(tuple(B[i], i));
    long ans = 0;

    long prevv = -1;
    int previdx = -1;

    while (!pq.empty) {
        auto v = pq.front[0];
        auto idx = pq.front[1];
        pq.removeFront;

        if (v == prevv && idx == previdx) {
            writeln(-1);
            return;
        }

        prevv = v;
        previdx = idx;

        if (v < A[idx]) {
            writeln(-1);
            return;
        } else if (v == A[idx]) {
            continue;
        }

        auto left = (idx - 1+ N) % N;
        auto right = (idx + 1) % N;
        auto x = B[left] + B[right];

        if (v % x == A[idx] % x) {
            ans += (v - A[idx]) / x;
            B[idx] = A[idx];
            continue;
        }

        ans += B[idx] / x;
        B[idx] %= x;
        pq.insert(tuple(B[idx], idx));
    }

    ans.writeln;
}
