#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

typedef long long LL;

const int maxn=2e5+5;

struct QST{
	int i,b;
};
bool operator < (const QST &a,const QST &b) {return a.b<b.b;}

int n,a[maxn],b[maxn];
priority_queue<QST> Q;

int main()
{
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	fo(i,1,n) scanf("%d",&b[i]);
	
	fo(i,1,n) Q.push((QST){i,b[i]});
	LL ans=0;
	while (!Q.empty())
	{
		QST tp=Q.top(); Q.pop();
		int i=tp.i;
		if (b[i]>a[i] && b[i]>=b[i%n+1]+b[(i==1)?n:i-1])
		{
			int sum=b[i%n+1]+b[(i==1)?n:i-1];
			if (a[i]>=b[i]%sum && (b[i]-a[i])%sum!=0) {ans=-1; break;}
			int d=min(b[i]-a[i],b[i]-b[i]%sum);
			b[i]-=d;
			ans+=d/sum;
			Q.push((QST){i,b[i]});
		}
	}
	fo(i,1,n) if (a[i]!=b[i]) {ans=-1; break;}
	
	printf("%lld\n",ans);
}