Given an array A consisting of integers of size N and 2 additional integers K and X, you need to find the number of subsets of this array of size K, where Absolute difference between the **Maximum** and **Minimum** number of the subset is at most X.

As this number that you need to find can be rather large, print it **Modulo** 10^{9}+7

**Input:**

The first line of input contains T denoting the no of test cases . Then T test cases follow . The first line of each test case contains 3 space separated integers denoting N, K and X. The next line contains N space separated values of the array A[ ] .

**Output:**

For each test case output the required result in a new line, print it **Modulo** 10^{9}+7.

**Constraints:**

1≤N≤5×10^{5}

1≤K≤N

1≤A[i],X≤10^{9}

**Example:
Input:**

2

5 3 5

1 2 3 4 5

8 4 6

2 4 6 8 10 12 14 16

10

5

**Explanation :
For the first test case**

Possible subsets of size 3 are {1,2,3} {1,2,4} {1,2,5} {1,3,4} {1,3,5} {1,4,5} {2,3,4} {2,3,5} {2,4,5} {3,4,5} having difference of maximum and minimum element less than equal to 5.

**For the second test case**

Possible subsets of size 4 are {2,4,6,8} {4,6,8,10} {6,8,10,12} {8,10,12,14} {10,12,14,16} having difference of maximum and minimum element less than equal to 6.

Author: Amit Khandelwal 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

vamsikrishna55 | 162 |

Vagesh Verma | 158 |

UrGuru | 133 |

abducodes | 127 |

Akhil varma | 114 |

abducodes | 683 |

harshtyagi36 | 322 |

Akhil varma | 267 |

arpit_anshuman | 258 |

highway_to_hell | 252 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.