#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5e4 + 5, mod = 1e9 + 7;
inline void Add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int n, a[N];
ll m;
int tot, nxt[N * 30][2], sz[N * 30], mn[N * 30], mx[N * 30];
int ps[N], cnt[N][30];
inline int newnode() {
  ++tot;
  mn[tot] = n + 1, mx[tot] = 0;
  return tot;
}
void ins(int x, int id) {
  int p = 0;
  for (int i = 29; i >= 0; i--) {
    int k = (x >> i) & 1;
    if (!nxt[p][k]) nxt[p][k] = newnode();
    p = nxt[p][k];
    sz[p]++;
    mn[p] = min(mn[p], id);
    mx[p] = max(mx[p], id);
  }
}
void go(int b, int op) {
  for (int i = 1; i <= n; i++) {
    int k = (a[i] >> b) & 1;
    if (ps[i] == -1) continue;
    if (nxt[ps[i]][k ^ op])
      ps[i] = nxt[ps[i]][k ^ op];
    else
      ps[i] = -1;
  }
}
int gao() {
  m <<= 1;
  int ans = 0, v = 0;
  for (int i = 29; i >= 0; i--) {
    ll cur = 0;
    for (int j = 1; j <= n; j++) {
      int k = (a[j] >> i) & 1;
      if (ps[j] == -1 || !nxt[ps[j]][k ^ 1]) continue;
      cur += sz[nxt[ps[j]][k ^ 1]];
    }
    if (cur >= m) {
      v |= (1 << i);
      go(i, 1);
    } else {
      m -= cur;
      for (int j = 1; j <= n; j++) {
        int k = (a[j] >> i) & 1;
        if (ps[j] == -1 || !nxt[ps[j]][k ^ 1]) continue;
        int l = mn[nxt[ps[j]][k ^ 1]], r = mx[nxt[ps[j]][k ^ 1]];
        for (int b = i - 1; b >= 0; b--) {
          int x = (a[j] >> b) & 1;
          if (!x)
            Add(ans, 1ll * (cnt[r][b] - cnt[l - 1][b]) * (1 << b) % mod);
          else
            Add(ans,
                1ll * (r - l + 1 - cnt[r][b] + cnt[l - 1][b]) * (1 << b) % mod);
        }
        Add(ans, 1ll * (r - l + 1) * (v | (1 << i)) % mod);
      }
      go(i, 0);
    }
  }
  Add(ans, 1ll * m * v % mod);
  ans = 1ll * ans * ((mod + 1) / 2) % mod;
  return ans;
}
int main() {
  scanf("%d%lld", &n, &m);
  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 i = 1; i <= n; i++)
    for (int j = 0; j <= 29; j++) cnt[i][j] = cnt[i - 1][j] + ((a[i] >> j) & 1);
  printf("%d\n", gao());
  return 0;
}
