#include <bits/stdc++.h>
using namespace std;
int n, m, a[(50 * 1000 + 10)], now, cnt1, mp2[(31)][2][(50 * 1000 + 10)],
    mp[(50 * 1000 + 10)];
long long ans, res;
int main() {
  scanf("%d%d", &n, &m);
  int m2 = m;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int t = (31) - 1; t >= 0; t--) {
    memset(mp2, 0, sizeof mp2);
    memset(mp, 0, sizeof mp);
    now *= 2;
    now++;
    cnt1 = res = 0;
    vector<int> tmp;
    for (int i = 0; i < n; i++) tmp.push_back((a[i] >> t));
    sort(tmp.begin(), tmp.end());
    tmp.resize(unique(tmp.begin(), tmp.end()) - tmp.begin());
    for (int i = 0; i < n; i++) {
      int ex = lower_bound(tmp.begin(), tmp.end(), (a[i] >> t)) - tmp.begin();
      mp[ex]++;
      for (int j = 0; j <= t; j++) mp2[j][((a[i] & (1 << j)) != 0)][ex]++;
    }
    for (int i = 0; i < tmp.size(); i++)
      if ((tmp[i] ^ now) > tmp[i]) {
        int ex =
            lower_bound(tmp.begin(), tmp.end(), (tmp[i] ^ now)) - tmp.begin();
        if (ex == (int)tmp.size() || tmp[ex] != (tmp[i] ^ now)) continue;
        cnt1 += mp[ex] * mp[i];
        for (int j = 0; j <= t; j++) {
          res += 1LL * mp2[j][0][i] * mp2[j][1][ex] * (1 << j);
          res += 1LL * mp2[j][1][i] * mp2[j][0][ex] * (1 << j);
        }
      }
    if (cnt1 < m)
      ans += res, now--, m -= cnt1;
    else
      ans += 1LL * m * (1 << t);
  }
  cout << ans % ((int)1e9 + 7);
  return 0;
}
