Under construction

Still being built. Things may change

Cowmistry

Time limit1sMemory limit512 MB

Summary
Count the sets of three distinct labels, taken from N disjoint integer intervals, where every pair has XOR at most K, modulo 1e9+7.
Level

Hard8 of 10

Topics
Bit manipulation, Divide and conquer, Combinatorics
Solved
No attempts yet

Problem

Bessie has been procrastinating on her cow-mistry homework and now needs your help! She needs to create a mixture of three different cow-michals. As all good cows know, though, some cow-michals cannot be mixed with each other, or else they will cause an explosion. Two cow-michals with labels aa and bb can only be present in the same mixture if a⊕b≤Ka \oplus b \le K (1≤K≤1091 \le K \le 10^9).

NOTE: Here, a⊕ba\oplus b denotes the bitwise exclusive or of non-negative integers aa and bb. This operation adds each corresponding pair of bits in base 2 and discards the carry. For example,

0⊕0=1⊕1=0,0\oplus 0=1\oplus 1=0, 1⊕0=0⊕1=1,1\oplus 0=0\oplus 1=1, 5⊕7=1012⊕1112=0102=2.5\oplus 7=101_2\oplus 111_2=010_2=2.

Bessie has NN (1≤N≤2⋅1041\le N\le 2\cdot 10^4) boxes of cow-michals. The ii-th box contains cow-michals labeled lil_i through rir_i inclusive (0≤li≤ri≤1090\le l_i \le r_i \le 10^9). No two boxes share a cow-michal. She wants to know how many unique mixtures of three different cow-michals she can create. Two mixtures are different if at least one cow-michal is present in one but not the other. Since the answer may be very large, report it modulo 109+710^9 + 7.

Input

The first line contains two integers NN and KK.

Each of the next NN lines contains two space-separated integers lil_i and rir_i. The boxes are given in increasing order of their contents, so ri<li+1r_i < l_{i+1} for each 1≤i<N1 \le i < N.

Output

Print the number of mixtures of three different cow-michals Bessie can create, modulo 109+710^9 + 7.

Examples2

  1. Example 1

    Input
    1 13
    0 199
    
    Expected output
    4280
    
  2. Example 2

    Input
    6 147
    1 35
    48 103
    125 127
    154 190
    195 235
    240 250
    
    Expected output
    267188