#include <bits/stdc++.h>
using namespace std;
int getint() {
  int ret = 0;
  bool ok = false;
  for (;;) {
    int c = getchar();
    if (c >= '0' && c <= '9')
      ret = (ret << 3) + ret + ret + c - '0', ok = true;
    else if (ok)
      return ret;
  }
}
struct Tnode {
  Tnode *l, *r;
  int s, S[32], x;
  char lv;
  Tnode();
};
Tnode *tp;
Tnode::Tnode() : r(tp) { tp = this; }
inline Tnode *newnode() {
  if (!tp) new Tnode[10000];
  Tnode *ret = tp;
  return tp = tp->r, ret;
}
inline void drop(Tnode *R) { R->r = tp, tp = R; }
inline Tnode *getnew(int s, int x) {
  Tnode *ret = newnode();
  memset(ret, 0, sizeof(Tnode));
  ret->x = x, ret->s = s, ret->lv = -1, ret->l = ret->r = 0;
  for (int i = 0; i <= 31; i++) ret->S[i] = (int)((bool)(x & (1 << i))) * s;
  return ret;
}
inline Tnode *getnew(Tnode *a, Tnode *b) {
  Tnode *ret = newnode();
  memset(ret, 0, sizeof(Tnode));
  ret->l = a, ret->r = b, ret->lv = a ? a->lv + 1 : b->lv + 1,
  ret->s = (a ? a->s : 0) + (b ? b->s : 0);
  for (int i = 0; i <= 31; i++)
    ret->S[i] = (a ? a->S[i] : 0) + (b ? b->S[i] : 0);
  return ret;
}
Tnode *create(int x, int lv) {
  if (lv == -1) return getnew(1, x);
  if (x & (1 << lv)) return getnew(0, create(x, lv - 1));
  return getnew(create(x, lv - 1), 0);
}
Tnode *merge(Tnode *a, Tnode *b) {
  if (!a || !b) return a ? a : b;
  if (a->lv == -1) return getnew(a->s + b->s, a->x);
  Tnode *al = a->l, *ar = a->r, *bl = b->l, *br = b->r;
  drop(b);
  return getnew(merge(al, bl), merge(ar, br));
}
int n, m;
int a[50010];
Tnode *R[50010];
int count(Tnode *R, int x, int xx) {
  if (!R) return 0;
  if (R->lv == -1) return R->s;
  Tnode *a = R->l, *b = R->r;
  if (xx & (1 << R->lv)) swap(a, b);
  if (x & (1 << R->lv)) return count(b, x, xx);
  return (b ? b->s : 0) + count(a, x, xx);
}
long long sum(Tnode *R, int x, int xx) {
  if (!R) return 0;
  long long ret = 0;
  if (R->lv == -1) {
    for (int i = 0; i <= 31; i++)
      if (xx & (1 << i))
        ret += (long long)(R->s - R->S[i]) * (1 << i);
      else
        ret += (long long)R->S[i] * (1 << i);
    return ret;
  }
  Tnode *a = R->l, *b = R->r;
  if (xx & (1 << R->lv)) swap(a, b);
  if (x & (1 << R->lv)) return sum(b, x, xx);
  if (b)
    for (int i = 0; i <= 31; i++)
      if (xx & (1 << i))
        ret += (long long)(b->s - b->S[i]) * (1 << i);
      else
        ret += (long long)b->S[i] * (1 << i);
  return ret + sum(a, x, xx);
}
int main() {
  n = getint(), m = getint();
  if (!m) return puts("0"), 0;
  for (int i = 1; i <= n; i++) a[i] = getint();
  for (int i = 1; i <= n; i++) {
    Tnode *t = create(a[i], 31);
    R[i] = merge(R[i - 1], t);
  }
  int l = 0, r = ~0U >> 1, t;
  while (l + 1 != r) {
    int mid = (l + r) >> 1;
    t = 0;
    for (int i = 1; i <= n; i++) t += count(R[i - 1], mid, a[i]);
    if (t < m)
      r = mid;
    else
      l = mid;
  }
  t = 0;
  for (int i = 1; i <= n; i++) t += count(R[i - 1], l, a[i]);
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    ans = (ans + sum(R[i - 1], l, a[i])) % 1000000007;
  ans = (ans - (t - m) * l) % 1000000007;
  ans = (ans + 1000000007) % 1000000007;
  printf("%I64d\n", ans);
  return 0;
}
