Problem:
Score : 1200 points

Problem Statement

There are N non-negative integers written on the blackboard: A_1, ..., A_N.

Snuke can perform the following two operations at most K times in total in any order:

Operation A: Replace each integer X on the blackboard with X divided by 2, rounded down to the nearest integer.

Operation B: Replace each integer X on the blackboard with X minus 1. This operation cannot be performed if one or more 0s are written on the blackboard.

Find the number of the different possible combinations of integers written on the blackboard after Snuke performs the operations, modulo 1,000,000,007.

Constraints

1 \leq N \leq 200

1 \leq A_i \leq 10^{18}

1 \leq K \leq 10^{18}

A_i and K are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the number of the different possible combinations of integers written on the blackboard after Snuke performs the operations, modulo 1,000,000,007.

Sample Input 1

2 2
5 7

Sample Output 1

6

There are six possible combinations of integers on the blackboard: (1, 1), (1, 2), (2, 3), (3, 5), (4, 6) and (5, 7).
For example, (1, 2) can be obtained by performing Operation A and Operation B in this order.

Sample Input 2

3 4
10 13 22

Sample Output 2

20

Sample Input 3

1 100
10

Sample Output 3

11

Sample Input 4

10 123456789012345678
228344079825412349 478465001534875275 398048921164061989 329102208281783917 779698519704384319 617456682030809556 561259383338846380 254083246422083141 458181156833851984 502254767369499613

Sample Output 4

164286011

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
 
using namespace std;
 
const long long mod=1000000007;
 
int n,po,l,r,mid,ans1,ans2;
long long xx,d[201],K,ma,k,a[201],mi,ans,tot,f[61][61][2],ff[61][61][2],t[61],tmp,len,m,mii[12001][1001],le,cnt;
string e;
 
struct node
{
	long long b,c,d;
	int po;
}x[201];
 
map<string,int> mmp;
map<string,int>::iterator it;
 
int solve(long long l,long long r)
{
	if (l==0) return 0;
	if (l==1) return 1;
	t[0]=0; l--;
	while (l) t[++t[0]]=l%2,l/=2; len=t[0];
	for (int i=1; i<=(t[0]/2); i++) tmp=t[i],t[i]=t[t[0]-i+1],t[t[0]-i+1]=tmp;
	memset(f,0,sizeof(f));
	f[0][0][1]=1;
	for (int i=1; i<=t[0]; i++)
		for (int l=0; l<=60; l++)
			for (int j=0; j<=1&&j+l<=60; j++)
				if (j>t[i])
					f[i][l+j][0]+=f[i-1][l][0];
				else
				if (j<t[i])
					f[i][l+j][0]+=f[i-1][l][0]+f[i-1][l][1];
				else
					f[i][l+j][0]+=f[i-1][l][0],f[i][l+j][1]+=f[i-1][l][1];
	t[0]=0;
	while (r) t[++t[0]]=r%2,r/=2;
	for (int i=1; i<=(t[0]/2); i++) tmp=t[i],t[i]=t[t[0]-i+1],t[t[0]-i+1]=tmp;
	memset(ff,0,sizeof(ff));
	ff[0][0][1]=1;
	for (int i=1; i<=t[0]; i++)
		for (int l=0; l<=60; l++)
			for (int j=0; j<=1&&j+l<=60; j++)
				if (j>t[i])
					ff[i][l+j][0]+=ff[i-1][l][0];
				else
				if (j<t[i])
					ff[i][l+j][0]+=ff[i-1][l][0]+ff[i-1][l][1];
				else 
					ff[i][l+j][0]+=ff[i-1][l][0],ff[i][j+l][1]+=ff[i-1][l][1];
	for (int i=1; i<=60; i++)
		if (f[len][i][0]+f[len][i][1]!=ff[t[0]][i][0]+ff[t[0]][i][1]) return i;
}
 
bool cmp(node a,node b) {return a.c<b.c;}
 
