#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::complex;

long long min(long long a, long long b) {return a < b ? a : b;}
long long min(int a, long long b) {return a < b ? a : b;}
long long min(long long a, int b) {return a < b ? a : b;}
long long min(int a, int b) {return a < b ? a : b;}

long long max(long long a, long long b) {return a > b ? a : b;}
long long max(int a, long long b) {return a > b ? a : b;}
long long max(long long a, int b) {return a > b ? a : b;}
long long max(int a, int b) {return a > b ? a : b;}

#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;
typedef complex<double> cd;

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

const double PI = acos(-1);
const int N = (1 << 19);
const int MOD = 1e9 + 7;
const double eps = 1e-8;
const int K = 5;
const int LG = 19;

int n, M;
int bitreverse[N];

int Bitreverse(int x)
{
    int y = 0;
    for (int i = 0; i < LG; i++)
    {
        if ((1 << i) & x) y = 2 * y + 1;
        else y = 2 * y;
    }
    return y;
}

vector<cd> dft(vector<cd> a, int fl)
{
    vector<cd> b(N);
    for (int i = 0; i < N; i++) b[i] = a[bitreverse[i]];
    for (int len = 2; len <= N; len <<= 1)
    {
        double ang = 2 * PI / len * fl;
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < N; i += len)
        {
            cd w(1, 0);
            for (int j = 0; j < len / 2; j++)
            {
                cd v = b[i + j], u = b[i + j + len / 2] * w;
                b[i + j] = v + u;
                b[i + j + len / 2] = v - u;
                w = w * wlen;
            }
        }
    }
    return b;
}

vector<int> fft(vector<int> a, vector<int> b)
{
    vector<cd> A(N), B(N), C(N);
    for (int i = 0; i < N; i++) A[i].real(a[i]), B[i].real(b[i]);
    A = dft(A, 1), B = dft(B, 1);
    for (int i = 0; i < N; i++) C[i] = A[i] * B[i];
    C = dft(C, -1);
    vector<int> c(N);
    for (int i = 0; i < N; i++) c[i] = round(C[i].real() / N);
    return c;
}

signed main()
{
    for (int i = 0; i < N; i++) bitreverse[i] = Bitreverse(i);
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> M;
    vector<int> a(N);
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        a[x]++;
    }
    vector<int> b = fft(a, a);
    long long s = 0;
    for (int i = N - 1; i >= 0; i--)
    {
        if (b[i] <= M)
        {
            M -= b[i];
            s += b[i] * i;
        }
        else
        {
            s += M * i;
            M = 0;
        }
    }
    cout << s;
}


Measured memory_bytes: 66300