Given an array of non-negative integers and positive integer , sort the elements of the given array in the increasing order of their modulo with . If two or more elements have the same remainder, sort the numbers numerically.
Input Specification
You will receive three lines of input. The first line will contain positive integer , the length of the array.
The next line will contain positive integer , the number you are dividing by.
The final line will contain array . The array will contain non-negative integers. The integers in will never exceed .
Output Specification
On a single line, output the sorted array with a single space between each number.
Subtasks
Subtask 1 [20%]
For 20% of the marks, .
Subtask 2 [20%]
For an additional 20% of the marks, .
Subtask 3 [60%]
No additional constraints.
Sample Input 1
4
4
68 19 14 62
Sample Output 1
68 14 62 19
Explanation for Sample Output 1
The first number is . The next numbers are and . Because , comes first. Finally, that leaves . It comes last because .
Sample Input 2
8
4
1 18 21 27 17 4 4 16
Sample Output 2
4 4 16 1 17 21 18 27
Comments