module efft;

import std.algorithm, std.array, std.conv, std.range, std.stdio, std.string;
void main()
{
    auto buf = readln.chomp.split.to!(int[]);
    solve(buf[1], readln.chomp.split.to!(int[])).writeln;
}
long solve(int m, int[] powers)
{
    import std.complex, std.math, std.numeric;
    auto a = new Complex!double[size_t(1) << 18];
    a[] = complex(0);
    foreach (p; powers)
        a[p] += complex(1);
    a = a.fft;
    a[] *= a[];
    a = a.inverseFft;
    long ret = 0;
    foreach_reverse (p, _n; a)
    {
        auto n = _n.re.round.to!long;
        if (!n) continue;
        stderr.writefln("happiness=%d handshakes=%d", p, n);
        ret += p * min(n, m);
        m -= min(n, m);
    }
    return ret;
}
unittest
{
    assert (solve(3, [10, 14, 19, 34, 33]) == 202);
    assert (solve(14, [1, 3, 5, 110, 24, 21, 34, 5, 3]) == 1837);
    assert (solve(73, [67597, 52981, 5828, 66249, 75177, 64141, 40773, 79105, 16076]) == 8128170);
    stderr.writefln("unittest passed!");
}
