#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct Node {
  int cnt, l, r, z_0, z_1;
  Node() {
    cnt = 0;
    l = r = -1;
    z_0 = z_1 = 0;
  }
};
vector<Node> Trie;
void update(int x) {
  int cur = 0;
  for (int i = 30; i >= 0; i--) {
    int c = (((1 << i) & x) > 0);
    if (Trie[cur].l == -1) {
      Trie.push_back(Node());
      Trie[cur].l = Trie.size() - 1;
    }
    if (Trie[cur].r == -1) {
      Trie.push_back(Node());
      Trie[cur].r = Trie.size() - 1;
    }
    if (!c)
      cur = Trie[cur].l;
    else
      cur = Trie[cur].r;
    Trie[cur].cnt++;
  }
}
int query(int x, int k) {
  int ans = 0, cur = 0;
  for (int i = 30; i >= 0; i--) {
    int c_x = (((1 << i) & x) > 0);
    int c_k = (((1 << i) & k) > 0);
    if (Trie[cur].l == -1) {
      Trie.push_back(Node());
      Trie[cur].l = Trie.size() - 1;
    }
    if (Trie[cur].r == -1) {
      Trie.push_back(Node());
      Trie[cur].r = Trie.size() - 1;
    }
    if (!c_x) {
      if (!c_k) {
        ans += Trie[Trie[cur].r].cnt;
        cur = Trie[cur].l;
      } else
        cur = Trie[cur].r;
    } else {
      if (!c_k) {
        ans += Trie[Trie[cur].l].cnt;
        cur = Trie[cur].r;
      } else
        cur = Trie[cur].l;
    }
  }
  ans += Trie[cur].cnt;
  return ans;
}
void update2(int x, int col) {
  int cur = 0;
  for (int i = 30; i >= 0; i--) {
    int c = (((1 << i) & x) > 0);
    if (Trie[cur].l == -1) {
      Trie.push_back(Node());
      Trie[cur].l = Trie.size() - 1;
    }
    if (Trie[cur].r == -1) {
      Trie.push_back(Node());
      Trie[cur].r = Trie.size() - 1;
    }
    if (!c)
      cur = Trie[cur].l;
    else
      cur = Trie[cur].r;
    if (col == 1)
      Trie[cur].z_1++;
    else
      Trie[cur].z_0++;
  }
}
long long query2(int x, int k, int col) {
  long long ans = 0;
  int cur = 0;
  for (int i = 30; i >= 0; i--) {
    int c_x = (((1 << i) & x) > 0);
    int c_k = (((1 << i) & k) > 0);
    if (Trie[cur].l == -1) {
      Trie.push_back(Node());
      Trie[cur].l = Trie.size() - 1;
    }
    if (Trie[cur].r == -1) {
      Trie.push_back(Node());
      Trie[cur].r = Trie.size() - 1;
    }
    if (!c_x) {
      if (!c_k) {
        if (col == 1)
          ans += Trie[Trie[cur].r].z_1;
        else
          ans += Trie[Trie[cur].r].z_0;
        cur = Trie[cur].l;
      } else
        cur = Trie[cur].r;
    } else {
      if (!c_k) {
        if (col == 1)
          ans += Trie[Trie[cur].l].z_1;
        else
          ans += Trie[Trie[cur].l].z_0;
        cur = Trie[cur].r;
      } else
        cur = Trie[cur].l;
    }
  }
  if (col == 1)
    ans += Trie[cur].z_1;
  else
    ans += Trie[cur].z_0;
  return ans;
}
int n, m;
int a[50001];
int check(int x) {
  Trie.clear();
  Trie.push_back(Node());
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cnt += query(a[i], x);
    update(a[i]);
  }
  return cnt;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  if (m == 0) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= n; i++) cin >> a[i];
  long long l = 0, r = 2e9;
  int ans = -1;
  while (l <= r) {
    long long mi = (l + r) / 2;
    if (check(mi) >= m) {
      ans = mi;
      l = mi + 1;
    } else
      r = mi - 1;
  }
  int lft = check(ans) - m;
  long long res = 0;
  for (int j = 0; j <= 30; j++) {
    Trie.clear();
    Trie.push_back(Node());
    for (int i = 1; i <= n; i++) {
      int c = (((1 << j) & a[i]) > 0);
      res = (res + (query2(a[i], ans, 1 - c) * (1LL << j)) % mod) % mod;
      update2(a[i], c);
    }
  }
  cout << ((res - lft * ans) % mod + mod) % mod;
}
