#include <iostream>

using namespace std;
long long a[200010],b[200010],c[200010],cnt = 0;
int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	for(i=0;i<n;i++){
		cin >> b[i];
	}
	int k = 0;
	while(k<300){
		k++;
		for(i=0;i<n;i++){
			int l = i - 1,r = i + 1;
			if(l<0) l += n;
			if(r>=n) r -= n;
			long long x = b[l] + b[r];
			if(b[i]%x>=a[i]){
				c[i] = b[i]%(b[l] + b[r]);
				cnt += b[i]/(b[l] + b[r]);
			}else{
				if(b[i] < a[i]){
					cout << -1 << endl;
					return 0;
				}
				if((b[i] - a[i])%(b[l] + b[r])==0){
					c[i] = a[i];
					cnt += (b[i] - a[i])/(b[l] + b[r]);
				}
			}
		}
		bool flag = true;
		for(i=0;i<n;i++){
			b[i] = c[i];
			if(a[i]!=b[i]){
				flag = false;
			}
		}
		if(flag){
			cout << cnt << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}