use proconio::input; fn main() { input! { n:usize, a:[i64;n], b:[i64;n], } if n == 2 { let ans = if a[0] - b[0] + a[1] - b[1] == 0 { (a[0] - b[0]).abs() } else { -1 }; println!("{}", ans); return; } let a_sum = a.iter().sum::(); let b_sum = b.iter().sum::(); let f1 = (0..n).all(|i| (a[i] - b[i]).abs() % 2 == (a[0] - b[0]).abs() % 2); let f2 = a_sum >= b_sum; let f3 = (a_sum - b_sum) % (n - 2) as i64 == 0; let f4 = (0..n).all(|i| (a[i] - b[i]).abs() <= (a_sum - b_sum) / (n - 2) as i64); let ans = if f1 && f2 && f3 && f4 { (a_sum - b_sum) / (n - 2) as i64 } else { -1 }; println!("{}", ans); }