local n, m = io.read("*n", "*n") local a = {} for i = 1, n do a[i] = io.read("*n") end table.sort(a) local v = 0LL for i = 2, m do v = v + 1LL * (a[i] - a[i - 1]) * (a[i] - a[i - 1]) end local ans = v for i = m + 1, n do v = v - 1LL * (a[i - m + 1] - a[i - m]) * (a[i - m + 1] - a[i - m]) v = v + 1LL * (a[i] - a[i - 1]) * (a[i] - a[i - 1]) if v < ans then ans = v end end ans = tostring(ans):gsub("LL", "") print(ans)