use std::io::Read; fn main() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let v: Vec = s.split_whitespace().skip(1).flat_map(str::parse).collect(); let mut m = 0; let r: Vec = v .chunks(2) .map(|n| { let l = n[0] + 4 * n[1]; m = m.max(l); l }) .collect(); let mut t = 0; for r in r { if (m - r) % 2 != 0 { t = -1; break; } t += (m - r) / 2; } println!("{}", t) }