Input Format: The first line consists of two space separated integers N and K. The next line consists of N space separated integers denoting the elements of array A.
You have been given an array A of size N and an integer K. This array consists of N integers ranging from 1 to 10^7. Each element in this array is said to have a Special Weight. The special weight of an element a[i] is a[i]%K.
You now need to sort this array in Non-Increasing order of the weight of each element, i.e the element with the highest weight should appear first, then the element with the second highest weight and so on. In case two elements have the same weight, the one with the lower value should appear in the output first.
Input Format:
The first line consists of two space separated integers N and K. The next line consists of N space separated integers denoting the elements of array A.
Output Format:
Print N space separated integers denoting the elements of the array in the order in which they are required.
Constraints:
1≤N≤10^5
1≤A[i]≤10^7
1≤K≤10^7
Note:
You need to print the value of each element and not their weight.
SAMPLE INPUT
5 2
1 2 3 4 5

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images









