#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::sort;
const int MAXN = 50050;
int n;
long long k;
int a[MAXN];
int sum[MAXN][30][2];
int kth;
long long ans;
long long tm;
inline int read() {
  int h = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    h = (h << 1) + (h << 3) + c - '0';
    c = getchar();
  }
  return h;
}
void pre_sum() {
  for (register int j = 0; j <= 29; j++) {
    for (register int i = 1; i <= n; i++) {
      sum[i][j][0] = sum[i - 1][j][0];
      sum[i][j][1] = sum[i - 1][j][1];
      sum[i][j][(a[i] >> j) & 1]++;
    }
  }
}
struct Node {
  int sz;
  int ch[2];
  int l, r;
} z[MAXN * 30];
int cnt = 1;
int r[MAXN];
inline void insert(int pla, int x) {
  int rt = 1;
  for (register int i = 29; i >= 0; i--) {
    z[rt].sz++;
    int nw = ((x >> i) & 1);
    if (!z[rt].ch[nw]) {
      z[rt].ch[nw] = ++cnt;
      z[z[rt].ch[nw]].l = pla;
    }
    z[z[rt].ch[nw]].r = pla;
    rt = z[rt].ch[nw];
  }
  z[rt].sz++;
}
inline long long calc(int l, int r, int x) {
  if (l == 0 && r == 0) return 0;
  long long anss = 0;
  for (register int i = 29; i >= 0; i--) {
    int nws = ((x >> i) & 1);
    anss += (1ll << i) * (sum[r][i][nws ^ 1] - sum[l - 1][i][nws ^ 1]);
  }
  return anss;
}
inline void get_kth() {
  long long kk = k;
  for (register int i = 1; i <= n; i++) {
    r[i] = 1;
  }
  for (register int j = 29; j >= 0; j--) {
    long long tmp = 0;
    for (register int i = 1; i <= n; i++) {
      int nws = ((a[i] >> j) & 1) ^ 1;
      tmp += z[z[r[i]].ch[nws]].sz;
    }
    if (tmp >= kk) {
      kth |= (1 << j);
      for (register int i = 1; i <= n; i++) {
        int nws = ((a[i] >> j) & 1) ^ 1;
        r[i] = z[r[i]].ch[nws];
      }
    } else {
      kk -= tmp;
      for (register int i = 1; i <= n; i++) {
        int nws = ((a[i] >> j) & 1);
        tm += z[z[r[i]].ch[nws ^ 1]].sz;
        ans += calc(z[z[r[i]].ch[nws ^ 1]].l, z[z[r[i]].ch[nws ^ 1]].r, a[i]);
        r[i] = z[r[i]].ch[nws];
      }
    }
  }
}
void get_sum() {
  for (register int i = 1; i <= n; i++) {
    int rt = 1;
    for (register int j = 29; j >= 0; j--) {
      int nws = ((a[i] >> j) & 1), dk = ((kth >> j) & 1);
      if (dk == 0) {
        tm += z[z[rt].ch[nws ^ 1]].sz;
        ans += calc(z[z[rt].ch[nws ^ 1]].l, z[z[rt].ch[nws ^ 1]].r, a[i]);
        rt = z[rt].ch[nws];
      } else {
        rt = z[rt].ch[nws ^ 1];
      }
    }
  }
}
int main() {
  n = read(), k = read();
  k <<= 1;
  for (int i = 1; i <= n; i++) {
    a[i] = read();
  }
  sort(a + 1, a + n + 1);
  pre_sum();
  z[1].l = 1, z[1].r = n;
  for (int i = 1; i <= n; i++) {
    insert(i, a[i]);
  }
  get_kth();
  ans += kth * (k - tm);
  ans >>= 1;
  ans %= 1000000007;
  printf("%lld\n", ans);
  return 0;
}
