#include <bits/stdc++.h>
using namespace std;
int n, a[50005], root, cnt, ch[50005 * 30][2], sz[50005 * 30], now[50005],
    T[50005 * 30][30];
long long ans, nn, m;
void insert(int x) {
  int now = root;
  for (int i = 1 << 29; i; i >>= 1) {
    int ha = ((x & i) == 0) ? 0 : 1;
    if (!ch[now][ha]) ch[now][ha] = ++cnt;
    now = ch[now][ha];
    sz[now]++;
    for (int j = 1, jc = 0; j <= i; j <<= 1, jc++) T[now][jc] += (x >> jc) & 1;
  }
}
int main() {
  scanf("%d%I64d", &n, &m);
  m <<= 1;
  root = ++cnt;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), insert(a[i]);
  sz[root] = n;
  for (int i = 1; i <= n; i++) now[i] = root;
  for (int i = 1 << 29; i && m; i >>= 1) {
    long long s = 0;
    for (int j = 1; j <= n; j++) {
      int ha = (i & a[j]) == 0 ? 1 : 0;
      s += sz[ch[now[j]][ha]];
    }
    if (s <= m) {
      for (int j = 1; j <= n; j++) {
        int ha = (i & a[j]) == 0 ? 1 : 0, x = now[j], cc = ch[x][ha],
            ss = sz[cc];
        if (!x) continue;
        ans += ss * nn;
        for (int k = 1, ck = 0; k <= i; k <<= 1, ck++) {
          ans +=
              (long long)(((a[j] >> ck) & 1) ? (ss - T[cc][ck]) : (T[cc][ck]))
              << ck;
        }
        now[j] = ch[x][!ha];
      }
      m -= s;
    } else {
      for (int j = 1; j <= n; j++) {
        int ha = (i & a[j]) == 0 ? 1 : 0;
        now[j] = ch[now[j]][ha];
        nn |= i;
      }
    }
  }
  printf("%d\n", (ans + m * nn) / 2 % 1000000007);
  return 0;
}
