from numpy.fft import rfft, irfft

import numpy as np



N, M = list(map(int, input().split()))

A = list(map(int, input().split()))



a = np.zeros(2 ** 18)

for Ai in A:

    a[Ai] += 1



fa = rfft(a)

a2 = irfft(fa ** 2)

a2 = np.round(a2).astype(np.int)



cum_a2 = np.cumsum(a2)



index = np.searchsorted(cum_a2, N ** 2 - M)



a2[index] -= cum_a2[index] - (N ** 2 - M)



ans = sum(A) * 2 * N - (a2[: index + 1] * np.arange(index + 1)).sum()

print(ans)

from numpy.fft import rfft, irfft

import numpy as np



N, M = list(map(int, input().split()))

A = list(map(int, input().split()))



a = np.bincount(A, minlength=2 ** 18)



fa = rfft(a)

a2 = irfft(fa ** 2)

a2 = np.round(a2).astype(np.int)



cum_a2 = np.cumsum(a2)



index = np.searchsorted(cum_a2, N ** 2 - M)



a2[index] -= cum_a2[index] - (N ** 2 - M)



ans = sum(A) * 2 * N - (a2[: index + 1] * np.arange(index + 1)).sum()

print(ans)

from numpy.fft import rfft, irfft
import numpy as np

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
a = np.zeros(2**18)
for Ai in A:
    a[Ai] += 1
fa = rfft(a)
a2 = irfft(fa**2)
a2 = np.round(a2).astype(np.int)
cum_a2 = np.cumsum(a2)
index = np.searchsorted(cum_a2, N**2 - M)
a2[index] -= cum_a2[index] - (N**2 - M)
ans = sum(A) * 2 * N - (a2[: index + 1] * np.arange(index + 1)).sum()
print(ans)

from numpy.fft import rfft, irfft
import numpy as np

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
a = np.bincount(A, minlength=2**18)
fa = rfft(a)
a2 = irfft(fa**2)
a2 = np.round(a2).astype(np.int)
cum_a2 = np.cumsum(a2)
index = np.searchsorted(cum_a2, N**2 - M)
a2[index] -= cum_a2[index] - (N**2 - M)
ans = sum(A) * 2 * N - (a2[: index + 1] * np.arange(index + 1)).sum()
print(ans)

-a = np.zeros(2**18) -for Ai in A: -    a[Ai] += 1 +a = np.bincount(A, minlength=2**18)