#include "bits/stdc++.h"
 
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define ull unsigned long long
#define uint unsigned int
 


uint digit_level;
uint digitN;
 
const uint MODP0=2013265921; 
const uint MODP1=1811939329;
uint MODP_WnSqrt0,MODP_WnSqrt1;
uint MODP_Wn0,MODP_Wn1;
vector<uint> MTABLE0;
vector<uint> MTABLE1;

uint CreateWnSqrt(uint a,uint m,uint n_level){
  ull ans=a;
  ull ulm=m;
  for(int i=0;i<n_level-digit_level-1;i++){
    ans=ans*ans%ulm;
  }      
  return (uint)ans;
}
 
 
 
//aの逆元を返す mod m
uint modinv(uint a,uint m){
    ll b = m;
    ll u = 1;
    ll v = 0;
    ll t,tmp;
    while (b!=0){
        t = a / b;
        a -= t * b;
        tmp=a;
        a=b;
        b=tmp;
        u -= t * v;
        tmp = u;
        u = v;
        v = tmp;
    }
    u %= m;
    if (u < 0)u += m;
    return (uint)u;
}
 
 
//aのn乗 mod c
uint expmod(uint a,uint n,uint MOD){
  ull ans=1ULL,aa=a,beki=n,ulm=(ull)MOD;
  for(int i=0;i<63;i++){
    if (beki%2==1) ans=ans*aa%ulm;
    aa=aa*aa%ulm;
    beki/=2;
    if (beki==0)break;
  }
  return (uint)ans;
}
 
 
uint expmod0(uint a,uint n,uint MOD){
    return MTABLE0[n];
}

uint expmod1(uint a,uint n,uint MOD){
  return MTABLE1[n];
}
 
 
 
//garnerのアルゴリズム、3変数ver
void Garner(ll a_,ll b_,ll ar_,ll br_,ll *rx){
  ll a = a_;
  ll b = b_;
  ll ar = ar_;
  ll br = br_;
  ll mab=(ll)modinv(a,b);
  ll x=(br - ar) * mab % b;
  if (x<0){
    x+=b;
  }
  x = ar + x * a;
  *rx=x;
  }
 
 
void iFMT0(vector<uint>& arrayA){
  uint t2,t0,t1,arrayAt0,arrayAt1,w0,w1;
  for(int i=0;i<digit_level;i++){
    uint loopCnt_Pow2 = 1 << i;
    for(int idx=0;idx<digitN/2;idx++){
      t2 = idx % loopCnt_Pow2;
      t0 = idx * 2 - t2;
      t1 = t0 + loopCnt_Pow2;
      arrayAt0 = arrayA[t0];
      arrayAt1 = arrayA[t1];
      w0 = expmod0(MODP_Wn0, digitN - t2 * (1 << (digit_level - 1 - i)),MODP0);
      w1 = (uint)((ull)arrayAt1 * (ull)w0 % (ull)MODP0);
      arrayAt1=arrayAt0 + MODP0 - w1;
      if (arrayAt1>=MODP0)arrayAt1-=MODP0;
      arrayAt0+=w1;
      if (arrayAt0>=MODP0)arrayAt0-=MODP0;
      arrayA[t1] = arrayAt1;
      arrayA[t0] = arrayAt0;
    }
  }
}

void iFMT1(vector<uint>& arrayA){
  uint t2,t0,t1,arrayAt0,arrayAt1,w0,w1;
  for(int i=0;i<digit_level;i++){
    uint loopCnt_Pow2 = 1 << i;
    for(int idx=0;idx<digitN/2;idx++){
      t2 = idx % loopCnt_Pow2;
      t0 = idx * 2 - t2;
      t1 = t0 + loopCnt_Pow2;
      arrayAt0 = arrayA[t0];
      arrayAt1 = arrayA[t1];
      w0 = expmod1(MODP_Wn1, digitN - t2 * (1 << (digit_level - 1 - i)),MODP1);
      w1 = (uint)((ull)arrayAt1 * (ull)w0 % (ull)MODP1);
      arrayAt1=arrayAt0 + MODP1 - w1;
      if (arrayAt1>=MODP1)arrayAt1-=MODP1;
      arrayAt0+=w1;
      if (arrayAt0>=MODP1)arrayAt0-=MODP1;
      arrayA[t1] = arrayAt1;
      arrayA[t0] = arrayAt0;
    }
  }
}
 

 
void uFMT0(vector<uint>& arrayA){
  uint t2,t0,t1,arrayAt0,arrayAt1,w0,w1,r0,r1;
  for(int i=0;i<digit_level;i++){
    uint loopCnt_Pow2 = 1 << (digit_level - i - 1);
    for(int idx=0;idx<digitN/2;idx++){
        t2 = idx % loopCnt_Pow2;
        t0 = idx * 2 - t2;
        t1 = t0 + loopCnt_Pow2;
        arrayAt0 = arrayA[t0];
        arrayAt1 = arrayA[t1];
        w0 = expmod0(MODP_Wn0, t2 * (1 << i),MODP0);
        r0 = (arrayAt0 - arrayAt1 + MODP0);
        if (r0>=MODP0)r0-= MODP0;
        r1 = (arrayAt0 + arrayAt1);
        if (r1>=MODP0)r1-= MODP0;
        w1 = (uint)((ull)r0 * (ull)w0 % (ull)MODP0);
        arrayA[t1] = w1;
        arrayA[t0] = r1;
    }
  }
}
 
  
void uFMT1(vector<uint>& arrayA){
  uint t2,t0,t1,arrayAt0,arrayAt1,w0,w1,r0,r1;
  for(int i=0;i<digit_level;i++){
    uint loopCnt_Pow2 = 1 << (digit_level - i - 1);
    for(int idx=0;idx<digitN/2;idx++){
        t2 = idx % loopCnt_Pow2;
        t0 = idx * 2 - t2;
        t1 = t0 + loopCnt_Pow2;
        arrayAt0 = arrayA[t0];
        arrayAt1 = arrayA[t1];
        w0 = expmod1(MODP_Wn1, t2 * (1 << i),MODP1);
        r0 = (arrayAt0 - arrayAt1 + MODP1);
        if (r0>=MODP1)r0-= MODP1;
        r1 = (arrayAt0 + arrayAt1);
        if (r1>=MODP1)r1-= MODP1;
        w1 = (uint)((ull)r0 * (ull)w0 % (ull)MODP1);
        arrayA[t1] = w1;
        arrayA[t0] = r1;
    }
  }
}
 
