#include <bits/stdc++.h>
char ch;
template <class T>
inline void read(T &x) {
  x = 0;
  ch = getchar();
  while (ch <= 32) ch = getchar();
  while (ch > 32) {
    x = x * 10 + ch - 48;
    ch = getchar();
  };
};
unsigned int a[50005];
unsigned int sums[50005 * 2][30];
int cnt;
struct tnode {
  tnode *s[2];
  int cnt;
  unsigned int *sum;
} * tot, *root;
tnode _tr[50005 * 31];
inline tnode *newtnode() {
  *++tot = (tnode){{_tr, _tr}, 0};
  return tot;
};
inline void insert(tnode *a, unsigned int x) {
  int i, t;
  for (i = 29; i >= 0; i--) {
    t = (x >> i) & 1;
    if (a->s[t] == _tr) {
      a->s[t] = newtnode();
    };
    a = a->s[t];
    ++a->cnt;
  };
};
inline unsigned int *newsum(unsigned int x, unsigned int y) {
  unsigned int *ret = sums[++cnt];
  int i;
  for (i = 29; i >= 0; i--) ret[i] = y * ((x >> i) & 1);
  return ret;
};
inline unsigned int *mergesum(unsigned int *a, unsigned int *b) {
  unsigned int *ret = sums[++cnt];
  int i;
  for (i = 29; i >= 0; i--) ret[i] = a[i] + b[i];
  return ret;
};
inline void dfs(tnode *a, unsigned int x, int i) {
  if (a == _tr) return;
  if (i < 0) {
    a->sum = newsum(x, a->cnt);
    return;
  };
  if (a->s[0] != _tr) dfs(a->s[0], x, i - 1);
  if (a->s[1] != _tr) dfs(a->s[1], x | (1 << i), i - 1);
  if (a->s[0] != _tr && a->s[1] != _tr) {
    a->sum = mergesum(a->s[0]->sum, a->s[1]->sum);
  } else if (a->s[0] != _tr) {
    a->sum = a->s[0]->sum;
  } else if (a->s[1] != _tr) {
    a->sum = a->s[1]->sum;
  };
};
tnode *rt[50005];
unsigned long long _sum[31];
inline void getsum(unsigned int *a, unsigned int k, unsigned int cnt) {
  if (!a) return;
  int i;
  for (i = 29; i >= 0; i--) _sum[i] += ((k >> i) & 1) ? cnt - a[i] : a[i];
};
int main() {
  int n;
  unsigned long long m;
  read(n);
  read(m);
  m *= 2;
  int i, j;
  tot = _tr;
  *_tr = (tnode){{_tr, _tr}, 0};
  root = newtnode();
  for (i = 1; i <= n; i++) {
    read(a[i]);
    insert(root, a[i]);
  };
  dfs(root, 0, 29);
  for (i = 1; i <= n; i++) rt[i] = root;
  unsigned int x = 0;
  unsigned int sum = 0;
  for (i = 29; i >= 0; i--) {
    unsigned int tmp = 0;
    for (j = 1; j <= n; j++) {
      unsigned int t = (a[j] >> i) & 1;
      tmp += rt[j]->s[t ^ 1]->cnt;
    };
    unsigned int t1 = 1;
    if (tmp < m) {
      t1 = 0;
      m -= tmp;
      for (j = 1; j <= n; j++) {
        unsigned int t = (a[j] >> i) & 1;
        getsum(rt[j]->s[t ^ 1]->sum, a[j], rt[j]->s[t ^ 1]->cnt);
      };
    } else {
      x |= 1 << i;
    };
    for (j = 1; j <= n; j++) {
      unsigned int t = (a[j] >> i) & 1;
      rt[j] = rt[j]->s[t ^ t1];
    };
  };
  for (i = 29; i >= 0; i--)
    sum = (sum + _sum[i] % 1000000007u * (1ull << i)) % 1000000007u;
  sum = (sum + m * x) % 1000000007u;
  sum = sum * 500000004LL % 1000000007u;
  printf("%d\n", sum);
}
