#include <bits/stdc++.h>
using namespace std;
inline void EnableFileIO(const string& fileName, bool local = 0) {
  if (fileName.empty()) return;
  if (local) {
    freopen((fileName + ".in").c_str(), "r", stdin);
    freopen((fileName + ".out").c_str(), "w", stdout);
    return;
  }
  freopen((fileName + ".in").c_str(), "r", stdin);
  freopen((fileName + ".out").c_str(), "w", stdout);
}
const int INF = (1 << 30) - 1;
const long long LINF = (1LL << 61) - 1;
const double EPS = 1e-10, PI = acos(-1);
const int N = 5e4 + 100, L = 31, P = 1e9 + 7;
int tot = 1;
int trans[N * L][2];
short cnt[N * 30];
short sum[N * 30][L][2];
__attribute__((__optimize__("-O3"))) void ins(int k) {
  int u = 1;
  for (int i = L - 1; i >= 0; i--) {
    int c = k >> i & 1;
    if (!trans[u][c]) trans[u][c] = ++tot;
    ++sum[u][i][c];
    u = trans[u][c];
  }
  ++cnt[u];
}
__attribute__((__optimize__("-O3"))) void dfs(int u, int d) {
  if (!u) return;
  dfs(trans[u][0], d - 1);
  dfs(trans[u][1], d - 1);
  cnt[u] = cnt[u] + cnt[trans[u][0]] + cnt[trans[u][1]];
  for (int i = 0; i <= d; i++) {
    sum[u][i][0] += sum[trans[u][0]][i][0] + sum[trans[u][1]][i][0];
    sum[u][i][1] += sum[trans[u][0]][i][1] + sum[trans[u][1]][i][1];
  }
}
int n, m, a[N];
long long mid, num;
__attribute__((__optimize__("-O3"))) int dfs(int u, int d, int eq) {
  if (!u) return 0;
  if (d < 0 || !eq) return cnt[u];
  int cb = mid >> d & 1, cn = num >> d & 1, res = 0;
  if (cb) {
    if (cn) {
      res += dfs(trans[u][0], d - 1, 1);
    } else {
      res += dfs(trans[u][1], d - 1, 1);
    }
  } else {
    if (cn) {
      res += dfs(trans[u][1], d - 1, 1);
      res += dfs(trans[u][0], d - 1, 0);
    } else {
      res += dfs(trans[u][0], d - 1, 1);
      res += dfs(trans[u][1], d - 1, 0);
    }
  }
  return res;
}
__attribute__((__optimize__("-O3"))) inline int check() {
  long long res = 0;
  for (int i = 0; i < n; i++) {
    num = a[i];
    res += dfs(1, L - 1, 1);
  }
  return int(res / 2);
}
__attribute__((__optimize__("-O3"))) pair<long long, long long> dfsans(int u,
                                                                       int d,
                                                                       int eq) {
  if (!u) return make_pair(0, 0);
  long long res = 0, nodes = 0;
  if (d < 0 || !eq) {
    for (int i = 0; i <= d; ++i) {
      int c = num >> i & 1;
      if (c) {
        res += sum[u][i][0] * (1LL << i);
      } else {
        res += sum[u][i][1] * (1LL << i);
      }
    }
    return make_pair(cnt[u], res);
  }
  int cb = mid >> d & 1, cn = num >> d & 1;
  pair<long long, long long> p;
  if (cb) {
    if (cn) {
      p = dfsans(trans[u][0], d - 1, 1);
      res += p.first * (1LL << d) + p.second;
      nodes += p.first;
    } else {
      p = dfsans(trans[u][1], d - 1, 1);
      res += p.first * (1LL << d) + p.second;
      nodes += p.first;
    }
  } else {
    if (cn) {
      p = dfsans(trans[u][1], d - 1, 1);
      res += p.second;
      nodes += p.first;
      p = dfsans(trans[u][0], d - 1, 0);
      res += p.first * (1LL << d) + p.second;
      nodes += p.first;
    } else {
      p = dfsans(trans[u][0], d - 1, 1);
      res += p.second;
      nodes += p.first;
      p = dfsans(trans[u][1], d - 1, 0);
      res += p.first * (1LL << d) + p.second;
      nodes += p.first;
    }
  }
  return make_pair(nodes, res);
}
__attribute__((__optimize__("-O3"))) long long calcans() {
  long long res = 0;
  for (int i = 0; i < n; i++) {
    num = a[i];
    res += dfsans(1, L - 1, 1).second;
  }
  return res / 2;
}
__attribute__((__optimize__("-O3"))) int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; i++) {
    ins(a[i]);
  }
  dfs(1, L - 1);
  long long lb = 0, rb = 2147483647LL;
  while (rb - lb > 1) {
    mid = (lb + rb) >> 1;
    if (check() >= m) {
      lb = mid;
    } else {
      rb = mid;
    }
  }
  mid = lb + 1;
  long long ans = (m - check()) * 1LL * lb;
  mid = lb + 1;
  ans += calcans();
  printf("%lld\n", ans % P);
  return 0;
}
