import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

alias X = Tuple!(int, "i", long, "a", long, "b", long, "c");

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(long[]);
    auto BS = readln.split.to!(long[]);

    X[] xs;
    foreach (i; 0..N) {
        auto j = (i+N-1)%N;
        auto k = (i+1)%N;
        xs ~= X(i, BS[j], BS[i], BS[k]);
    }
    auto rbt = redBlackTree!((a, b) => (BS[a.i] > AS[a.i]) != (BS[b.i] > AS[b.i]) ? BS[a.i] > AS[a.i] : (a.b > a.a + a.c) != (b.b > b.a + b.c) ? a.b > a.a + a.c : a.b > b.b)(xs);
    long res;
    for (;;) {
        auto h = rbt.front;
        rbt.removeFront();
        with (h) {
            auto j = (h.i+N-1)%N;
            auto k = (h.i+1)%N;
            auto f = X(j, BS[(j+N-1)%N], a, b);
            auto r = X(k, b, c, BS[(k+1)%N]);
            rbt.removeKey(f, r);
            auto n = b - AS[i];
            if (n < 0 || n/(a+c) == 0) break;
            res += n/(a+c);
            b = AS[i] + n%(a+c);
            BS[i] = b;
            h.b = b;
            f.c = b;
            r.a = b;
            rbt.insert(h);
            rbt.insert(f);
            rbt.insert(r);
        }
    }
    foreach (i; 0..N) if (AS[i] != BS[i]) {
        writeln(-1);
        return;
    }
    writeln(res);
}