#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int a[3500];
int Hash[3500];
int main()
{
int n,p,t;
while(~scanf("%d%d",&n,&p))
{
memset(Hash,-1,sizeof(Hash));
for(int i = 0; i < n; i ++)
{
scanf("%d", &a[i]);
}
for(int i = 0; i < n; i ++)
{
t = a[i] % p;
if(Hash[t] == a[i]) a[i] = t; //如果在这个之前存过,而且没有经过线性探测,就是存在的她自己,那么就不用再找其他的了
else if(Hash[t] == -1) // 如果没有数,也不用探测,直接存入
{
Hash[t] = a[i];
a[i] = t;
}
else //如果这个位置有数了,就需要一个一个往后找
{
for(t = t + 1;;t ++)
{
if(Hash[t % p] == a[i]) // 先判断往后找的这个地方是不是已经存过这个数了,如果存过了,就不用再存放了
{
a[i] = t % p;
break;
}
if(Hash[t % p] == -1) //这个数第一次出现,需要存起来
{
Hash[t%p] = a[i];
a[i] = t % p;
break;
}
}
}
}
for(int i = 0; i < n; i ++)
{
if(i == 0) printf("%d",a[i]);
else printf(" %d",a[i]);
}
printf("
");
}
return 0;
}