#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int n;
long long m;
int a[(50000 + 5)];
struct Trie {
  int ch[2], cnt, r;
} T[(50000 + 5) * 31];
int t[(50000 + 5)][31];
int num = 1;
void Insert(int idx, int val) {
  int b[31];
  for (int i = 30; ~i; --i) {
    b[i] = val & 1;
    val >>= 1;
  }
  int x = 1;
  for (int i = 0; i < 31; ++i) {
    ++T[x].cnt;
    T[x].r = idx;
    if (!T[x].ch[b[i]]) T[x].ch[b[i]] = ++num;
    x = T[x].ch[b[i]];
  }
  ++T[x].cnt;
  T[x].r = idx;
}
int Rank(int val, int k) {
  int b[35], c[35];
  for (int i = 30; ~i; --i) {
    b[i] = val & 1;
    c[i] = k & 1;
    val >>= 1;
    k >>= 1;
  }
  int x = 1, rk = 0;
  for (int i = 0; i < 31; ++i) {
    if (b[i])
      x = T[x].ch[c[i] ^ 1];
    else
      rk += T[T[x].ch[c[i] ^ 1]].cnt, x = T[x].ch[c[i]];
  }
  return rk;
}
bool Check(int val) {
  long long rk = 1;
  for (int i = 1; i <= n; ++i) rk += Rank(val, a[i]);
  return rk <= m;
}
long long Sum(int val, int k) {
  int b[35], c[35];
  for (int i = 30; ~i; --i) {
    b[i] = val & 1;
    c[i] = k & 1;
    val >>= 1;
    k >>= 1;
  }
  long long sum = 0;
  int x = 1, tmp;
  for (int i = 0; i < 31; ++i) {
    if (b[i])
      x = T[x].ch[c[i] ^ 1];
    else {
      int y = T[x].ch[c[i] ^ 1];
      for (int j = 0; j < 31; ++j) {
        if (c[j] ^ 1)
          tmp = t[T[y].r][j] - t[T[y].r - T[y].cnt][j];
        else
          tmp = T[y].cnt - (t[T[y].r][j] - t[T[y].r - T[y].cnt][j]);
        sum += (long long)tmp * (1 << 30 - j);
      }
      x = T[x].ch[c[i]];
    }
  }
  return sum;
}
int main() {
  scanf("%d%d", &n, &m);
  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) Insert(i, a[i]);
  for (int i = 1; i <= n; ++i)
    for (int j = 30, k = a[i]; ~j; --j, k >>= 1)
      t[i][j] = t[i - 1][j] + (k & 1);
  int l = 0, r = (1 << 30) - 1, mid;
  while (l < r) {
    mid = l + r >> 1;
    if (Check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) ans += Sum(l, a[i]), m -= Rank(l, a[i]);
  ans += m * l;
  printf("%lld", ans / 2 % mod);
  return 0;
}
