import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;
	
	long[] as, bs;
	foreach(i; 0 .. n) as ~= read.to!long;
	foreach(i; 0 .. n) bs ~= read.to!long;
	
	X[] xs;
	foreach(i; 0 .. n) xs ~= new X(i, as[i], bs[i]);
	
	foreach(i; 0 .. n - 1){
		xs[i].next = xs[i + 1];
		xs[i + 1].prev = xs[i];
	}
	xs[n - 1].next = xs[0];
	xs[0].prev = xs[n - 1];
	
	auto xh = new RedBlackTree!(X, "a.isLargerThan(b)", true);
	
	foreach(x; xs){
		if(x.b > x.a && x.prev.a + x.next.a > x.b - x.a){
			"-1".writeln;
			return;
		}
		if(x.b > x.a){
			xh.insert(x);
		}
	}
	log("xh:", xh[], "xs:", xs);
	
	long ans = 0;
	while(xh.length > 0){
		X x = xh.front;
		xh.removeFront;
		long bsum = x.prev.b + x.next.b;
		long bmax = max(x.prev.b, x.next.b);
		if(bsum > x.b - x.a){
			"-1".writeln;
			return;
		}
		if(x.a >= bmax){
			if((x.b - x.a) % bsum == 0){
				ans += (x.b - x.a) / bsum;
				x.b = x.a;
			}
			else{
				"-1".writeln;
				return;
			}
		}
		else{
			long k = (x.b - bmax + bsum - 1) / bsum;
			long b2 = x.b - k * bsum;
			if(b2 < x.a){
				"-1".writeln;
				return;
			}
			else{
				ans += k;
				x.b = b2;
				if(x.a < x.b) xh.insert(x);
			}
		}
		log("xh:", xh[], "xs:", xs, "ans:", ans);
		
	}
	
	ans.writeln;
	
	
	
	

}

class X{
	int id;
	long a;
	long b;
	X prev, next;
	this(int id, long a, long b){
		this.id = id;
		this.a = a;
		this.b = b;
	}
	bool isLargerThan(X y){
		if(this.b > y.b) return 1;
		if(this.b < y.b) return 0;
		return this.id > y.id;
	}
	override string toString(){
		return b.to!string ~ "(" ~ a.to!string ~ ")";
	}
}
