import std.algorithm;
import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

long solve (int n, int [] a, int [] b)
{
	alias Pair = Tuple !(int, q{val}, int, q{pos});
	auto t = redBlackTree !(Pair);
	foreach (i; 0..n)
	{
		if (b[i] != a[i])
		{
			t.insert (Pair (b[i], i));
		}
	}
	long res = 0;
	while (!t.empty)
	{
		auto i = t.back.pos;
		t.removeBack ();
		auto sub = b[(i + n - 1) % n] + b[(i + 1) % n];
		if (b[i] - sub < a[i])
		{
			return -1;
		}
		auto steps = (b[i] - a[i]) / sub;
		res += steps;
		b[i] -= steps * sub;
		if (b[i] > a[i])
		{
			t.insert (Pair (b[i], i));
		}
	}
	return res;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto b = readln.splitter.map !(to !(int)).array;
		writeln (solve (n, a, b));
	}
}
