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.

mantan_g | 267 |

tushki | 198 |

aksht7 | 182 |

ayush1101 | 128 |

namansharmacse17 | 110 |

ARUN_PUNDIR | 730 |

manishgupta8497 | 627 |

AMAN__JAIN | 625 |

Abhimanyu_kumar | 562 |

AJ786 | 541 |

blackshadows | 5335 |

Ibrahim Nash | 5223 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4584 |

Login to report an issue on this page.