k-sorting
This year, Hrytsko enrolled at the IT University, where he encountered a variety of new subjects—some fascinating, others less so. Among these, Hrytsko has taken a particular liking to "Algorithms and Data Structures." In a recent lecture, the topic of sorting algorithms was discussed. Being an ambitious young individual, Hrytsko aspires to create his own sorting algorithm, which he plans to name after his beloved grandfather. Inspired by Knuth's comprehensive works, Hrytsko decided to innovate an existing sorting algorithm for natural numbers by introducing a unique constraint: two elements can only be swapped if they are comparable by the modulus of a natural number k, meaning they yield the same remainder when divided by k. However, all new methods need testing, so Hrytsko has sought your assistance!
Determine if this new version of the algorithm can successfully sort the given array of natural numbers.
Input
The first line of the input contains two numbers n (1 ≤ n ≤ 1000) and k (1 ≤ k ≤ 10^9)—the number of elements in the array and the modulus used for comparison.
The second line contains n integers a_i—the elements of the array (1 ≤ a_i ≤ 10^9).
Output
Print YES if the algorithm can sort the given array; otherwise, print NO.