#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 50, mod = 1e9 + 7;
inline long long read() {
  long long s = 0, w = 1, ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    s = (s << 3) + (s << 1) + ch - 48;
    ch = getchar();
  }
  return s * w;
}
long long n, m, a[maxn], RES, LIM, ans;
long long trie[maxn][2], tot = 1, siz[maxn], ko[31];
unsigned short num[maxn][31];
void add(long long i) {
  for (long long j = 30; j >= 0; j--)
    if (ko[j] == 1) num[i][j]++;
}
void unzip(long long x) {
  for (long long i = 30; i >= 0; i--) {
    long long ch = (x >> i) & 1;
    ko[i] = ch;
  }
}
void insert(long long x) {
  long long pos = 1;
  siz[pos]++;
  unzip(x);
  add(pos);
  for (long long i = 30; i >= 0; i--) {
    long long ch = (x >> i) & 1;
    if (trie[pos][ch] == 0) {
      trie[pos][ch] = ++tot;
    }
    pos = trie[pos][ch];
    siz[pos]++;
    add(pos);
  }
}
void calc(long long x) {
  long long pos = 1;
  for (long long i = 30; i >= 0; i--) {
    if (pos == 0) break;
    long long ch = (x >> i) & 1;
    long long cl = (LIM >> i) & 1;
    if (cl == 0) {
      RES += siz[trie[pos][ch ^ 1]];
      pos = trie[pos][ch];
    } else if (cl == 1) {
      pos = trie[pos][ch ^ 1];
    }
  }
}
void calc_sum(long long x) {
  long long pos = 1;
  unzip(x);
  for (long long i = 30; i >= 0; i--) {
    if (pos == 0) break;
    long long ch = (x >> i) & 1;
    long long cl = (LIM >> i) & 1;
    if (cl == 0) {
      for (long long j = 30; j >= 0; j--) {
        long long po = trie[pos][ch ^ 1];
        if (ko[j] == 0)
          ans = (ans + (1 << j) * (long long)num[po][j] % mod) % mod;
        if (ko[j] == 1)
          ans =
              (ans + (1 << j) * (siz[po] - (long long)num[po][j]) % mod) % mod;
      }
      pos = trie[pos][ch];
    } else
      pos = trie[pos][ch ^ 1];
  }
}
inline long long power(long long a, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1) res = res * a % mod;
    p >>= 1;
    a = (a * a) % mod;
  }
  return res;
}
signed main() {
  n = read();
  m = read();
  for (long long i = 1; i <= n; i++) {
    a[i] = read();
  }
  long long l = 0, r = 2e9;
  for (long long i = 1; i <= n; i++) insert(a[i]);
  while (l + 1 < r) {
    LIM = (l + r) / 2;
    RES = 0;
    long long flag = 0;
    for (long long i = 1; i <= n; i++) {
      calc(a[i]);
      if (RES >= m * 2) {
        flag = 1;
        break;
      }
    }
    if (flag)
      l = LIM;
    else
      r = LIM;
  }
  LIM = r;
  RES = 0;
  for (long long i = 1; i <= n; i++) {
    calc_sum(a[i]), calc(a[i]);
  }
  cout << (ans + (2 * m - RES) * LIM % mod) % mod * power(2, mod - 2) % mod
       << endl;
  return 0;
}
