#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 5e4 + 10;
const long long MAX_LOG = 33;
const long long INF = 2e9 + 10;
const long long Mod = 1e9 + 7;
struct trie {
  long long p;
  int lc, rc, cnt, val[MAX_LOG];
  trie() {
    p = 0;
    lc = -1;
    rc = -1;
    cnt = 0;
    for (long long i = 0; i < MAX_LOG; i++) {
      val[i] = 0;
    }
  }
};
trie tree[35 * MAXN];
int a[MAXN];
long long n, t = 2, rev2;
long long pw(int x, int n) {
  if (n == 0) {
    return 1;
  }
  long long w = pw(x, n / 2);
  w *= w;
  w %= Mod;
  if (n & 1) {
    w *= x;
    w %= Mod;
  }
  return w;
}
void add(int id, long long x, int h) {
  tree[id].cnt++;
  for (int i = 0; i < MAX_LOG; i++) {
    tree[id].val[i] += (((x) >> (i)) & 1);
  }
  if (h == -1) {
    return;
  }
  if (tree[id].lc == -1) {
    tree[id].lc = t++;
  }
  if (tree[id].rc == -1) {
    tree[id].rc = t++;
  }
  if ((((x) >> (h)) & 1)) {
    add(tree[id].rc, x, h - 1);
  } else {
    add(tree[id].lc, x, h - 1);
  }
}
pair<long long, long long> get(int id, long long x, long long goal, int h,
                               bool d) {
  if (tree[id].cnt == 0) {
    return make_pair(0, 0);
  }
  if (h == -1) {
    long long res = 0;
    if (!d) {
      return make_pair(0, tree[id].cnt);
    }
    for (int i = 0; i < MAX_LOG; i++) {
      if ((((x) >> (i)) & 1)) {
        res += (1LL << i) * (tree[id].cnt - tree[id].val[i]);
        res %= Mod;
      } else {
        res += (1LL << i) * (tree[id].val[i]);
        res %= Mod;
      }
    }
    return make_pair(res, tree[id].cnt);
  }
  if (tree[id].lc == -1) {
    tree[id].lc = t++;
  }
  if (tree[id].rc == -1) {
    tree[id].rc = t++;
  }
  if ((((x) >> (h)) & 1) && (((goal) >> (h)) & 1)) {
    return get(tree[id].lc, x, goal, h - 1, d);
  }
  if ((((x) >> (h)) & 1) && !(((goal) >> (h)) & 1)) {
    pair<long long, long long> e = get(tree[id].rc, x, goal, h - 1, d);
    e.second += tree[tree[id].lc].cnt;
    if (!d) {
      return e;
    }
    for (int i = 0; i < MAX_LOG; i++) {
      if ((((x) >> (i)) & 1)) {
        e.first +=
            (1LL << i) * (tree[tree[id].lc].cnt - tree[tree[id].lc].val[i]);
        e.first %= Mod;
      } else {
        e.first += (1LL << i) * (tree[tree[id].lc].val[i]);
        e.first %= Mod;
      }
    }
    return e;
  }
  if (!(((x) >> (h)) & 1) && (((goal) >> (h)) & 1)) {
    return get(tree[id].rc, x, goal, h - 1, d);
  }
  if (!(((x) >> (h)) & 1) && !(((goal) >> (h)) & 1)) {
    pair<long long, long long> e = get(tree[id].lc, x, goal, h - 1, d);
    e.second += tree[tree[id].rc].cnt;
    if (!d) {
      return e;
    }
    for (int i = 0; i < MAX_LOG; i++) {
      if ((((x) >> (i)) & 1)) {
        e.first +=
            (1LL << i) * (tree[tree[id].rc].cnt - tree[tree[id].rc].val[i]);
        e.first %= Mod;
      } else {
        e.first += (1LL << i) * (tree[tree[id].rc].val[i]);
        e.first %= Mod;
      }
    }
    return e;
  }
}
pair<long long, long long> check(long long x, bool d) {
  pair<long long, long long> res = make_pair(0LL, 0LL);
  for (int i = 0; i < n; i++) {
    pair<long long, long long> b = get(1, a[i], x, MAX_LOG - 1, d);
    res.second += b.second;
    res.first += b.first;
    res.first %= Mod;
  }
  res.second /= 2;
  res.first *= rev2;
  res.first %= Mod;
  return res;
}
int main() {
  long long m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    add(1, a[i], MAX_LOG - 1);
  }
  rev2 = pw(2, Mod - 2);
  long long l = 0, r = INF;
  while (true) {
    if (r - l == 1) {
      pair<long long, long long> x = check(l, 1);
      cout << (x.first + ((x.second - m) * (Mod - l)) % Mod) % Mod;
      return 0;
    }
    long long mid = (l + r) / 2;
    if (check(mid, 0).second < m) {
      r = mid;
    } else {
      l = mid;
    }
  }
}
