#include <bits/stdc++.h>
using namespace std;
const int MAX_SIZE = 50007;
const int MOD = 1000000000 + 7;
int data[MAX_SIZE + 10], n, K;
int trie[MAX_SIZE * 35][2];
int le[MAX_SIZE * 35], ri[MAX_SIZE * 35];
int tn;
int pre[32][MAX_SIZE + 10], pos[MAX_SIZE + 10];
void insert(int val) {
  int cur = 0;
  for (int i = 30; i >= 0; i--) {
    ++ri[cur];
    int p = (val >> i) & 1;
    if (!trie[cur][p]) {
      trie[cur][p] = ++tn;
      le[tn] = ri[cur];
      ri[tn] = le[tn] - 1;
    }
    cur = trie[cur][p];
  }
  ++ri[tn];
}
int main() {
  scanf("%d%d", &n, &K);
  for (int i = 1; i <= n; i++) scanf("%d", data + i);
  sort(data + 1, data + n + 1);
  for (int i = 1; i <= n; i++) insert(data[i]);
  for (int j = 0; j <= 30; j++)
    for (int i = 1; i <= n; i++)
      pre[j][i] = pre[j][i - 1] + ((data[i] >> j) & 1);
  int ans = 0, val = 0;
  unsigned int cnt = 0;
  unsigned int ha = (unsigned int)K * 2;
  for (int j = 30; j >= 0; j--) {
    unsigned int tmp = 0;
    for (int i = 1; i <= n; i++) {
      bool nxt = ((data[i] >> j) & 1) ^ 1;
      if (pos[i] != -1 && trie[pos[i]][nxt])
        tmp += ri[trie[pos[i]][nxt]] - le[trie[pos[i]][nxt]] + 1;
    }
    if (cnt + tmp < ha) {
      cnt += tmp;
      for (int i = 1; i <= n; i++) {
        if (pos[i] == -1) continue;
        bool nxt = ((data[i] >> j) & 1) ^ 1;
        for (register int k = 0; k <= 30; k++) {
          register int son = trie[pos[i]][nxt];
          if ((data[i] >> k) & 1) {
            if (son) {
              (ans) +=
                  ((int)(((long long)(ri[son] - le[son] + 1 -
                                      (pre[k][ri[son]] - pre[k][le[son] - 1]))
                          << k) %
                         MOD));
              if ((ans) >= MOD) (ans) -= MOD;
            };
          } else {
            if (son) {
              (ans) +=
                  ((int)(((long long)(pre[k][ri[son]] - pre[k][le[son] - 1])
                          << k) %
                         MOD));
              if ((ans) >= MOD) (ans) -= MOD;
            };
          }
        }
        if (trie[pos[i]][nxt ^ 1])
          pos[i] = trie[pos[i]][nxt ^ 1];
        else
          pos[i] = -1;
      }
    } else {
      val |= 1 << j;
      for (int i = 1; i <= n; i++) {
        int nxt = ((data[i] >> j) & 1) ^ 1;
        if (pos[i] != -1) {
          if (trie[pos[i]][nxt])
            pos[i] = trie[pos[i]][nxt];
          else
            pos[i] = -1;
        }
      }
    }
  }
  ans = (int)((long long)ans * 500000004 % MOD);
  {
    (ans) += ((int)((K - (cnt >> 1)) % MOD * val % MOD));
    if ((ans) >= MOD) (ans) -= MOD;
  };
  printf("%d\n", ans);
  return 0;
}
