import Data.Array
import Data.List 

main = print =<< sol <$> get <*> get

get = fmap read . words <$> getLine

sol [n,m] as = s + (m-c)*lvl
  where
  a = listArray (1,n) $ sortBy (flip compare) as
  fnd a x = bsearch (0,n) ((x <=) . (a!))
  cnt a x = sum $ fnd a . (-) x <$> elems a
  lvl = bsearch (2*a!n,2*a!1) ((m <=) . cnt a)
  i = fnd a (lvl - a!1)
  acc = array (1,n) $ (1,a!1):[(i,a!i + acc!(i-1)) | i <- [2..n]]
  (c,s) = foldl' upd (0,0) [1..i]
  upd (c,s) i = (c+j, s + j*(a!i) + acc!j)
    where j = fnd a (lvl - a!i)

-- | Binary search
bsearch :: (Int, Int) -> (Int -> Bool) -> Int
bsearch (l,r) p -- precondition: (p l) && not (p r)
  | l >= r    = l
  | p m       = bsearch (m,r) p
  | otherwise = bsearch (l,m-1) p
  where m = (l+r+1) `div` 2
