#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
  return x * f;
}
inline int first_read() {
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  return ch - '0';
}
inline int digit_read() {
  char ch = getchar();
  if (!isdigit(ch)) return -1;
  return ch - '0';
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
inline void writes(long long x) { write(x), putchar(' '); }
inline void Writes(long long x) { write(x), putchar('\n'); }
int n;
long long A[50050], k, kth_num;
int pos[50050];
int p[50050 * 34][2], num[50050 * 34], cnt = 1;
int lp[50050 * 34], rp[50050 * 34];
int pre[50050][34];
long long ans;
long long get_res(int l, int r, long long x) {
  if (l == 0x3f3f3f3f or r == -1) return 0;
  long long res = 0;
  for (int i = 0; i <= 32; ++i) {
    int num1 = pre[r][i] - pre[l - 1][i];
    int num0 = r - l + 1 - num1;
    if (x >> i & 1)
      res += 1ll * num0 * (1ll << i);
    else
      res += 1ll * num1 * (1ll << i);
  }
  return res;
}
void Insert(int x, long long val, int bit, int loc) {
  if (bit == -1) {
    num[x]++;
    lp[x] = min(lp[x], loc), rp[x] = max(rp[x], loc);
    return;
  }
  int now = val >> bit & 1;
  if (!p[x][now]) p[x][now] = ++cnt;
  Insert(p[x][now], val, bit - 1, loc);
  num[x] = num[p[x][0]] + num[p[x][1]];
  lp[x] = min(lp[p[x][0]], lp[p[x][1]]);
  rp[x] = max(rp[p[x][0]], rp[p[x][1]]);
}
long long Query(int x, long long val, int bit) {
  if (!x) return 0;
  if (bit == -1) return get_res(lp[x], rp[x], val);
  int nowk = kth_num >> bit & 1, nowv = val >> bit & 1;
  if (nowk == 1)
    return Query(p[x][nowv ^ 1], val, bit - 1);
  else if (nowk == 0)
    return get_res(lp[p[x][nowv ^ 1]], rp[p[x][nowv ^ 1]], val) +
           Query(p[x][nowv], val, bit - 1);
  return -1;
}
int oppsite(int i, int bit) {
  int now = A[i] >> bit & 1;
  return num[p[pos[i]][now ^ 1]];
}
void move(int i, int bit, int dir) {
  int now = A[i] >> bit & 1;
  pos[i] = p[pos[i]][now ^ dir];
}
void get_pre() {
  memset(lp, 0x3f, sizeof lp);
  memset(rp, -1, sizeof rp);
  sort(A + 1, A + 1 + n);
  for (int i = 1; i <= n; ++i) Insert(1, A[i], 32, i);
  for (int i = 0; i <= 32; ++i) {
    for (int j = 1; j <= n; ++j)
      pre[j][i] = pre[j - 1][i] + ((A[j] >> i & 1) == 1);
  }
}
void get_kth() {
  for (int i = 1; i <= n; ++i) pos[i] = 1;
  for (int i = 32; i >= 0; --i) {
    long long tot = 0;
    int dir = -1;
    for (int j = 1; j <= n; ++j) tot += oppsite(j, i);
    if (tot >= k)
      kth_num |= 1ll << i, dir = 1;
    else
      k -= tot, dir = 0;
    for (int j = 1; j <= n; ++j) move(j, i, dir);
  }
}
void get_sum() {
  for (int i = 1; i <= n; ++i) {
    ans += Query(1, A[i], 32), ans %= 1000000007;
  }
}
int main() {
  n = read(), k = 2 * read();
  if (k == 0) {
    Writes(0);
    return 0;
  }
  for (int i = 1; i <= n; ++i) A[i] = read();
  get_pre();
  get_kth();
  ans = 1ll * k * kth_num, ++kth_num;
  get_sum();
  Writes(ans * ((1000000007 + 1ll) / 2) % 1000000007);
  return 0;
}
