from scipy.signal import*

n,m,*a=list(map(int,open(0).read().split()))

b=[0]*2**17

for i in a:b[i]+=1

i=2**18-1

c=0

for a in(fftconvolve(b,b)+.5).astype(int)[::-1]:

  i-=1

  if a:

    t=min(m,a)

    c+=i*t

    m-=t

    if not m:break

print(c)
import cmath

pi = cmath.pi

exp = cmath.exp



N=2**18



def make_exp_t(N, base):

    exp_t = {0: 1}

    temp = N

    while temp:

        exp_t[temp] = exp(base / temp)

        temp >>= 1

    return exp_t



fft_exp_t = make_exp_t(N, -2j*pi)

ifft_exp_t = make_exp_t(N, 2j*pi)



def fft_dfs(f, s, N, st, exp_t):

    if N==2:

        a = f[s]; b = f[s+st]

        return [a+b, a-b]

    N2 = N//2; st2 = st*2

    F0 = fft_dfs(f, s   , N2, st2, exp_t)

    F1 = fft_dfs(f, s+st, N2, st2, exp_t)

    w = exp_t[N]; wk = 1.0

    for k in range(N2):

        U = F0[k]; V = wk * F1[k]

        F0[k] = U + V

        F1[k] = U - V

        wk *= w

    F0.extend(F1)

    return F0



def fft(f, N):

    if N==1:

        return f

    return fft_dfs(f, 0, N, 1, fft_exp_t)



def ifft(F, N):

    if N==1:

        return F

    f = fft_dfs(F, 0, N, 1, ifft_exp_t)

    for i in range(N):

        f[i] /= N

    return f



n,m,*a=list(map(int,open(0).read().split()))

b=[0]*N

for i in a:b[i]+=1

i=N

c=0

for a in ifft([t*t for t in fft(b,N)],N)[::-1]:

  a=int(a.real+.5)

  i-=1

  if a:

    t=min(m,a)

    c+=i*t

    m-=t

    if not m:break

print(c)
from scipy.signal import *

n, m, *a = list(map(int, open(0).read().split()))
b = [0] * 2**17
for i in a:
    b[i] += 1
i = 2**18 - 1
c = 0
for a in (fftconvolve(b, b) + 0.5).astype(int)[::-1]:
    i -= 1
    if a:
        t = min(m, a)
        c += i * t
        m -= t
        if not m:
            break
print(c)

import cmath

pi = cmath.pi
exp = cmath.exp
N = 2**18


def make_exp_t(N, base):
    exp_t = {0: 1}
    temp = N
    while temp:
        exp_t[temp] = exp(base / temp)
        temp >>= 1
    return exp_t


fft_exp_t = make_exp_t(N, -2j * pi)
ifft_exp_t = make_exp_t(N, 2j * pi)


def fft_dfs(f, s, N, st, exp_t):
    if N == 2:
        a = f[s]
        b = f[s + st]
        return [a + b, a - b]
    N2 = N // 2
    st2 = st * 2
    F0 = fft_dfs(f, s, N2, st2, exp_t)
    F1 = fft_dfs(f, s + st, N2, st2, exp_t)
    w = exp_t[N]
    wk = 1.0
    for k in range(N2):
        U = F0[k]
        V = wk * F1[k]
        F0[k] = U + V
        F1[k] = U - V
        wk *= w
    F0.extend(F1)
    return F0


def fft(f, N):
    if N == 1:
        return f
    return fft_dfs(f, 0, N, 1, fft_exp_t)


def ifft(F, N):
    if N == 1:
        return F
    f = fft_dfs(F, 0, N, 1, ifft_exp_t)
    for i in range(N):
        f[i] /= N
    return f


n, m, *a = list(map(int, open(0).read().split()))
b = [0] * N
for i in a:
    b[i] += 1
i = N
c = 0
for a in ifft([t * t for t in fft(b, N)], N)[::-1]:
    a = int(a.real + 0.5)
    i -= 1
    if a:
        t = min(m, a)
        c += i * t
        m -= t
        if not m:
            break
print(c)

-from scipy.signal import * +import cmath + +pi = cmath.pi +exp = cmath.exp +N = 2**18 + + +def make_exp_t(N, base): +    exp_t = {0: 1} +    temp = N +    while temp: +        exp_t[temp] = exp(base / temp) +        temp >>= 1 +    return exp_t + + +fft_exp_t = make_exp_t(N, -2j * pi) +ifft_exp_t = make_exp_t(N, 2j * pi) + + +def fft_dfs(f, s, N, st, exp_t): +    if N == 2: +        a = f[s] +        b = f[s + st] +        return [a + b, a - b] +    N2 = N // 2 +    st2 = st * 2 +    F0 = fft_dfs(f, s, N2, st2, exp_t) +    F1 = fft_dfs(f, s + st, N2, st2, exp_t) +    w = exp_t[N] +    wk = 1.0 +    for k in range(N2): +        U = F0[k] +        V = wk * F1[k] +        F0[k] = U + V +        F1[k] = U - V +        wk *= w +    F0.extend(F1) +    return F0 + + +def fft(f, N): +    if N == 1: +        return f +    return fft_dfs(f, 0, N, 1, fft_exp_t) + + +def ifft(F, N): +    if N == 1: +        return F +    f = fft_dfs(F, 0, N, 1, ifft_exp_t) +    for i in range(N): +        f[i] /= N +    return f + -b = [0] * 2**17 +b = [0] * N -i = 2**18 - 1 +i = N -for a in (fftconvolve(b, b) + 0.5).astype(int)[::-1]: +for a in ifft([t * t for t in fft(b, N)], N)[::-1]: +    a = int(a.real + 0.5)