import sequtils, strscans, sugar let input = stdin.lines.toseq xs = newSeq.collect: for i, str in input: if i == 0: continue let (_, a, b) = str.scanTuple"$i $i" a + b * 4 max = max xs acc = xs.foldl(a + max.pred b, 0) echo: if (acc mod 2) == 0: acc div 2 else: -1