You are given N positive integers arranged in a circle. Takahashi wants to transform the i-th number to a specific value B_i. He can repeatedly choose an integer i and replace the i-th number with the sum of its adjacent numbers. Determine if Takahashi can achieve his objective and find the minimum number of operations required. Constraints: 3 ≤ N ≤ 2 × 10^5, 1 ≤ A_i, B_i ≤ 10^9. Input format: N, followed by A_i values, followed by B_i values. Output the minimum number of operations required or -1 if the objective cannot be achieved. Example: Input: 3, 1 1 1, 13 5 7. Output: 4. Takahashi can achieve his objective in 4 operations.

# Buggy version:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


n = I()
A = LI()
B = LI()
q = [(-B[i], i) for i in range(n)]
ans = 0
while q:
    a, idx = heappop(q)
    a = -a
    if A[idx] == a:
        continue
    b = B[(idx-1)%n] + B[(idx+1)%n]
    ans += a // b
    ax = a % b
    B[idx] = ax
    if ax < A[idx]:
        print(-1)
        exit()
    elif ax == A[idx]:
        continue
    else:
        heappush(q, (-ax, idx))

print(ans)









# Fixed version:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, acos, asin, atan, sqrt, tan, cos, pi
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


n = I()
A = LI()
B = LI()
q = [(-B[i], i) for i in range(n)]
heapify(q)
ans = 0
while q:
    _, idx = heappop(q)
    if A[idx] == B[idx]:
        continue
    total = B[(idx-1)%n] + B[(idx+1)%n]
    t = (B[idx] - A[idx]) // total
    B[idx] -= t * total
    if not t:
        print(-1)
        exit()
    ans += t
    heappush(q, (-B[idx], idx))

print(ans)

# Buggy version:
n = int(input())
b = list(map(int,input().split()))
a = list(map(int,input().split()))
lock = [0]*n

ans = 0
top = []
for i in range(n):
  if a[i] > b[i]:
    print(-1)
    exit()
  if a[i] == b[i]:
    lock[i] = 1
    continue
  if a[i-1]+a[(i+1)%n]<a[i]:
    top.append(i)
while True:
  while top:
    x = top.pop()
    ne = a[x-1]+a[(x+1)%n]
    if (a[x]-b[x])%ne == 0:
      ans += (a[x]-b[x])//ne
      lock[x] = 1
      a[x] = b[x]
    else:
      ans += a[x]//ne
      a[x] %= ne
    for i in (x+1,x-1):
      if a[i-1]+a[(i+1)%n]<a[i%n]:
        top.append(i%n)
  if lock.count(1) == n:
    print(ans)
    exit()
  elif not top:
    print(-1)
    exit()

# Fixed version:
n = int(input())
b = list(map(int,input().split()))
a = list(map(int,input().split()))
lock = [0]*n

ans = 0
top = []
for i in range(n):
  if a[i] < b[i]:
    print(-1)
    exit()
  if a[i] == b[i]:
    lock[i] = 1
    continue
  if a[i-1]+a[(i+1)%n]<a[i]:
    top.append(i)
while True:
  while top:
    x = top.pop()
    ne = a[x-1]+a[(x+1)%n]
    if (a[x]-b[x])%ne == 0:
      ans += (a[x]-b[x])//ne
      lock[x] = 1
      a[x] = b[x]
    else:
      ans += a[x]//ne
      a[x] %= ne
    for i in (x+1,x-1):
      if a[i-1]+a[(i+1)%n]<a[i%n]:
        top.append(i%n)
  if lock.count(1) == n:
    print(ans)
    exit()
  elif not top:
    print(-1)
    exit()

# Buggy version:
import sys
from heapq import heappush as hpu
from heapq import heappop as hpo
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

base = 10 ** 10
sb = [(-b[i], i) for i in range(N) if a[i] != b[i]]
h = []
hpu = lambda x: hpu(h, x)
for t in sb: hpu(t)
res = 0
while len(h):
  v, i = hpo(h)
  v = -v
  if v < a[i]:
    print(-1)
    exit(0)
  d = v - a[i]
  x = b[i - 1] + b[(i + 1) % N]
  t = d // x
  if t == 0:
    if v == a[i]: continue
    print(-1)
    exit(0)
  b[i] -= x * (t)
  res += t
  hpu((-b[i], i))
print(res)


# Fixed version:
import sys
from heapq import heappush as hpu
from heapq import heappop as hpo
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

base = 10 ** 6
sb = [-(b[i] * base + i) for i in range(N) if a[i] != b[i]]
h = []
for t in sb: hpu(h, t)
res = 0
while len(h):
  v = hpo(h)
  i = -v % base
  v = -v // base
  if v < a[i]:
    print(-1)
    exit(0)
  d = v - a[i]
  x = b[i - 1] + b[(i + 1) % N]
  t = d // x
  if t == 0:
    if v == a[i]: continue
    print(-1)
    exit(0)
  b[i] -= x * (t)
  res += t
  hpu(h, -(b[i] * base + i))
print(res)

# Buggy version:
import sys
from heapq import heappop as hpp, heappush as hp

readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

geta = 10**6        
Q = [-(B[i]*geta+i) for i in range(N)] + [0]
Q.sort()

ans = 0
cnt = 0
inf = 10**9+7
while cnt < N:
    b, idx = divmod(-hpp(Q), geta)
    a = A[idx]
    if b < a:
        ans = -1
        break
    bside = B[(idx+1)%N] + B[(idx-1)%N]
    kb = 1+(b-bside)//bside
    ka = (b-a)//bside
    k = min(ka, kb)
    B[idx] -= k*bside
    ans += k
    if B[idx] == a:
        cnt += 1
    elif k == 0:
        ans = -1
        break
    else:
        hp(Q, -(B[idx]*geta+idx))

