#include <bits/stdc++.h>
using namespace std;
class Trie : vector<Trie> {
 private:
  int value;
  vector<int> _cnt;

 public:
  Trie() {
    value = 0;
    _cnt = vector<int>(30, 0);
  }
  int& v() { return value; }
  int& cnt(int x) { return _cnt[x]; }
  Trie& operator[](int x) {
    if (!this->size()) this->assign(2, Trie());
    return this->at(x);
  }
};
int get_bit(int i, const int& x) { return (((1 << i) & x) ? 1 : 0); }
Trie T;
void add(Trie& Tr, const int& x, int cur) {
  if (cur < 0) {
    ++Tr.v();
    for (int i = 0; i < (int)30; ++i) Tr.cnt(i) += (((1 << i) & x) ? 1 : 0);
    return;
  }
  ++Tr.v();
  add(Tr[get_bit(cur, x)], x, cur - 1);
  for (int i = 0; i < (int)30; ++i) Tr.cnt(i) += get_bit(i, x);
}
int steps = 0;
int cnt(const int& x, const int& m, int cur) {
  int ans = 0;
  Trie* Tr = &T;
  while (1) {
    if (!(*Tr).v()) return ans;
    if (cur == -1) return ans + Tr->v();
    if ((1 << cur) & m)
      Tr = &((*Tr)[get_bit(cur, x) ^ 1]);
    else {
      ans += (*Tr)[get_bit(cur, x) ^ 1].v();
      Tr = &((*Tr)[get_bit(cur, x)]);
    }
    --cur;
  }
}
void sum(Trie& Tr, const int& x, const int& m, vector<int>& ct, int cur) {
  if (!Tr.v()) return;
  if (cur == -1) {
    for (int i = 0; i < (int)30; ++i) ct[i] += Tr.cnt(i);
    return;
  }
  if ((1 << cur) & m)
    return sum(Tr[get_bit(cur, x) ^ 1], x, m, ct, cur - 1), void(0);
  sum(Tr[get_bit(cur, x)], x, m, ct, cur - 1);
  for (int i = 0; i < (int)30; ++i) ct[i] += Tr[get_bit(cur, x) ^ 1].cnt(i);
}
int n;
long long m;
vector<int> A;
long long get_cnt(int mid) {
  long long ans = 0;
  for (int i = 0; i < (int)n; ++i) ans += cnt(A[i], mid, 29);
  return ans / 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  A.assign(n, 0);
  ;
  for (int i = 0; i < (int)n; ++i) {
    cin >> A[i];
    add(T, A[i], 29);
  }
  long long low = 1, hi = (1 << 30);
  while (low != hi) {
    long long mid = (low + hi) >> 1;
    if (get_cnt(mid) > m)
      low = mid + 1;
    else
      hi = mid;
  }
  if (get_cnt(low) < m) --low;
  long long ans = 0;
  for (int i = 0; i < (int)n; ++i) {
    vector<int> ct(30);
    sum(T, A[i], low, ct, 29);
    long long c = cnt(A[i], low, 29);
    for (int k = 0; k < (int)30; ++k)
      if (get_bit(k, A[i]))
        ans += (c - ct[k]) * (1LL << k);
      else
        ans += ct[k] * (1LL << k);
  }
  ans /= 2;
  long long gg = get_cnt(low);
  ans -= max(0LL, gg - m) * low;
  cout << ans % 1000000007 << endl;
}
