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();
			int[] a = new int[n];
			int[] b = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = cin.Int();
			}

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

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

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

						if (b[target] > a[target] && count != 0) {
							pq.Push(target);
						}
					}
				}
			}

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

			Console.WriteLine(ans);
		}
	}

	public class PriorityQueue<T>
	{
		private readonly List<T> heap_;
		private readonly Comparison<T> comparison_;
		public bool Reverses { get; set; } = false;

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

		public PriorityQueue() : this(Comparer<T>.Default) { }
		public PriorityQueue(int capacity) : this(capacity, Comparer<T>.Default.Compare) { }
		public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) { }
		public PriorityQueue(Comparison<T> comparison) : this(16, comparison) { }

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

		public void Push(T elem)
		{
			int n = heap_.Count;
			heap_.Add(elem);
			while (n > 0) {
				int i = (n - 1) >> 1;
				if (Compare(i, n) > 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 + 1, j) < 0) {
					++j;
				}

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

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

	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: 42796