← Home
// Code written for Jasnah

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const int MOD = 1000000007;
const int N = 50010;
int n,m,a[N],ct;

int main()
{
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
  for(int i=29;i>=0;i--)
  {
    map<int,int> hsh;
    int res=0;
    for(int j=1;j<=n;j++) hsh[a[j]>>i]++;ct<<=1;
    for(map<int,int> :: iterator p=hsh.begin();p!=hsh.end();p++)
    {
      int x=p->first,y=(ct+1) ^ x;
      if(x<y) res+=p->second*hsh[y];
    }
    if(res>=m) ct++;
    else m-=res;
  }

  LL ans=0;
  sort(a+1,a+n+1);
  for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
    {
      int t=a[i]^a[j];
      if(t>ct) ans+=t;
    }
  printf("%I64d\n",(ans+1ll*m*ct)%MOD);
  return 0;
}