CF BUDDY
← Problems·

1670F · Jee, You See?

2400 · bitmasks, combinatorics, dp

Problem: During their training for the ICPC competitions, team "Jee You See" stumbled upon a very basic counting problem. After many "Wrong answer" verdicts, they finally decided to give up and destroy turn-off the PC. Now they want your help in up-solving the problem.

You are given 4 integers nn, ll, rr, and zz. Count the number of arrays aa of length nn containing non-negative integers such that:

  • la1+a2++anrl\le a_1+a_2+\ldots+a_n\le r, and
  • a1a2an=za_1\oplus a_2 \oplus \ldots\oplus a_n=z, where \oplus denotes the bitwise XOR operation.

Since the answer can be large, print it modulo 109+710^9+7.

Input Format: The only line contains four integers nn, ll, rr, zz (1n10001 \le n \le 1000, 1lr10181\le l\le r\le 10^{18}, 1z10181\le z\le 10^{18}).

Output Format: Print the number of arrays aa satisfying all requirements modulo 109+710^9+7.

Note: The following arrays satisfy the conditions for the first sample:

  • [1,0,0][1, 0, 0];
  • [0,1,0][0, 1, 0];
  • [3,2,0][3, 2, 0];
  • [2,3,0][2, 3, 0];
  • [0,0,1][0, 0, 1];
  • [1,1,1][1, 1, 1];
  • [2,2,1][2, 2, 1];
  • [3,0,2][3, 0, 2];
  • [2,1,2][2, 1, 2];
  • [1,2,2][1, 2, 2];
  • [0,3,2][0, 3, 2];
  • [2,0,3][2, 0, 3];
  • [0,2,3][0, 2, 3].

The following arrays satisfy the conditions for the second sample:

  • [2,0,0,0][2, 0, 0, 0];
  • [0,2,0,0][0, 2, 0, 0];
  • [0,0,2,0][0, 0, 2, 0];
  • [0,0,0,2][0, 0, 0, 2].

Sample Cases

Case 1

Input

3 1 5 1

Output

13

Case 2

Input

4 1 3 2

Output

4

Case 3

Input

2 1 100000 15629

Output

49152

Case 4

Input

100 56 89 66

Output

981727503

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback