'use strict';
(function(input){
  input=input.trim().split(/\n+/);
  input=input.map(str=>str.trim().split(/\s+/).map(x=>x-0));
  const N=input[0][0],M=input[0][1],A=input[1];
  A.sort((a,b)=>a-b);
  let r=Math.floor(Math.sqrt(M));
  let s=M-r*r;
  let t=s%2;
  s=(s-t)/2;
  /*M=r*r+2*s+t、r,s,t>0,[r,s]maximized*/
  let first_s_total=0,
      first_s_plus_t_total=0,
      first_r_total=0,
      last_one=0;
  
  for(let i=0;i<s;i++){
    first_s_total+=A.pop();
  }
  
  first_s_plus_t_total+=first_s_total;
  if(t)first_s_plus_t_total+=A.pop();
  
  first_r_total+=first_s_plus_t_total;
  for(let i=r+s+t;i<r;i++){
    first_r_total+=A.pop();
  }
  
  last_one=A.pop();
  
  let ans=0;
  
  ans+=2*r*first_r_total;
  ans+=first_s_total;
  ans+=first_s_plus_t_total;
  ans+=(2*s+t)*last_one;
  
  console.log(ans)
  
})(require('fs').readFileSync('/dev/stdin','utf8'));