#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
struct ModInteger {
  int x;
  ModInteger(int x = 0) : x(x) {}
  ModInteger operator+(const int v) {
    return ModInteger(x >= MOD - v ? x - MOD + v : x + v);
  }
  ModInteger operator+(const ModInteger &rhs) {
    return ModInteger(x >= MOD - rhs.x ? x - MOD + rhs.x : x + rhs.x);
  }
  void operator+=(const int v) { x = x >= MOD - v ? x - MOD + v : x + v; }
  void operator+=(const ModInteger &rhs) {
    x = x >= MOD - rhs.x ? x - MOD + rhs.x : x + rhs.x;
  }
  ModInteger operator-(const int v) {
    return ModInteger(x < v ? x - v + MOD : x - v);
  }
  ModInteger operator-(const ModInteger &rhs) {
    return ModInteger(x < rhs.x ? x - rhs.x + MOD : x - rhs.x);
  }
  void operator-=(const int v) { x = x < v ? x - v + MOD : x - v; }
  void operator-=(const ModInteger &rhs) {
    x = x < rhs.x ? x - rhs.x + MOD : x - rhs.x;
  }
  ModInteger operator*(const int v) {
    return ModInteger((long long)x * v % MOD);
  }
  ModInteger operator*(const ModInteger &rhs) {
    return ModInteger((long long)x * rhs.x % MOD);
  }
  void operator*=(const int v) { x = (long long)x * v % MOD; }
  void operator*=(const ModInteger &rhs) { x = (long long)x * rhs.x % MOD; }
  ModInteger operator^(int e) {
    ModInteger res = ModInteger(1), a = *this;
    for (; e; e >>= 1, a *= a)
      if (e & 1) res *= a;
    return res;
  }
  void operator^=(int e) {
    ModInteger res = ModInteger(1), a = *this;
    for (; e; e >>= 1, a *= a)
      if (e & 1) res *= a;
    x = res.x;
  }
  int getValue() { return x; }
};
const int MAXN = 50000;
const int MAXBIT = 30;
int n, m, a[MAXN], sum[MAXBIT][MAXN];
void initSum() {
  for (int i = (0); i < (n); i++) {
    for (int bit = (0); bit < (MAXBIT); bit++) {
      if (a[i] & (1 << bit)) {
        sum[bit][i]++;
      }
    }
  }
  for (int bit = (0); bit < (MAXBIT); bit++) {
    for (int i = (1); i < (n); i++) {
      sum[bit][i] += sum[bit][i - 1];
    }
  }
}
int getSum(int bit, int l, int r) {
  return sum[bit][r] - (l ? sum[bit][l - 1] : 0);
}
int calcSizeGE(int v) {
  int res = 0;
  for (int i = (0); i < (n); i++) {
    int l = i + 1, r = n - 1;
    for (int bit = MAXBIT - 1; bit >= 0; bit--) {
      int partialSum = getSum(bit, l, r);
      if (v & (1 << bit)) {
        if (a[i] & (1 << bit)) {
          r -= partialSum;
        } else {
          l = r - partialSum + 1;
        }
      } else {
        if (a[i] & (1 << bit)) {
          res += r - l + 1 - partialSum;
          l = r - partialSum + 1;
        } else {
          res += partialSum;
          r -= partialSum;
        }
      }
      if (l > r) break;
    }
    if (l <= r) {
      res += r - l + 1;
    }
  }
  return res;
}
ModInteger calcSumGE(int v) {
  ModInteger res = ModInteger(0);
  for (int i = (0); i < (n); i++) {
    int l = i + 1, r = n - 1, prefix = 0;
    for (int bit = MAXBIT - 1; bit >= 0; bit--) {
      int partialSum = getSum(bit, l, r);
      if (v & (1 << bit)) {
        prefix |= 1 << bit;
        if (a[i] & (1 << bit)) {
          r -= partialSum;
        } else {
          l = r - partialSum + 1;
        }
      } else {
        int newl = l, newr = r;
        if (a[i] & (1 << bit)) {
          res += ModInteger(prefix % MOD) * (r - l + 1 - partialSum);
          l = r - partialSum + 1;
          newr = l - 1;
        } else {
          res += ModInteger(prefix % MOD) * partialSum;
          r -= partialSum;
          newl = r + 1;
        }
        if (newl <= newr) {
          for (int bit0 = bit; bit0 >= 0; bit0--) {
            partialSum = getSum(bit0, newl, newr);
            if (a[i] & (1 << bit0)) {
              res += ModInteger(1 << bit0) * (newr - newl + 1 - partialSum);
            } else {
              res += ModInteger(1 << bit0) * partialSum;
            }
          }
        }
      }
      if (l > r) break;
    }
    if (l <= r) {
      res += ModInteger(prefix % MOD) * (r - l + 1);
    }
  }
  return res;
}
int getBound() {
  int res = -1;
  for (int lower = 0, upper = (1 << MAXBIT) - 1; lower <= upper;) {
    int medium = (lower + upper) >> 1;
    if (calcSizeGE(medium) < m) {
      res = medium;
      upper = medium - 1;
    } else {
      lower = medium + 1;
    }
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (n); i++) scanf("%d", &a[i]);
  sort(a, a + n);
  initSum();
  int bound = getBound();
  printf("%d\n", (calcSumGE(bound) +
                  ModInteger((m - calcSizeGE(bound)) % MOD) * (bound - 1))
                     .getValue());
  return 0;
}
