#include <stdio.h>
#include <queue>
using namespace std;
long long n;
long long a[200000];
long long b[200000];
long long s, t, x, y, z;
long long ans;
priority_queue<long long>q;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", a + i);
		s += a[i];
	}
	for (int i = 0; i < n; i++) {
		scanf("%lld", b + i);
		t += b[i];
		q.push(b[i] * n + i);
	}
	while (t > s) {
		if (q.empty())break;
		x = q.top();
		x %= n;
		if (b[x] == a[x]) {
			q.pop();
			continue;
		}
		if (b[x] - b[(x + n - 1) % n] - b[(x + 1) % n] < a[x])break;
		q.pop();
		y = b[(x + n - 1) % n] + b[(x + 1) % n];
		z = (b[x] - a[x]) / y;
		b[x] -= z * y;
		t -= z * y;
		ans += z;
		q.push(b[x] * n + x);
	}
	y = 1;
	for (int i = 0; i < n; i++) {
		if (a[i] != b[i])y = 0;
	}
	if (y)printf("%lld\n", ans);
	else printf("-1\n");
}