fn main() { let n: usize = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf.trim_end().parse().unwrap() }; let a: Vec = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let iter = buf.split_whitespace(); iter.map(|x| x.parse().unwrap()).collect() }; let b: Vec = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let iter = buf.split_whitespace(); iter.map(|x| x.parse().unwrap()).collect() }; let mut c = vec![0; n]; for i in 0..n { c[i] = a[i] - b[i]; } c.sort(); let mut sum = 0; for i in (0..(n - 1)).rev() { c[i] -= sum; let x = c[i + 1] - c[i]; if x % 2 == 0 { c[i] = (c[i] + c[i + 1]) / 2; sum += x / 2; } else { println!("-1"); return; } } if c[0] == 0 { println!("{}", sum); } else { println!("-1"); } }