## Modulo Sort

View as PDF

Points: 5 (partial)
Time limit: 0.5s
Memory limit: 256M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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.

For 20% of the marks, .

For an additional 20% of the marks, .

#### Sample Input 1

4
4
68 19 14 62

#### Sample Output 1

68 14 62 19

#### Explanation for Sample Output 1

The first number, . The next numbers 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