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 Rust (1.15.1) (judge verdict: Accepted)

use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const MOD: i64 = 1e+9 as i64 + 7;
fn count_best_bits(lower: i64, upper: i64) -> i64 {
    if lower == 0 {
        return 0;
    }
    let lower = lower - 1;
    let same = lower & upper;
    let diff = lower ^ upper;
    let lower_mask = (1i64 << (64 - diff.leading_zeros())) - 1;
    let upper_mask = !lower_mask;
    (same & upper_mask).count_ones() as i64 + 1
}
struct Solver {
    n: usize,
    k: i64,
    aseq: Vec<i64>,
    ans_range: HashMap<Vec<i64>, Vec<(i64, i64)>>,
}

impl Solver {
    fn new() -> Solver {
        let n: usize = read();
        let k: i64 = read();
        let mut aseq = vec![0; n];
        for i in 0..n {
            aseq[i] = read();
        }
        aseq.sort();
        Solver {
            n: n,
            k: k,
            aseq: aseq,
            ans_range: HashMap::new(),
        }
    }
    fn make_offset_seq(&self, pow: i64, target_rest: i64) -> Vec<i64> {
        let mut ret = vec![0; self.n];
        for i in 0..self.n {
            ret[i] = self.aseq[i] / pow - (if self.aseq[i] % pow < target_rest {
                1
            } else {
                0
            });
        }
        let min_value = ret[0];
        for i in 0..self.n {
            ret[i] -= min_value;
        }
        ret
    }
    fn calc(&mut self, base: i64) {
        let pow = 1i64 << base;
        let mut rests = vec![0; self.n];
        for i in 0..self.n {
            rests[i] = self.aseq[i] % pow;
        }
        rests.sort();
        rests.dedup();
        // println!("rest: {:?}", rests);
        let mut prev = -1;
        for &rest in rests.iter() {
            let usea = count_best_bits(prev + 1, rest);
            let offset = if self.aseq[0] % pow < rest { 1 } else { 0 };
            let upper = self.aseq[0] / pow - offset;
            let cnt = std::cmp::min(self.k - (usea + base), upper);
            // println!("{} {} {}", usea, base, cnt);
            if cnt >= 0 {
                let range = (upper - cnt, upper);
                let offset_seq = self.make_offset_seq(pow, rest);
                // println!("{:?} {:?}", offset_seq, range);
                self.ans_range
                    .entry(offset_seq)
                    .or_insert(vec![])
                    .push(range);
            }
            prev = rest;
        }
    }
    fn solve(&mut self) -> i64 {
        for i in 0..62 {
            self.calc(i);
        }
        // println!("{:?}", self.ans_range);
        let mut ans: i64 = 0;
        for ranges in self.ans_range.values_mut() {
            ranges.sort();
            let mut prev = ranges[0];
            for &range in ranges.iter() {
                if range.0 <= prev.1 {
                    prev.1 = std::cmp::max(prev.1, range.1);
                } else {
                    ans = (ans + (prev.1 - prev.0 + 1)) % MOD;
                    prev = range;
                }
            }
            ans = (ans + (prev.1 - prev.0 + 1)) % MOD;
        }
        ans
    }
}

fn main() {
    let mut solver = Solver::new();
    let ans = solver.solve();
    println!("{}", ans);
}