void DivN0(vector<uint>& arrayA){
  ull digitN_r = modinv(digitN, MODP0);
  for(int i=0;i<digitN;i++){
    ull ret = (ull)(arrayA[i]) * digitN_r % (ull)MODP0;
    arrayA[i]=(uint)(ret);
  }
}

void DivN1(vector<uint>& arrayA){
  ull digitN_r = modinv(digitN, MODP1);
  for(int i=0;i<digitN;i++){
    ull ret = (ull)(arrayA[i]) * digitN_r % (ull)MODP1;
    arrayA[i]=(uint)(ret);
  }
}

//    #A*Bの畳み込み結果を返す
void Convolution0(vector<uint>& A_,vector<uint>& B_,vector<uint>& E){
  //#正巡回
  vector<uint> A1(digitN),B1(digitN);
  for(int i=0;i<digitN;i++)
    A1[i]=A_[i]%MODP0;
  for(int i=0;i<digitN;i++)
    B1[i]=B_[i]%MODP0;
  uFMT0(A1);
  uFMT0(B1);
  for(int i=0;i<digitN;i++)
    E[i]=(uint)((ull)A1[i]*(ull)B1[i]%(ull)MODP0);
  iFMT0(E);
  DivN0(E);
}


//    #A*Bの畳み込み結果を返す
void Convolution1(vector<uint>& A_,vector<uint>& B_,vector<uint>& E){
  //#正巡回
  vector<uint> A1(digitN),B1(digitN);
  for(int i=0;i<digitN;i++)
    A1[i]=A_[i]%MODP1;
  for(int i=0;i<digitN;i++)
    B1[i]=B_[i]%MODP1;
  uFMT1(A1);
  uFMT1(B1);
  for(int i=0;i<digitN;i++)
    E[i]=(uint)((ull)A1[i]*(ull)B1[i]%(ull)MODP1);
  iFMT1(E);
  DivN1(E);
}


//#E0,E1を使ってgarnerでEを復元
void Carrying(vector<uint>& E0,vector<uint>& E1,vector<ll>& E){
  ll out_;
  for(int i=0;i<digitN;i++){
    Garner(MODP0,MODP1, E0[i], E1[i],&out_);
    E[i]=out_;
  }
}
 
 


 void CreateTable()
 {
  MTABLE0.resize(1<<(digit_level+1));
  MTABLE1.resize(1<<(digit_level+1));
  MTABLE0[0]=1;
  MTABLE1[0]=1;
  for(int i=1;i<digitN*2;i++){
    MTABLE0[i]=(uint)((ull)MTABLE0[i-1]*(ull)MODP_Wn0%(ull)MODP0);
  }
  for(int i=1;i<digitN*2;i++){
    MTABLE1[i]=(uint)((ull)MTABLE1[i-1]*(ull)MODP_Wn1%(ull)MODP1);
  }
 }
 
 

 
ll n,m;
int main(){
  ll ans=0;
  cin >> n >> m;
  vector<int> a(n);
  REP(i,n) cin>>a[i];
 

  digit_level=18;
  digitN=1<<digit_level;//乗算前の要素数。乗算結果は2*digitN要素数になる
  
  //P 2種類作る
  MODP_WnSqrt0=CreateWnSqrt(52278,2013265921,27);
  MODP_Wn0=(uint)((ull)MODP_WnSqrt0*(ull)MODP_WnSqrt0%(ull)MODP0);
  MODP_WnSqrt1=CreateWnSqrt(59189,1811939329,26);
  MODP_Wn1=(uint)((ull)MODP_WnSqrt1*(ull)MODP_WnSqrt1%(ull)MODP1);
 
  CreateTable();
  
 
  vector<uint> A_(digitN),B_(digitN),E0(digitN),E1(digitN);
  for(int i=0;i<n;i++){
    A_[a[i]]++;
    B_[a[i]]++;
  }
 
 
  Convolution0(A_,B_,E0);
  Convolution1(A_,B_,E1);

  vector<ll> E(digitN,0);//結果格納変数
  Carrying(E0,E1,E);
 
 
 
 
  for(ll i=digitN-1;i>=0;i--){
    if (m>E[i]){
      m-=E[i];
      ans+=E[i]*i;
    }else{
      ans+=m*i;
      break;
    }
  }
 
 
 
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 12920