import java.util.*
fun main(arg: Array<String>) {
    val N = nextInt()
    val A = listOfLong()
    val B = listOfLong().toLongArray()
    var P = PriorityQueue<Pair<Long, Int>>(N, Comparator { a, b ->  b.first.compareTo(a.first) })
    B.forEachIndexed { index, value ->  if (A[index] != value) P.add(Pair(value, index))}
    var ans = 0L
    while (!P.isEmpty()) {
        val p = P.poll()
        val at = p.second
        val lr = B[(N + at - 1) % N] + B[(N + at + 1) % N]
        if (B[at] - A[at] < lr) {
            ans = -1
            break
        }
        val t = (B[at] - A[at]) / lr
        B[at] -= lr * t
        ans += t
        if (A[at] != B[at]) P.add(Pair(B[at], at)) }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { it.toLong() }
