#include <stdio.h>
#include <stdlib.h>
int main() {
int N, X;
// Input the number of sticker types
scanf("%d", &N);
// Declare an array to store sticker counts
int counts[N];
// Input sticker counts for each type
for (int i = 0; i < N; i++) {
scanf("%d", &counts[i]);
}
// Input the categorization factor
scanf("%d", &X);
// Sort sticker counts based on remainders using bubble sort
for (int i = 0; i < N - 1; i++) {
for (int j = 0; j < N - i - 1; j++) {
int mod_a = counts[j] % X;
int mod_b = counts[j + 1] % X;
if (mod_a > mod_b) {
// Swap counts[j] and counts[j + 1]
int temp = counts[j];
counts[j] = counts[j + 1];
counts[j + 1] = temp;
}
}
}
// Print the refined arrangement of sticker counts
for (int i = 0; i < N; i++) {
printf("%d ", counts[i]);
}
return 0;
}