import java.lang.Math.*
import java.util.*

private fun readln() = readLine()!!.trim()
private fun readlnInt() = readln().toInt()
private fun readlnStrings() = readln().split(' ')
private fun readlnInts() = readlnStrings().map { it.toInt() }
private fun readlnLongs() = readlnStrings().map { it.toLong() }


fun solve() {
    val N = readlnInt()
    val A = readlnInts()
    val B = readlnInts().toMutableList()
    val pq = PriorityQueue<Int>(N) {a:Int, b:Int -> B[b] - B[a]}
    (0 until N).filter { B[it] > A[it] }.toCollection(pq)
    var ttl = 0L
    while (pq.isNotEmpty()){
        val i = pq.poll()!!
        val iP = (i+1)%N
        val iN = (i-1+N)%N
        val step = B[iP] + B[iN]
        if (B[i] - A[i] < step){
            println(-1)
            return
        } else {
            val p = (B[i] - A[i]) / step
            B[i] -= p * step
            ttl += p
            if (B[i] > A[i]){
                pq.add(i)
            }
        }
    }
    if ((0 until N).all{B[it] == A[it]}){
        println(ttl)
    } else {
        println(-1)
    }
}


fun main(args: Array<String>) {
//    val queryNum = readlnInt()
//    for (queryIdx in 1..queryNum) {
//        println("Case #$queryIdx:")
    solve()
//    }
}