#include <bits/stdc++.h>
using namespace std;
struct Trie {
  int ch[2], l, r, sz;
} t[50010 * 32];
int li[100], len, sz, a[50010], root, cur[50010], cs[50010];
unsigned short cc[50010][32];
bool b[30];
void ins(int w, int id) {
  bool c;
  int x = root;
  for (int i = 0; i < 30; i++) b[i] = w >> i & 1;
  for (int i = 30 - 1; i >= 0; i--) {
    c = b[i];
    ++t[x].sz;
    if (t[x].l > id) t[x].l = id;
    if (t[x].r < id) t[x].r = id;
    if (!t[x].ch[c]) {
      t[x].ch[c] = ++sz;
      t[t[x].ch[c]].l = t[t[x].ch[c]].r = id;
    }
    x = t[x].ch[c];
  }
  ++t[x].sz;
  if (t[x].l > id) t[x].l = id;
  if (t[x].r < id) t[x].r = id;
}
int n;
long long m, rem, fin;
int ans;
int main() {
  scanf("%d%I64d", &n, &m), root = sz = 1, m *= 2;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    ins(a[i], i);
    for (int j = 0; j < 30; j++) cc[i][j] = cc[i - 1][j] + (a[i] >> j & 1);
  }
  t[root].l = 1, t[root].r = n;
  long long cnt = 0;
  rem = m;
  int iv2 = (1000000007 + 1) / 2;
  for (int i = 1; i <= n; i++) cur[i] = cs[i] = root;
  for (int i = 30 - 1; i >= 0; i--) {
    long long _c = cnt;
    bool c;
    int x = root;
    li[++len] = 1;
    for (int j = 1; j <= n; j++) _c += t[t[cur[j]].ch[!(a[j] >> i & 1)]].sz;
    if (m > _c) li[len] = 0;
    for (int j = 1; j <= n; j++) {
      c = a[j] >> i & 1;
      if (!li[len]) {
        cnt += t[t[cur[j]].ch[!c]].sz;
        cur[j] = t[cur[j]].ch[c];
        int &x = cs[j], y = t[x].ch[!c];
        c ^= li[len];
        if (y) {
          rem -= t[y].sz;
          for (int k = 30 - 1; k >= 0; k--)
            ans = (ans + ((long long)((a[j] >> k & 1)
                                          ? (t[y].sz - cc[t[y].r][k] +
                                             cc[t[y].l - 1][k])
                                          : (cc[t[y].r][k] - cc[t[y].l - 1][k]))
                          << k)) %
                  1000000007;
        }
        x = t[x].ch[c];
      } else
        cur[j] = t[cur[j]].ch[!c], cs[j] = t[cs[j]].ch[li[len] ^ c];
    }
    fin = fin << 1 | li[len];
  }
  ans = (ans + rem * fin) % 1000000007;
  printf("%d\n", 1ll * ans * iv2 % 1000000007);
  return 0;
}
