#include <bits/stdc++.h>
using namespace std;
int n, m, sum[50009][31];
unsigned limit, a[50009], number;
struct Trie {
  int size[50009 * 31], root, ch[50009 * 31][2], cnt, pos[50009];
  unsigned S;
  void init() { root = cnt = 1; }
  void ins(int x) {
    int now = root;
    for (int i = 31 - 1; i >= 0; i--) {
      size[now]++;
      int c = x >> i & 1;
      if (!ch[now][c]) ch[now][c] = ++cnt;
      now = ch[now][c];
    }
    size[now]++;
  }
  void work() {
    for (int i = 1; i <= n; i++) pos[i] = root;
    number = limit = 0;
    for (int i = 31 - 1; i >= 0; i--) {
      S = 0;
      for (int j = 1; j <= n; j++)
        S += size[ch[pos[j]][!((limit ^ a[j]) >> i & 1)]];
      if (S + number <= m * 2)
        number += S;
      else
        limit ^= 1 << i;
      for (int j = 1; j <= n; j++) pos[j] = ch[pos[j]][(limit ^ a[j]) >> i & 1];
    }
    number /= 2;
  }
  int calc(int ret = 0) {
    for (int i = 1; i <= n; i++)
      for (int j = 0; j < 31; j++)
        if (!(limit >> j & 1)) {
          unsigned Min = a[i] ^ (limit | (1 << j));
          Min &= ~0 << j;
          int l = lower_bound(a + 1, a + n + 1, Min) - a;
          int r = lower_bound(a + 1, a + n + 1, Min + (1 << j)) - a;
          ret = (ret + (long long)((limit | (1 << j)) & (~0 << j)) %
                           1000000007 * (r - l) % 1000000007) %
                1000000007;
          for (int k = 0; k < j; k++) {
            int num = sum[r - 1][k] - sum[l - 1][k];
            if (a[i] >> k & 1) num = r - l - num;
            ret =
                (ret + (long long)num * ((1 << k) % 1000000007) % 1000000007) %
                1000000007;
          }
        }
    return (long long)ret * ((1000000007 + 1) / 2) % 1000000007;
  }
} trie;
int read() {
  int x = 1;
  char ch;
  while (ch = getchar(), ch < '0' || ch > '9')
    if (ch == '-') x = -1;
  int s = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10ll + ch - '0';
  return s * x;
}
int main() {
  trie.init();
  n = read(), m = read();
  for (int i = 1; i <= n; i++) trie.ins(a[i] = read());
  if (m == 0) {
    puts("0");
    return 0;
  }
  sort(a + 1, a + n + 1);
  for (int i = 0; i < 31; i++) sum[0][i] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 31; j++) sum[i][j] = sum[i - 1][j] + (a[i] >> j & 1);
  trie.work();
  printf("%d\n", (trie.calc() +
                  (long long)(m - number) * (limit % 1000000007) % 1000000007) %
                     1000000007);
  return 0;
}
