#include <bits/stdc++.h>
using namespace std;
const int size = 51110;
const int mod = 1e9 + 7;
struct node {
  int sum, cnt[32], son[2];
} t[size * 33];
int tot = 1;
void insert(int a) {
  int cur = 0;
  for (int i = 31; i >= 0; i--) {
    int d = (a >> i) & 1;
    if (t[cur].son[d] == 0) {
      t[cur].son[d] = tot;
      t[tot].sum = t[tot].son[0] = t[tot].son[1] = 0;
      for (int i = 31; i >= 0; i--) t[tot].cnt[i] = 0;
      tot++;
    }
    cur = t[cur].son[d];
    t[cur].sum++;
    for (int i = 31; i >= 0; i--) t[cur].cnt[i] += ((a >> i) & 1);
  }
}
long long n, m, a[size];
long long Num, Sum;
void work(int p, int flag) {
  Num = Sum = 0;
  for (int i = 0; i < n; i++) {
    int a = ::a[i], cur = 0, x;
    for (int i = 31; i >= 0; i--) {
      int d = ((a ^ p) >> i) & 1;
      if ((p >> i) & 1) {
      } else {
        x = t[cur].son[!d];
        Num += t[x].sum;
        if (flag)
          for (int i = 31; i >= 0; i--) {
            if (a & (1 << i))
              Sum = (Sum + 1ll * (t[x].sum - t[x].cnt[i]) * (1 << i)) % mod;
            else
              Sum = (Sum + 1ll * t[x].cnt[i] * (1 << i)) % mod;
          }
      }
      if (t[cur].son[d] != 0)
        cur = t[cur].son[d];
      else
        goto ex;
    }
    x = cur;
    Num += t[x].sum;
    if (flag)
      for (int i = 31; i >= 0; i--) {
        if (a & (1 << i))
          Sum = (Sum + 1ll * (t[x].sum - t[x].cnt[i]) * (1 << i)) % mod;
        else
          Sum = (Sum + 1ll * t[x].cnt[i] * (1 << i)) % mod;
      }
  ex:;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    insert(a[i]);
  }
  long long low = 0, high = (1ll << 31) - 1, mid;
  while (high > low) {
    mid = (high + low + 1) >> 1;
    work(mid, 0);
    if (Num / 2 >= m)
      low = mid;
    else
      high = mid - 1;
  }
  work(low, 1);
  Sum -= (Num - 2 * m) * low;
  Sum %= mod;
  if (Sum < 0) Sum += mod;
  if (Sum % 2)
    Sum = (Sum + mod) / 2;
  else
    Sum /= 2;
  cout << Sum;
}
