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::(); 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 { let has_irdata = b.iter().zip(a.iter()) .filter(|ba| (*ba.0 - *ba.1).abs() % 2 != count % 2) .count() > 0; let actualcount: isize = b.iter().zip(a.iter()) .map(|ba| *ba.0 - (*ba.1 - count)) .map(|i| i / 2) .sum() ; println!("{}", if has_irdata || actualcount != count { -1 } else { count }); } } else { println!("-1"); } }