import java.util.*;
import static java.lang.System.*;
public class main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNextInt())
{
int num = sc.nextInt();
int m = sc.nextInt();
System.out.printf("%d %d\r\n", num, m);
if(num == 0&& m == 0)
break;
Data[] datas = new Data[num];
for(int i = 0; i < num; i++)
{
int n = sc.nextInt();
datas[i] = new Data(n, n % m, n % 2 == 0);
}
Arrays.sort(datas);
for(int i = 0; i < num; i++)
{
System.out.println(datas[i].toString());
}
}
}
public static class Data implements Comparable
{
int n;
int r;
boolean even;
Data(int n, int r, boolean even)
{
this.n = n;
this.r = r;
this.even = even;
}
public String toString()
{
return Integer.toString(this.n);
}
@Override
public int compareTo(Data other)
{
if(this.r != other.r)
return this.r < other.r ? -1 : 1;
else
{
if(this.even != other.even)
return !this.even ? -1 : 1;
else if(this.even && other.even)
return this.n < other.n ? -1 : 1;
else
return this. n < other.n ? 1 : -1;
}
}
}
};
留言
張貼留言