#include <bits/stdc++.h>
using namespace std;
long long n, m;
int a[50002];
long long results = 0;
int numZero[50002][30], numOne[50002][30];
long long power(int x, int p) {
  if (!p) return 1;
  long long q = power(x, p / 2);
  q = (q * q) % 1000000007;
  if (p & 1) q = (q * x) % 1000000007;
  return q;
}
int getLowerbound(int value) {
  int low = 0, high = n, ans = n;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (a[mid] <= value) {
      ans = mid;
      low = mid + 1;
    } else
      high = mid - 1;
  }
  return ans;
}
pair<int, int> getRange(int hash, int depth, int x) {
  int prefix = 0;
  for (int j = 30 - 1; j >= depth; j--)
    if ((hash & (1 << j)) != (x & (1 << j))) prefix |= 1 << j;
  int low = prefix - 1, high = prefix + (1 << depth) - 1;
  int lowPos = getLowerbound(low), highPos = getLowerbound(high);
  return make_pair(lowPos, highPos);
}
int getPrefix(int hash, int depth, int x) {
  int prefix = 0;
  for (int j = 30 - 1; j >= depth; j--)
    if ((hash & (1 << j)) != (x & (1 << j))) prefix |= 1 << j;
  return prefix;
}
long long countNumber(int hash, int depth) {
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    pair<int, int> R = getRange(hash, depth, a[i]);
    if (R.first >= R.second) continue;
    ans += R.second - R.first;
    if (R.first < i && i <= R.second) ans--;
  }
  return ans;
}
long long sumAll(int hash, int depth, long long rem) {
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    pair<int, int> R = getRange(hash, depth, a[i]);
    int numbers = R.second - R.first;
    if (R.first < i && i <= R.second) numbers--;
    if (numbers <= 0) continue;
    if (numbers > rem) numbers = rem;
    int prefix = getPrefix(hash, depth, a[i]);
    for (int j = depth - 1; j >= 0; j--) {
      int counter = 0;
      if (a[i] & (1 << j)) {
        counter += numZero[R.second][j];
        counter -= numZero[R.first][j];
      } else {
        counter += numOne[R.second][j];
        counter -= numOne[R.first][j];
      }
      counter = min(counter, numbers);
      long long add = 1LL * counter * (1LL << j);
      ans = (ans + add) % 1000000007;
    }
    long long add = (1LL * hash * numbers) % 1000000007;
    ans = (ans + add) % 1000000007;
    rem -= numbers;
  }
  return ans;
}
void solve() {
  long long hashValue = 0, rem = m;
  for (int i = 30 - 1; i >= 0; i--) {
    if (rem <= 0) break;
    long long tmp = countNumber(hashValue | 1 << i, i);
    if (tmp <= rem) {
      results = (results + sumAll(hashValue | 1 << i, i, tmp));
      rem -= tmp;
    } else
      hashValue |= 1 << i;
  }
  if (rem > 0) results = (results + sumAll(hashValue, 0, rem));
  cout << (results * power(2, 1000000007 - 2)) % 1000000007 << endl;
}
void slowAnswer() {
  vector<int> opt;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) opt.push_back(a[i] ^ a[j]);
  sort(opt.rbegin(), opt.rend());
  long long answer = 0;
  for (int i = 0; i < m; i++) answer = (answer + opt[i]) % 1000000007;
  cout << answer << endl;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  a[0] = -(1 << 30);
  sort(a, a + n + 1);
  a[n + 1] = 1 << 30;
  for (int i = 1; i <= n + 1; i++)
    for (int j = 0; j < 30; j++)
      if (a[i] & (1 << j)) {
        numZero[i][j] = numZero[i - 1][j];
        numOne[i][j] = numOne[i - 1][j] + 1;
      } else {
        numZero[i][j] = numZero[i - 1][j] + 1;
        numOne[i][j] = numOne[i - 1][j];
      }
  m *= 2;
  solve();
}
