#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a[200000],b[200000];
  int n;
  cin>>n;
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  bool flag=true;
  int ans=0;
  while(flag){
    flag=false;
    rep(i,n){
      if(b[(i+n-1)%n]+b[(i+1)%n] <= b[i]-a[i]){
	ans+=(b[i]-a[i])/(b[(i-1+n)%n]+b[(i+1)%n]);
	b[i]=((b[i]-a[i])%(b[(i-1+n)%n]+b[(i+1)%n]))+a[i];
	
	flag=true;
      }
    }
  }
  rep(i,n){
    if(a[i]!=b[i]){cout<<-1<<endl;return 0;}
  }
  //cout<<-1 % 3 <<endl;
  cout<<ans<<endl;
  return 0;
}