# Fixed version:
import sys
from heapq import heappop as hpp, heappush as hp

readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

geta = 10**6        
Q = [-(B[i]*geta+i) for i in range(N)] + [0]
Q.sort()

ans = 0
cnt = 0
inf = 10**9+7
while cnt < N:
    b, idx = divmod(-hpp(Q), geta)
    a = A[idx]
    if b < a:
        ans = -1
        break
    bside = B[(idx+1)%N] + B[(idx-1)%N]
    kb = 1+(b-bside)//bside
    ka = (b-a)//bside
    k = min(ka, kb)
    B[idx] -= k*bside
    ans += k
    if B[idx] == a:
        cnt += 1
    elif k == 0:
        ans = -1
        break
    else:
        hp(Q, -(B[idx]*geta+idx))
print(ans)

# Buggy version:
import heapq
n = int(input())
a = tuple(map(int,input().split()))
b = list(map(int,input().split()))

le = 10**6

tank = []
for i,e in enumerate(b):
    heapq.heappush(tank,-e*le-i)

res = 0
while len(tank):
    p = -heapq.heappop(tank)
    ele = p//le
    ind = p%le
    if ele == a[ind]:
        continue
    elif ele < a[ind]:
        print(-1)
        exit()
    if ind == n-1:
        w = b[ind-1] + b[0]
    else:
        w = b[ind-1] + b[ind+1]
    res += ele//w
    ele = ele%w
    b[ind] = ele
    heapq.heappush(tank,-ele*le-ind)

print(res)

# Fixed version:
import heapq,sys
input = sys.stdin.readline

n = int(input())
a = tuple(map(int,input().split()))
b = list(map(int,input().split()))
le = 10**6

tank = []
for i,e in enumerate(b):
    heapq.heappush(tank,-e*le-i)

res = 0
while len(tank):
    p = -heapq.heappop(tank)

    ele = p//le
    ind = p%le

    if ele == a[ind]:
        continue
    elif ele < a[ind]:
        print(-1)
        exit()

    if ind == n-1:
        w = b[ind-1] + b[0]
    elif ind == 0:
        w = b[-1] + b[1]
    else:
        w = b[ind-1] + b[ind+1]
    
    q = (ele-a[ind])//w
    if q == 0:
        print(-1)
        exit()
    res += q
    ele -= q*w
    b[ind] = ele
    heapq.heappush(tank,-ele*le-ind)

print(res)

# Buggy version:
# c
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, c = B[i-1], B[(i+1)%n]
        if (B[i] > A[i]) &\
           (B[i] > a) &\
           (B[i] > c):
            B[i] -= (a+c)*((B[i]-A[i]+a+c)//(a+c))
            cnt += 1
        elif B[i] < A[i]:
            print(-1)
            exit()
print(cnt)

# Fixed version:
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, c = B[i-1], B[(i+1)%n]
        if (B[i] > A[i]) &\
           (B[i] > a) &\
           (B[i] > c):
            d = (B[i]-max(A[i], a, c)+a+c-1)//(a+c)
            B[i] -= (a+c)*d
            cnt += d
        elif B[i] < A[i]:
            print(-1)
            exit()
print(cnt)

# Buggy version:
import heapq

n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
q=[]
for i in range(n):
  heapq.heappush(q,(-arr2[i],i))
cnt=0
num=0
while 1:
  val,pos=-heapq.heappop(q)
  diff=arr2[pos-1]+arr2[(pos+1)%n]
  move=(val-diff)//diff+1
  if move<=0:
    break
  tmp=arr2[pos]-diff*move
  if tmp<=0:
    break
  arr2[pos]=tmp
  heapq.heappush(q,-tmp)
  if tmp==arr1[pos]:
    num+=1
  cnt+=move
  if num==n:
    break
for i in range(n):
  if arr1[i]!=arr2[i]:
    print(-1)
    break
else:
  print(cnt)

# Fixed version:
import heapq

n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
q=[]
for i in range(n):
  if arr2[i]!=arr1[i]:
    heapq.heappush(q,(-arr2[i],i))
cnt=0
while q:
  val,pos=heapq.heappop(q)
  val*=-1
  diff=arr2[pos-1]+arr2[(pos+1)%n]
  move,tmp=divmod(val-arr1[pos],diff)
  if move==0:
    break
  cnt+=move
  tmp+=arr1[pos]
  arr2[pos]=tmp
  if tmp!=arr1[pos]:
    heapq.heappush(q,(-tmp,pos))
for i in range(n):
  if arr1[i]!=arr2[i]:
    print(-1)
    break
else:
  print(cnt)

# Buggy version:
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]

from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]

for i,b in enumerate(B):
  push(b,i)

ans=0
while BB:
  b,ind=heappop(BB)
  b,ai=-b,A[ind]
  if b<ai:
    ans=-1
    break
  if ind==0:
    d=B[1]+B[-1]
  elif ind==n-1:
    d=B[-2]+B[0]
  else:
    d=B[ind-1]+B[ind+1)]
  dd=(b-ai)//d
  if dd==0:
    if b==ai:
      continue
    ans=-1
    break
  ans+=dd
  B[ind]-=d*dd
  push(B[ind],ind)
  
print(ans)


# Fixed version:
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]

from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]

for i,b in enumerate(B):
  push(b,i)

ans=0
while BB:
  b,ind=heappop(BB)
  b,ai=-b,A[ind]
  if b<ai:
    ans=-1
    break
  d=B[(ind-1)%n]+B[(ind+1)%n]
  dd=(b-ai)//d
  if dd==0:
    if b==ai:
      continue
    ans=-1
    break
  ans+=dd
  B[ind]-=d*dd
  push(b-d*dd,ind)
  
print(ans)