#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return l + rng() % (r - l + 1); }
const int N = 50010 * 30, M = 1000000007;
int n, m, it = 1, mode, cur;
int s[N], a[N];
int nxt[N][2];
int cnt[N][2];
void add(int x) {
  int i = 1;
  for (int k = 30, _c = 1; k >= _c; --k) {
    int j = ((x >> (k - 1)) & 1);
    if (!nxt[i][j]) nxt[i][j] = ++it;
    if (mode) cnt[i][((x >> (cur - 1)) & 1)]++;
    s[i]++;
    i = nxt[i][j];
  }
  s[i]++;
  if (mode) {
    cnt[i][((x >> (cur - 1)) & 1)]++;
  }
}
long long que(int x, int y) {
  int i = 1;
  long long tot = 0;
  for (int k = 30, _c = 1; k >= _c; --k) {
    if (!i) break;
    int j = ((x >> (k - 1)) & 1), t = ((y >> (k - 1)) & 1);
    if (mode) {
      if (!t) {
        tot = (tot + (long long)(1 << cur - 1) *
                         cnt[nxt[i][j ^ 1]][((x >> (cur - 1)) & 1) ^ 1]) %
              M;
        i = nxt[i][j];
      } else {
        i = nxt[i][j ^ 1];
      }
    } else {
      if (!t)
        tot += s[nxt[i][j ^ 1]], i = nxt[i][j];
      else
        i = nxt[i][j ^ 1];
    }
  }
  return (tot +
          (mode ? ((y >> (cur - 1)) & 1) * s[i] * (1 << cur - 1) : s[i])) %
         M;
}
int chk(int x) {
  while (it) {
    nxt[it][0] = nxt[it][1] = s[it] = 0;
    it--;
  }
  it++;
  int tot = 0;
  for (int i = 1, _c = n; i <= _c; ++i) {
    tot += que(a[i], x);
    add(a[i]);
  }
  return tot;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1, _c = n; i <= _c; ++i) cin >> a[i];
  int le = 0, mi, ri = (1 << 30) - 1, ret;
  while (le <= ri) {
    mi = le + (ri - le) / 2;
    if (chk(mi) >= m)
      ret = mi, le = mi + 1;
    else
      ri = mi - 1;
  }
  mode = 1;
  long long tot = 0;
  for (int i = 1, _c = 30; i <= _c; ++i) {
    cur = i;
    while (it) {
      nxt[it][0] = nxt[it][1] = s[it] = cnt[it][0] = cnt[it][1] = 0;
      it--;
    }
    it++;
    for (int j = 1, _c = n; j <= _c; ++j) {
      tot = (tot + que(a[j], ret)) % M;
      if (tot < 0) {
        exit(0);
      }
      add(a[j]);
    }
  }
  mode = 0;
  cout << (tot - (chk(ret) - m) * ret % M + M) % M;
}
