import strutils, sequtils proc readLine: auto = readLine stdin var a, b = newSeqWith(0, 0) even, odd: bool maxW, cnt = 0 let N = readLine().parseInt for i in 0 ..< N: let t = readLine().split.map parseInt a.add t[0] b.add t[1] case a[^1] mod 2: of 0: even = true else: odd = true if even and odd: echo -1 quit() maxW = max(maxW, a[^1] + 4 * b[^1]) for i in 0 ..< N: cnt += (maxW - a[i] - 4 * b[i]) div 2 echo cnt