using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			long[] a = new long[n];
			long[] b = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = cin.Long();
			}

			for (int i = 0; i < n; i++) {
				b[i] = cin.Long();
			}

			var pq = new PriorityQueue<PriorityQueue<long>.Pair<int>>(n);
			for (int i = 0; i < n; i++) {
				pq.Push(new PriorityQueue<long>.Pair<int>(b[i], i));
			}

			long ans = 0;
			while (pq.Count > 0) {
				var target = pq.Pop();
				long prev = target.Value != 0 ? b[target.Value - 1] : b[n - 1];
				long next = target.Value != n - 1 ? b[target.Value + 1] : b[0];
				if (target.Priority >= prev && target.Priority >= next) {
					if (b[target.Value] > a[target.Value] && (prev + next) != 0) {
						long count = (b[target.Value] - a[target.Value]) / (prev + next);
						b[target.Value] -= (prev + next) * count;
						ans += count;

						if (b[target.Value] > a[target.Value] && count != 0) {
							pq.Push(new PriorityQueue<long>.Pair<int>(b[target.Value], target.Value));
						}
					}
				}
			}

			for (int i = 0; i < n; i++) {
				if (a[i] != b[i]) {
					Console.WriteLine(-1);
					return;
				}
			}

			Console.WriteLine(ans);
		}
	}

	public class PriorityQueue<T>
		where T : IComparable<T>
	{
		private readonly List<T> heap_;
		public bool Reverses { get; set; } = false;

		public T Top => heap_[0];
		public int Count => heap_.Count;

		public PriorityQueue(int capacity)
		{
			heap_ = new List<T>(capacity);
		}

		public void Push(T elem)
		{
			int n = heap_.Count;
			heap_.Add(elem);
			while (n > 0) {
				int i = (n - 1) >> 1;
				if (Compare(n, i) > 0) {
					Swap(i, n);
				} else {
					break;
				}

				n = i;
			}
		}
		public T Pop()
		{
			T ret = heap_[0];
			int n = heap_.Count - 1;
			heap_[0] = heap_[n];
			heap_.RemoveAt(n);
			for (int i = 0, j; (j = (i << 1) + 1) < n; i = j) {
				if (j != n - 1 && Compare(j, j + 1) < 0) {
					++j;
				}

				if (Compare(i, j) < 0) {
					Swap(i, j);
				} else {
					break;
				}
			}
			return ret;
		}

		private int Compare(int self, int target)
			=> heap_[self].CompareTo(heap_[target]) * (Reverses ? -1 : 1);
		private void Swap(int x, int y)
		{
			var t = heap_[x];
			heap_[x] = heap_[y];
			heap_[y] = t;
		}

		public struct Pair<U> : IComparable<Pair<U>>
		{
			public T Priority { get; set; }
			public U Value { get; set; }
			public Pair(T priority, U value)
			{
				Priority = priority;
				Value = value;
			}
			public int CompareTo(Pair<U> target)
				=> Priority.CompareTo(target.Priority);
			public override string ToString()
				=> $"{Priority} {Value}";
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;
		
		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

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

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

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

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 49088