int main()
{
	scanf("%d%lld",&n,&K); ma=0;
	for (int i=1; i<=n; i++) {scanf("%lld",&a[i]); if (a[i]>ma) ma=a[i];}
	sort(a+1,a+1+n);
	mmp.clear(); ma*=2ll;
	x[0].c=-1; tot=0; cnt=0;
	memset(mii,0,sizeof(mii));
	for (k=1; K>=0&&k<=ma; k*=2ll,K--)
	{
		mi=(1e18)+1;
		for (int i=1; i<=n; i++) 
		{
			x[i].c=a[i]%k; x[i].b=a[i]/k; x[i].d=x[i].b; x[i].po=i;
			if (x[i].b<mi) mi=x[i].b;
		}
		sort(x+1,x+n+1,cmp);
		for (int i=1; i<=n; i++)
		{
			if (mi<0) break;
			if (x[i].c!=x[i-1].c)
			{
				ans=solve(x[i-1].c+1,x[i].c);
				if (ans>K) {if (x[i].b-1<mi) mi=x[i].b-1; x[i].d--; continue;}
				po=1;
				for (int j=1; j<=n; j++) d[x[j].po]=x[j].d;
				e="";
				for (int j=1; j<n; j++) 
				{
					xx=d[j+1]-d[j]; t[0]=0;
					while (xx) t[++t[0]]=xx%94,xx/=94;
					for (int k=1; k<=t[0]; k++) e=e+(char)(t[k]+33);
					e=e+" ";
				}
				it=mmp.find(e);
				if (it==mmp.end()) 
				{
					if (K-ans>mi) tot=(tot+mi+1)%mod;
					else tot=(tot+K-ans+1)%mod;
					cnt++;
					mmp.insert(make_pair(e,cnt));
					mii[cnt][0]=2;
					if (K-ans>mi) m=mi; else m=K-ans;
					mii[cnt][1]=d[1]-m; mii[cnt][2]=d[1];
				} else
				{
					po=mmp[e]; 
					if (K-ans>mi) m=mi; else m=K-ans;
					l=1; r=mii[po][0]; ans1=0; le=d[1]-m; if (le<0) le=0;
					while (l<=r)
					{
						mid=(l+r)>>1;
						if (mii[po][mid]<le) ans1=mid,l=mid+1; else r=mid-1;
					}
					l=1; r=mii[po][0]; ans2=0;
					while (l<=r)
					{
						mid=(l+r)>>1;
						if (mii[po][mid]<=d[1]) ans2=mid,l=mid+1; else r=mid-1;
					}
					if (ans1==ans2)
					{
						if (!(ans1&1)) 
						{
							tot=(tot+d[1]-le+1)%mod;
							mii[po][0]+=2;
							for (int j=mii[po][0]; j>ans1+2; j--) mii[po][j]=mii[po][j-2];
							mii[po][ans1+2]=d[1]; mii[po][ans1+1]=le;
						}
					} else
					{
						if (ans1&1)
						{
							if (ans2&1)
							{
								for (int j=ans1+1; j<ans2; j+=2) tot=(tot+mii[po][j+1]-mii[po][j]-1)%mod;
								mii[po][0]-=ans2-ans1;
								for (int j=ans1+1; j<=mii[po][0]; j++) mii[po][j]=mii[po][j+ans2-ans1];
							} else
							{
								for (int j=ans1+1; j<ans2; j+=2) tot=(tot+mii[po][j+1]-mii[po][j]-1)%mod;
								tot=(tot+d[1]-mii[po][ans2])%mod;
								mii[po][0]-=ans2-ans1-1; mii[po][ans1+1]=d[1];
								for (int j=ans1+2; j<=mii[po][0]; j++) mii[po][j]=mii[po][j+ans2-ans1-1];
							}
						} else
						{
							if (ans2&1)
							{
								tot=(tot+mii[po][ans1+1]-le)%mod;
								for (int j=ans1+2; j<ans2; j+=2) tot=(tot+mii[po][j+1]-mii[po][j]-1)%mod;
								mii[po][0]-=ans2-ans1-1; mii[po][ans1+1]=le;
								for (int j=ans1+2; j<=mii[po][0]; j++) mii[po][j]=mii[po][j+ans2-ans1-1];
							} else
							{
								tot=(tot+mii[po][ans1+1]-le)%mod; tot=(tot+d[1]-mii[po][ans2])%mod;
								for (int j=ans1+2; j<ans2; j+=2) tot=(tot+mii[po][j+1]-mii[po][j]-1)%mod;
								mii[po][0]-=ans2-ans1-2; mii[po][ans1+1]=le; mii[po][ans1+2]=d[1];
								for (int j=ans1+3; j<=mii[po][0]; j++) mii[po][j]=mii[po][j+ans2-ans1-2];
							}
						}
					}
				}
			}
			if (x[i].b-1<mi) mi=x[i].b-1; x[i].d--;
		}
	}
	printf("%lld\n",tot);
	return 0;
}