import java.util.Scanner object Problem178 { def proc(AB: Seq[(Int, Int)]): Long = { val width = AB.map(x => x._1 + x._2 * 4L) if (!width.forall(x => x % 2 == width.head % 2)) { return -1 } val maxWidth = width.max width.map(x => (maxWidth - x) / 2).sum } def main(args: Array[String]) { val sc = new Scanner(System.in) val N = sc.nextInt() val AB = Seq.fill(N)(sc.nextInt(), sc.nextInt()) val result = proc(AB) println(result) } }