using System;
using System.Collections.Generic;

public class Program
{
    private int N;
    private int[] A, B;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.IntArray();
        B = sc.IntArray();

        // BからAに戻せるか?

        // i番目が発火 b[i] := b[i] -(b[i-1] + b[i+1])　a[i] > 0より　b[i] > b[i-1] + b[i+1]
        // i番目を発火して　上の式が成り立たないようにしないと b[i+-1]を発火できない
        // b[i] > b[i-1] + b[i+1] && B[i] > A[i]の間 b[i]を発火し続けて良い

        // b[i] > b[i-1] + b[i+1] && B[i] > A[i]を満たす B[i]
        var st = new Stack<int>();


        for (int i = 0; i < N; i++)
        {
            int prev = B[(i + N - 1) % N];
            int next = B[(i + 1) % N];
            if (B[i] > A[i] && B[i] > prev + next)
            {
                st.Push(i);
            }
        }

        long cnt = 0;

        while (st.Count > 0)
        {
            int s = st.Pop();
            int prev = (s + N - 1) % N;
            int next = (s + 1) % N;

            // b[i] <= b[i-1] + b[i+1] || B[i] == A[i] まで　発火し続ける
            int amari = B[s] % (B[prev] + B[next]);
            if (amari >= A[s])
            {
                cnt += B[s] / (B[prev] + B[next]);
                B[s] = amari;
            }
            else
            {
                int p = (B[s] - A[s]) / (B[prev] + B[next]);
                cnt += p;
                B[s] -= (B[prev] + B[next]) * p;
            }

            int prevprev = (s + N - 2) % N;
            int nextnext = (s + 2) % N;

            if (B[next] > A[next] && B[next] > B[nextnext] + B[s])
            {
                st.Push(next);
            }

            if (B[prev] > A[prev] && B[prev] > B[prevprev] + B[s])
            {
                st.Push(prev);
            }
        }

        for (int i = 0; i < N; i++)
        {
            if (A[i] != B[i])
            {
                Console.WriteLine(-1);
                return;
            }
        }
        Console.WriteLine(cnt);
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 47504