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 ans = { if n == 2 { let x = c[1] - c[0]; if x % 2 == 0 { x / 2 } else { -1 } } else { if (2..(n - 1)).fold(true, |acc, i| acc && c[i] == c[i + 1]) { let x = c[2] - c[1]; if x % 2 == 0 { let y = (c[2] + c[1]) / 2 - (c[0] - x / 2); if y % 2 == 0 { x / 2 + y / 2 } else { -1 } } else { -1 } } else { -1 } } }; println!("{}", ans); }