output_description: Print the maximum possible happiness after M handshakes.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      A_1 A_2 ... A_N
attempt: def modinv(x, mod):
      a, b = x, mod
      u, v = 1, 0
      while b:
          t = a // b
          a -= t * b
          a, b = b, a
          u -= t * v
          u, v = v, u
      return u % mod
  
  
  def _garner(xs, mods):
      M = len(xs)
      coeffs = [1] * M
      constants = [0] * M
      for i in range(M - 1):
          mod_i = mods[i]
          v = (xs[i] - constants[i]) * modinv(coeffs[i], mod_i) % mod_i
          for j in range(i + 1, M):
              mod_j = mods[j]
              constants[j] = (constants[j] + coeffs[j] * v) % mod_j
              coeffs[j] = (coeffs[j] * mod_i) % mod_j
  
      return constants[-1]
  
  
  def bit_reverse(d):
      n = len(d)
      ns = n >> 1
      nss = ns >> 1
      ns1 = ns + 1
      i = 0
      for j in range(0, ns, 2):
          if j < i:
              d[i], d[j] = d[j], d[i]
              d[i + ns1], d[j + ns1] = d[j + ns1], d[i + ns1]
          d[i + 1], d[j + ns] = d[j + ns], d[i + 1]
          k = nss
          i ^= k
          while k > i:
              k >>= 1
              i ^= k
      return d
  
  
  class NTT:
      def __init__(self, mod, primitive_root):
          self.mod = mod
          self.root = primitive_root
  
      def _ntt(self, a, sign):
          n = len(a)
          mod, g = self.mod, self.root
          tmp = (mod - 1) * modinv(n, mod) % mod  # -1/n
          h = pow(g, tmp, mod)  # ^n√g
          if sign < 0:
              h = modinv(h, mod)
  
          a = bit_reverse(a)
  
          m = 1
          while m < n:
              m2 = m << 1
              _base = pow(h, n // m2, mod)
              _w = 1
              for x in range(m):
                  for s in range(x, n, m2):
                      u = a[s]
                      d = a[s + m] * _w % mod
                      a[s] = (u + d) % mod
                      a[s + m] = (u - d) % mod
                  _w = _w * _base % mod
              m <<= 1
          return a
  
      def ntt(self, a):
          return self._ntt(a, 1)
  
      def intt(self, a):
          mod = self.mod
          n = len(a)
          n_inv = modinv(n, mod)
          a = self._ntt(a, -1)
          for i in range(n):
              a[i] = a[i] * n_inv % mod
          return a
  
      def convolution(self, a, b):
          mod = self.mod
          ret_size = len(a) + len(b) - 1
          n = 1 << (ret_size - 1).bit_length()
          _a = a + [0] * (n - len(a))
          _b = b + [0] * (n - len(b))
          _a = self.ntt(_a)
          _b = self.ntt(_b)
          _a = [x * y % mod for x, y in zip(_a, _b)]
          _a = self.intt(_a)
          _a = _a[:ret_size]
          return _a
  
  
  def convolution_ntt(a, b):
      mods = (1224736769,)
      ntt1 = NTT(mods[0], 3)
      x1 = ntt1.convolution(a, b)
      return x1
  
  
  m, k = map(int, input().split())
  f = list(map(int, input().split()))
  n = max(f) + 1
  g = [0] * n
  for x in f:
      g[x] += 1
  h = convolution_ntt(g, g)
  ans = 0
  cnt = 0
  for i in range(len(h) - 1, -1, -1):
      if cnt + h[i] < k:
          ans += h[i] * i
          cnt += h[i]
      else:
          ans += (k - cnt) * i
          break
  print(ans)
  
problem_description: Statement
  
  Takahashi has come to a party as a special guest. There are N ordinary guests
  at the party. The i-th ordinary guest has a _power_ of A_i.
  
  Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of
  the party (let the current happiness be 0). A handshake will be performed as
  follows:
  
    * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same).
    * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y.
  
  However, Takahashi should not perform the same handshake more than once.
  Formally, the following condition must hold:
  
    * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q).
  
  What is the maximum possible happiness after M handshakes?
samples: [{"input": "5 3\n    10 14 19 34 33", "output": "202\n    \n\nLet us say that Takahashi performs the following handshakes:\n\n  * In the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.\n  * In the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.\n  * In the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.\n\nThen, we will have the happiness of (34+34)+(34+33)+(33+34)=202.\n\nWe cannot achieve the happiness of 203 or greater, so the answer is 202.\n\n* * *"}, {"input": "9 14\n    1 3 5 110 24 21 34 5 3", "output": "1837\n    \n\n* * *"}, {"input": "9 73\n    67597 52981 5828 66249 75177 64141 40773 79105 16076", "output": "8128170"}]