#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2, class T3 = hash<T1>>   using umap = unordered_map<T1, T2, T3>;   template <class T>   using uset = unordered_set<T>;   template <class T>   using vec = vector<T>;   const long long infll = numeric_limits<long long>::max() >> 1;   const int inf = numeric_limits<int>::max() >> 1;   const int maxN = 2e6 + 1;   const int mod = 1e9 + 7;   const int N = 50001;   const int L = 30;   int n, m, cur;   int arr[N];   struct Trie {     int cnt[maxN];     int nxt[maxN][2];     int bit[maxN][L];   } trie;   void insert(int key) {     int node = 0;     for (int i = L - 1; i >= 0; --i) {       int j = key >> i & 1;       if (!trie.nxt[node][j]) {         trie.nxt[node][j] = ++cur;       }       node = trie.nxt[node][j];     }     trie.cnt[node]++;     for (int i = 0; i < L; ++i) {       if (key >> i & 1) {         trie.bit[node][i]++;       }     }   }   void dfs(int u = 0) {     for (int i = 0; i < 2; ++i) {       int v = trie.nxt[u][i];       if (!v) {         continue;       }       dfs(v);       trie.cnt[u] += trie.cnt[v];       for (int j = 0; j < L; ++j) {         trie.bit[u][j] += trie.bit[v][j];       }     }   }   int cnt_query(int key, int lim) {     int res = 0;     int node = 0;     for (int i = L - 1; i >= 0; --i) {       int j = key >> i & 1;       int k = lim >> i & 1;       if (!k) {         res += trie.nxt[node][j] ? trie.cnt[trie.nxt[node][j]] : 0;         node = trie.nxt[node][!j];       } else {         node = trie.nxt[node][j];       }       if (!node) {         return res;       }     }     res += trie.cnt[node];     return res;   }   int sum_query(int key, int lim) {     int res = 0;     int node = 0;     for (int i = L - 1; i >= 0; --i) {       int j = key >> i & 1;       int k = lim >> i & 1;       if (!k) {         int sum = 0;         for (int b = 0; b < L; ++b) {           int s = trie.cnt[trie.nxt[node][j]];           int x = trie.bit[trie.nxt[node][j]][b];           int c[2] = {s - x, x};           sum += ((1ll * c[key >> b & 1]) << b) % mod;           sum %= mod;         }         res += trie.nxt[node][j] ? sum : 0;         res %= mod;         node = trie.nxt[node][!j];       } else {         node = trie.nxt[node][j];       }       if (!node) {         return res;       }     }     int sum = 0;     for (int b = 0; b < L; ++b) {       int s = trie.cnt[node];       int x = trie.bit[node][b];       int c[2] = {s - x, x};       sum += ((1ll * c[key >> b & 1]) << b) % mod;       sum %= mod;     }     res += sum;     res %= mod;     return res;   }   void input() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> arr[i];       insert(arr[i]);     }     dfs();   }   int count(int q) {     long long res = 0;     for (int i = 1; i <= n; ++i) {       res += cnt_query(~arr[i], q);     }     return res / 2;   }   int compute(int q) {     int res = 0;     for (int i = 1; i <= n; ++i) {       res += sum_query(~arr[i], q);       res %= mod;     }     return 1ll * res * (mod + 1) / 2 % mod;   }   int bin_search(int l, int r) {     while (l < r) {       int q = l + r + 1 >> 1;       if (count(q) < m) {         r = q - 1;       } else {         l = q;       }     }     return l;   }   void solve() {     int q = bin_search(0, inf);     int c = count(q);     int res = compute(q) - 1ll * (c - m) * q % mod;     res += mod;     res %= mod;     cout << res <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     input();     solve();   }