#include <bits/stdc++.h>   using namespace std;   int n, a[50100];   long long m, ans;   struct node {     int s, cnt[30];     node *ch[2];     node();   } * tp, *nul, *root[50100];   int getint() {     char ch;     while (!isdigit(ch = getchar()))       ;     int x = ch -  0 ;     for (; isdigit(ch = getchar()); x = x * 10 + ch -  0 )       ;     return x;   }   node::node() { ch[0] = tp, tp = this; }   node *newnode(node *x) {     if (!tp) new node[50000];     node *t = tp;     tp = t->ch[0], *t = *x;     return t;   }   void insert(node *&x, node *y, int w) {     node *ret = newnode(y);     ++(x = ret)->s;     for (int i = 29; i >= 0; --i) {       for (int j = 0; j <= i; ++j) x->cnt[j] += (w >> j) & 1;       int t = (w >> i) & 1;       x->ch[t] = newnode(y = y->ch[t]), ++(x = x->ch[t])->s;     }     x = ret;   }   int main() {     scanf( %d%I64d , &n, &m);     nul = new node, tp = 0;     memset(nul, 0, sizeof(node));     root[1] = nul->ch[0] = nul->ch[1] = nul;     for (int i = 1; i <= n; ++i) insert(root[i + 1], root[i], a[i] = getint());     for (int i = 29; i >= 0; --i) {       long long sum = 0;       for (int j = 2; j <= n; ++j) sum += root[j]->ch[1 ^ ((a[j] >> i) & 1)]->s;       if (sum < m) {         m -= sum, ans += (1LL << i) * sum;         for (int j = 2; j <= n; ++j) {           node *x = root[j]->ch[1 ^ ((a[j] >> i) & 1)];           for (int k = 0; k <= i - 1; ++k)             ans +=                 (1LL << k) * (((a[j] >> k) & 1) ? x->s - x->cnt[k] : x->cnt[k]);           root[j] = root[j]->ch[(a[j] >> i) & 1];         }       } else {         ans += (1LL << i) * m;         for (int j = 2; j <= n; ++j) root[j] = root[j]->ch[1 ^ ((a[j] >> i) & 1)];       }     }     printf( %d n , ans % 1000000007);     return 0;   }   