#include<bits/stdc++.h>
using namespace std;
#define N 200005
#define LL long long
#define pii pair<int,int>
#define mp make_pair

int n,ci;
LL ans;
int a[N],b[N];
priority_queue<pii> q;

int main()
{
	ios_base::sync_with_stdio(0);
	
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>b[i];
	for(int i=0;i<n;i++)
		q.push(mp(b[i],i));
	while(!q.empty())
	{
		ci++;
		if(ci>=1e7) return cout<<"-1\n",0;
		int x=q.top().second;
		q.pop();
		if(b[x]==a[x]) continue;
		int pa,pb;
		if(x) pa=b[x-1];
		else pa=b[n-1];
		if(x!=n-1) pb=b[x+1];
		else pb=b[0];
		if(max(max(pa,pb),a[x])+pa+pb<b[x])
		{
			ans+=(b[x]-max(max(pa,pb),a[x]))/(pa+pb);
			b[x]-=(b[x]-max(max(pa,pb),a[x]))/(pa+pb)*(pa+pb);
		}
		else b[x]-=pa+pb,ans++;
		if(b[x]<a[x]) return cout<<"-1\n",0;
		q.push(mp(b[x],x));
	}
	cout<<ans<<'\n';
	
	return 0;
}