import sequtils,algorithm,math proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = var minus = false while true: var k = getchar_unlocked() if k == '-' : minus = true elif k < '0' or k > '9': break else: result = 10 * result + k.ord - '0'.ord if minus: result *= -1 let n = scan() var Y = newSeqWith(n,scan()) Y.sort(cmp) let mid = Y[n div 2] echo Y.foldl(a+abs(b-mid),0)