use std::io::Read; fn read() -> T { let token: String = std::io::stdin() .bytes() .map(|c| c.ok().unwrap() as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().unwrap() } fn main() { let n: i32 = read(); let a: Vec = (0..n).map(|_| read()).collect(); let b: Vec = (0..n).map(|_| read()).collect(); let d = a.iter().sum::() - b.iter().sum::(); if n == 2 { if d == 0 { println!("{}", (a[0] - b[0]).abs()); } else { println!("-1"); } return; } if d < 0 || d % (n - 2) != 0 { println!("-1"); return; } let k = d / (n - 2); let a2: Vec = a.iter().map(|x| x - k).collect(); let mut m = 0; for (a, b) in a2.iter().zip(b.iter()) { if a > b { println!("-1"); return; } m += (b - a) / 2; } if m <= k { println!("{}", k); } else { println!("-1"); } }