#include <bits/stdc++.h>
using namespace std;
class Input {
 private:
  char buf[1000000], *p1 = buf, *p2 = buf;

 public:
  inline char gc() {
    if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
    return p1 == p2 ? EOF : *(p1++);
  }
  template <typename T>
  inline Input &operator>>(T &n) {
    n = 0;
    register int ch = gc(), f;
    while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
    f = (ch == '-' ? ch = gc(), -1 : 1);
    while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
    n *= f;
    return *this;
  }
} fin;
class Output {
 private:
  char ouf[1000000], *P1 = ouf, *P2 = ouf;
  char Of[105], *O1 = Of, *O2 = Of;

 public:
  inline void Flush() {
    fwrite(ouf, 1, P2 - P1, stdout);
    P2 = P1;
  }
  inline void pc(char ch) {
    *(P2++) = ch;
    if (P2 == P1 + 1000000) Flush();
  }
  template <typename T>
  inline Output &operator<<(T n) {
    if (n < 0) pc('-'), n = -n;
    if (n == 0) pc('0');
    while (n) *(O1++) = (n % 10) ^ 48, n /= 10;
    while (O1 != O2) pc(*(--O1));
    return *this;
  }
  inline Output &operator<<(char ch) {
    pc(ch);
    return *this;
  }
  ~Output() { Flush(); }
} fout;
int const MAXN = 5e4 + 5;
int const BI = 29;
int a[MAXN];
struct Node {
  unsigned short a[2][BI + 1];
  Node() { memset(a, 0, sizeof(a)); }
  Node(int x) {
    *this = Node();
    for (register int i = BI; ~i; --i) ++a[(x >> i) & 1][i];
  }
  Node operator+(const Node &A) const {
    Node re;
    for (register int i = BI; ~i; --i) {
      re.a[0][i] = a[0][i] + A.a[0][i];
      re.a[1][i] = a[1][i] + A.a[1][i];
    }
    return re;
  }
} sum[MAXN * (BI + 2)];
unsigned short size[MAXN * (BI + 2)];
int child[MAXN * (BI + 2)][2], nodecnt;
int T[MAXN];
long long ans;
void Clone(int &now) {
  int tmp = ++nodecnt;
  sum[tmp] = sum[now];
  size[tmp] = size[now];
  child[tmp][0] = child[now][0];
  child[tmp][1] = child[now][1];
  now = tmp;
}
void Ins(int &now, int v, int bit, const Node &tmp) {
  Clone(now);
  sum[now] = sum[now] + tmp;
  ++size[now];
  if (bit == -1) return void();
  Ins(child[now][(v >> bit) & 1], v, bit - 1, tmp);
}
int Qry(int &now, int v, int bit, int lim, int op) {
  if (bit == -1) {
    if (op == 1)
      for (register int i = BI; ~i; --i)
        ans += 1ll * (1 << i) * (sum[now].a[((v >> i) & 1) ^ 1][i]);
    return size[now];
  }
  int re = 0;
  if ((lim >> bit) & 1) {
    re += Qry(child[now][((v >> bit) & 1) ^ 1], v, bit - 1, lim, op);
  } else {
    if (op == 1)
      for (register int i = BI; ~i; --i)
        ans += 1ll * (1 << i) *
               (sum[child[now][((v >> bit) & 1) ^ 1]].a[((v >> i) & 1) ^ 1][i]);
    re += size[child[now][((v >> bit) & 1) ^ 1]];
    re += Qry(child[now][(v >> bit) & 1], v, bit - 1, lim, op);
  }
  return re;
}
int Check(const int &n, int mid, int op) {
  int re = 0;
  for (register int i = 1; i <= n; ++i) re += Qry(T[i], a[i], BI, mid, op);
  return re;
}
int main() {
  int n, m;
  fin >> n >> m;
  if (m == 0) return puts("0"), 0;
  for (register int i = 1; i <= n; ++i) {
    fin >> a[i];
    Node tmp = Node(a[i]);
    T[i] = T[i - 1];
    Ins(T[i], a[i], BI, tmp);
  }
  int l = 0, r = (1 << (BI + 1)) - 1, mid, ans = 0;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (Check(n, mid, 0) >= m)
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  int sz = Check(n, ans + 1, 1);
  ::ans += 1ll * (m - sz) * ans;
  fout << ::ans % int(1e9 + 7) << '\n';
  return 0;
}
