#include <bits/stdc++.h>
inline unsigned int getuint() {
  char w = getchar();
  while (w < '0' || '9' < w) w = getchar();
  unsigned int ans = 0;
  for (; '0' <= w && w <= '9'; w = getchar()) ans = ans * 10 + w - '0';
  return ans;
}
const int mod = 1000000007;
int n, m;
int a[50005];
int s[50005][30];
struct Chairman_Trie {
  struct node {
    node *s[2];
    int l, r;
  } pool[1500005], *poolnow, *null, *root;
  inline node *newnode() {
    node *p = poolnow++;
    return p->s[0] = p->s[1] = null, p;
  }
  Chairman_Trie() {
    null = (poolnow = pool)++, null->s[0] = null->s[1] = null, null->l = 1,
    (root = newnode())->l = 1;
  }
  void insert(int x, int num) {
    node *p = root;
    for (int j = 30; j--;) {
      p->r = num;
      int f = x >> j & 1;
      if (p->s[f] == null) (p->s[f] = newnode())->l = num;
      p = p->s[f];
    }
    p->r = num;
  }
  std::pair<int, int> calimit() {
    static node *p[50005];
    int ans = 0, cnt = 0;
    for (int i = 1; i <= n; i++) p[i] = root;
    for (int j = 30; j--;) {
      long long sum = 0;
      for (int i = 1; i <= n; i++)
        sum += p[i]->s[~a[i] >> j & 1]->r - p[i]->s[~a[i] >> j & 1]->l + 1;
      if (cnt + (sum >>= 1) <= m)
        cnt += sum;
      else
        ans |= 1 << j;
      for (int i = 1; i <= n; i++) p[i] = p[i]->s[(ans ^ a[i]) >> j & 1];
    }
    return std::make_pair(ans, cnt);
  }
  long long solve(int limit) {
    long long ans = 0, sum;
    for (int i = 1; i <= n; i++) {
      node *p = root;
      for (int j = 30; j--; p = p->s[(limit ^ a[i]) >> j & 1])
        if (~limit >> j & 1) {
          node *q = p->s[~a[i] >> j & 1];
          sum = q->r - q->l + 1;
          ans += sum * ((limit | 1 << j) & (~0 << j)) % mod;
          for (int k = 0; k < j; k++) {
            sum = s[q->r][k] - s[q->l - 1][k];
            if (a[i] >> k & 1) sum = q->r - q->l + 1 - sum;
            ans += (sum << k) % mod;
          }
        }
      ans %= mod;
    }
    return ans * (mod + 1 >> 1) % mod;
  }
} CTrie;
int main() {
  n = getuint(), m = getuint();
  for (int i = 1; i <= n; i++) a[i] = getuint();
  std::sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 30; j++) s[i][j] = s[i - 1][j] + (a[i] >> j & 1);
  for (int i = 1; i <= n; i++) CTrie.insert(a[i], i);
  std::pair<int, int> t = CTrie.calimit();
  printf("%I64d\n",
         (1ll * t.first * (m - t.second) + CTrie.solve(t.first)) % mod);
  return 0;
}
