#include <bits/stdc++.h>
using namespace std;
const int maxN = 5e4 + 7;
const int mod = 1e9 + 7;
int a[maxN];
int n;
long long m;
struct node {
  int lson, rson;
  int num;
  short cnt[30][2];
  node() {
    lson = rson = 0;
    num = 0;
    memset(cnt, 0, sizeof(cnt));
  }
} t[maxN * 40];
int cou = 1;
void add(int x) {
  int root = 1;
  for (int i = 29; i >= 0; i--) {
    if ((1 << i) & x) {
      if (t[root].lson == 0) t[root].lson = ++cou;
      root = t[root].lson;
    } else {
      if (t[root].rson == 0) t[root].rson = ++cou;
      root = t[root].rson;
    }
    t[root].num++;
    for (int j = 0; j < 30; j++)
      if ((1 << j) & x)
        t[root].cnt[j][1]++;
      else
        t[root].cnt[j][0]++;
  }
}
bool judge(long long x) {
  long long k = 0;
  for (int i = 1; i <= n; i++) {
    int root = 1;
    for (int j = 29; j >= 0; j--) {
      bool flag;
      if (a[i] & (1 << j))
        flag = 0;
      else
        flag = 1;
      int ls = t[root].lson;
      int rs = t[root].rson;
      if (flag) {
        if (x & (1 << j)) {
          if (t[ls].num == 0) break;
          root = ls;
        } else {
          k += t[ls].num;
          root = rs;
        }
      } else {
        if (x & (1 << j)) {
          if (t[rs].num == 0) break;
          root = rs;
        } else {
          k += t[rs].num;
          root = ls;
        }
      }
      if (j == 0) k += t[root].num;
    }
  }
  return k >= 2LL * m;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) add(a[i]);
  long long L = 0, R = (1LL << 30) - 1;
  long long mid;
  while (L <= R) {
    mid = (L + R) >> 1;
    if (judge(mid))
      L = mid + 1;
    else
      R = mid - 1;
  }
  long long ans = 0;
  long long k = 0;
  for (int i = 1; i <= n; i++) {
    int root = 1;
    for (int j = 29; j >= 0; j--) {
      bool flag;
      if (a[i] & (1 << j))
        flag = 0;
      else
        flag = 1;
      int ls = t[root].lson;
      int rs = t[root].rson;
      if (flag) {
        if (R & (1 << j)) {
          if (t[ls].num == 0) break;
          root = ls;
        } else {
          k += t[ls].num;
          for (int x = 0; x < 30; x++) {
            if (a[i] & (1 << x)) {
              ans += 1LL * (1LL << x) * t[ls].cnt[x][0] % mod;
              ans %= mod;
            } else {
              ans += 1LL * (1LL << x) * t[ls].cnt[x][1] % mod;
              ans %= mod;
            }
          }
          root = rs;
        }
      } else {
        if (R & (1 << j)) {
          if (t[rs].num == 0) break;
          root = rs;
        } else {
          k += t[rs].num;
          for (int x = 0; x < 30; x++) {
            if (a[i] & (1 << x)) {
              ans += 1LL * (1LL << x) * t[rs].cnt[x][0] % mod;
              ans %= mod;
            } else {
              ans += 1LL * (1LL << x) * t[rs].cnt[x][1] % mod;
              ans %= mod;
            }
          }
          root = ls;
        }
      }
    }
  }
  ans = ans * 500000004 % mod;
  k /= 2;
  ans = (ans + 1LL * (m - k) * R) % mod;
  printf("%I64d\n", ans);
  return 0;
}
