#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())

typedef long long ll;

const int n = 2e5+10;

int N;
ll A[n], B[n];

int main(){
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	for(int i=0; i<N; i++){
		cin >> B[i];
	}
	ll cnt = 0;
	while(true){
		bool f = true;
		bool changed = false;
		for(int i=0; i<N; i++){
			ll sum = B[(i+N-1)%N]+B[(i+1)%N];
			if(B[i] >= sum){
				if((B[i]-A[i]) % sum == 0){
					cnt += (B[i]-A[i])/sum;
					if(B[i] != A[i])
						changed = true;
					B[i] = A[i];
				}
				else{
					cnt += B[i]/sum;
					changed = true;
					B[i] %= sum;
				}
				if(B[i] < A[i]){
					cout << -1 << endl;
					return 0;
				}
			}
			if(B[i] != A[i])
				f = false;
		}
		if(f){
			cout << cnt << endl;
			break;
		}
		if(!changed){
			cout << -1 << endl;
			break;
		}
	}

  return 0;
}
