# @author godmar # my guess here would be that the k numbers are consecutive when sorted n, k = map(int, input().split()) x = [int(input()) for i in range(n)] x.sort() S_X = sum(x[:k]) S_X2 = sum(_x*_x for _x in x[:k]) badness = S_X2 - S_X * S_X/k for i in range(k, n): S_X2 += -x[i-k] * x[i-k] + x[i] * x[i] S_X += -x[i-k] + x[i] badness = min(badness, S_X2 - S_X * S_X/k) print (badness)