import sequtils, strutils, math, algorithm var n = readLine(stdin).parseInt c = newSeq[int](n) d = newSeq[int](n) res:int for i in 0..