#include <bits/stdc++.h>
using namespace std;
const int maxn = int(5e4) + 100;
const int cut = 30;
const int mod = int(1e9) + 7;
struct node {
  node *son[2];
  int sum;
  int binary[cut];
  node() {
    son[0] = son[1] = NULL;
    sum = 0;
    for (int i = 0; i < cut; ++i) binary[i] = 0;
  }
};
node memory[maxn * cut];
node *mem = memory;
int n;
long long ans, must, m;
int a[maxn];
node *q[maxn];
node *trie;
void insert(int value) {
  node *cur = trie;
  for (int i = cut - 1; i >= 0; --i) {
    if (!cur->son[value >> i & 1]) cur->son[value >> i & 1] = mem++;
    cur = cur->son[value >> i & 1];
    cur->sum++;
    for (int j = 0; j < cut; ++j) cur->binary[j] += (value >> j & 1);
  }
}
void init() {
  trie = mem++;
  scanf("%d%I64d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    insert(a[i]);
  }
}
void solve() {
  for (int i = 1; i <= n; ++i) q[i] = trie;
  m <<= 1;
  for (int i = cut - 1; m && i >= 0; --i) {
    long long s = 0;
    for (int j = 1; j <= n; ++j)
      if (q[j] && q[j]->son[!(a[j] >> i & 1)])
        s += q[j]->son[!(a[j] >> i & 1)]->sum;
    if (s <= m) {
      for (int j = 1; j <= n; ++j) {
        if (!q[j]) continue;
        node *cur = q[j]->son[!(a[j] >> i & 1)];
        if (!cur) {
          q[j] = q[j]->son[a[j] >> i & 1];
          continue;
        }
        for (int k = 0; k < cut; ++k)
          ans += (1LL * ((a[j] >> k & 1) ? cur->sum - cur->binary[k]
                                         : cur->binary[k]))
                 << k;
        q[j] = q[j]->son[a[j] >> i & 1];
      }
      m -= s;
    } else {
      must |= 1 << i;
      for (int j = 1; j <= n; ++j)
        if (q[j]) q[j] = q[j]->son[!(a[j] >> i & 1)];
    }
  }
  printf("%I64d\n", ((ans + must * m) / 2) % mod);
}
int main() {
  init();
  solve();
  return 0;
}
