use proconio::input; fn main() { input! { n:usize, a:[i64;n], b:[i64;n], } if n == 2 { let ans = if a[0] + a[1] == b[0] + b[1] { (a[0] - b[0]).abs() } else { -1 }; println!("{}", ans); return; } let sum_a = a.iter().sum::(); let sum_b = b.iter().sum::(); if sum_a < sum_b || (sum_a - sum_b) % (n - 2) as i64 != 0 { println!("-1"); return; } let m = (sum_a - sum_b) / (n - 2) as i64; let mut cnt = 0; for i in 0..n { if a[i] - m > b[i] || (b[i] - (a[i] - m)) % 2 != 0 { println!("-1"); return; } cnt += (b[i] - (a[i] - m)) / 2; } if cnt != m { println!("-1"); return; } let ans = m; println!("{}", ans); }