fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut b = String::new(); std::io::stdin().read_line(&mut b).ok(); let b: Vec = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let diffs: Vec = b.iter().zip(a.iter()) .map(|ba| *ba.0 - *ba.1) .collect(); let count: isize = -1isize * diffs.iter().sum::(); let diffmax = diffs.iter().max().unwrap(); let diffmin = diffs.iter().min().unwrap(); if (n == 2 && count == 0isize) || (n > 2 && count % (n as isize - 2isize) == 0) { let count = if n > 2 { count / (n as isize - 2isize) } else { 0isize } ; if n == 2 { println!("{}", diffs[0].abs()); } else if diffmin.abs() <= count && diffmax.abs() <= count { println!("{}", count); } else { println!("-1"); } } else { println!("-1"); } }