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: count = 0
  res = 0
  M = 0
  
  
  class Node:
      def __init__(self, data):
          self.data = data
          self.left = None
          self.right = None
  
  
  class BST:
      def __init__(self, number_list):
          self.root = None
          for node in number_list:
              self.insert(node)
  
      def insert(self, data):
          n = self.root
          if n == None:
              self.root = Node(data)
              return
          else:
              while True:
                  entry = n.data
                  if data < entry:
                      if n.left is None:
                          n.left = Node(data)
                          return
                      n = n.left
                  elif data >= entry:
                      if n.right is None:
                          n.right = Node(data)
                          return
                      n = n.right
                  else:
                      n.data = data
                      return
  
      def printTree(self, node):
          if node.left == None:
              print("N-", end="")
          else:
              print("%d-" % (node.left.data), end="")
          print(node.data, end="")
          if node.right == None:
              print("-N")
          else:
              print("-%d" % (node.right.data))
          if node.left != None:
              self.printTree(node.left)
          if node.right != None:
              self.printTree(node.right)
  
      def inorder(self, node):
          if node is not None:
              self.inorder(node.left)
              print(node.data)
              self.inorder(node.right)
  
      def order(self, node):
          global res
          global count
          global M
          if node is not None:
              self.order(node.right)
              res += node.data
              count += 1
              if count == M:
                  print(res)
                  exit()
              #      print(node.data)
              self.order(node.left)
  
  
  args = input().split()
  N = int(args[0])
  M = int(args[1])
  A = list(map(int, input().split()))
  sumA = []
  for i in range(len(A) - 1):
      for j in range(i, len(A)):
          if i == j:
              sumA.append(A[i] + A[j])
          else:
              sumA.append(A[i] + A[j])
              sumA.append(A[i] + A[j])
  A = []
  tree = BST(sumA)
  sumA = []
  tree.order(tree.root)
  
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"}]