import sequtils,math proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = while true: let k = getchar_unlocked() if k < '0': break result = 10 * result + k.ord - '0'.ord let n = scan() let A = newSeqWith(n,scan().float) proc calcCost(b,d:float):float = for i,a in A: let bi = b + d * i.float result += (a - bi)*(a - bi) let S = toSeq(0..