PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000077. Nghịch thế sau khi xoay giá trị (Rotated Inversions)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Nghịch thế sau khi xoay giá trị (Rotated Inversions)

Rotated Inversions

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given positive integers N,MN,M and a sequence A1,A2,…,ANA_1,A_2,\ldots,A_N, where every value lies between 00 and M−1M-1. Duplicate values are allowed.

For each integer k=0,1,…,M−1k=0,1,\ldots,M-1, form a sequence B(k)B^{(k)} by setting Bi(k)=(Ai+k) mod MB^{(k)}_i=(A_i+k)\bmod M. The order of positions does not change: only the values are rotated modulo MM.

The inversion count of B(k)B^{(k)} is the number of index pairs i<ji<j for which Bi(k)>Bj(k)B^{(k)}_i>B^{(k)}_j. Equality must not be counted.

Compute and output the inversion count for every k=0,1,…,M−1k=0,1,\ldots,M-1 in increasing order.

Input

The first line contains integers N,MN,M.

The second line contains NN integers A1,A2,…,ANA_1,A_2,\ldots,A_N.

Output

Print exactly MM lines. Line k+1k+1 contains the inversion count of B(k)B^{(k)}, for 0≤k<M0\le k<M.

Subtasks

  • Subtask 1 (20 points): 1≤N,M≤81\le N,M\le 8; 0≤Ai<M0\le A_i<M for all 1≤i≤N1\le i\le N.

  • Subtask 2 (30 points): 1≤N,M≤20001\le N,M\le 2000; 0≤Ai<M0\le A_i<M for all 1≤i≤N1\le i\le N.

  • Subtask 3 (50 points): 1≤N,M≤2000001\le N,M\le 200000; 0≤Ai<M0\le A_i<M for all 1≤i≤N1\le i\le N.

Examples

Input

3 3
2 1 0

Output

3
1
1

Explanation

With N=M=3N=M=3 and A=[2,1,0]A=[2,1,0], consider all three values of kk:

  • k=0k=0: B(0)=[2,1,0]B^{(0)}=[2,1,0]; all pairs (1,2),(1,3),(2,3)(1,2),(1,3),(2,3) are inversions, so the answer is 33.
  • k=1k=1: B(1)=[0,2,1]B^{(1)}=[0,2,1]; only pair (2,3)(2,3) is an inversion, so the answer is 11.
  • k=2k=2: B(2)=[1,0,2]B^{(2)}=[1,0,2]; only pair (1,2)(1,2) is an inversion, so the answer is 11.

Print 3, 1, 1, one per line.