#P2119. [NOIP 2016 普及组] 魔法阵

[NOIP 2016 普及组] 魔法阵

Description

The once-in-60-years magic war is about to begin, and the grand mage is preparing to draw magic energy from nearby magic fields.

The grand mage has mm magic items, numbered 1,2,,m1, 2, \ldots, m. Each item has a magic value, denoted XiX_i for the item with index ii. Each magic value XiX_i is a positive integer not exceeding nn, and multiple items may share the same magic value.

The grand mage believes that a set of four items with indices a,b,c,da, b, c, d forms a magic formation if and only if they satisfy Xa<Xb<Xc<Xd,XbXa=2(XdXc)X_a<X_b<X_c<X_d,X_b-X_a=2(X_d-X_c), and XbXa<(XcXb)/3X_b-X_a<(X_c-X_b)/3. He calls these four items the AA item, BB item, CC item, and DD item of that magic formation, respectively.

Now, the grand mage wants to know, for each magic item, how many times it appears as the AA item in some magic formation, as the BB item, as the CC item, and as the DD item.

Input Format

The first line contains two positive integers n,mn, m separated by a space.

Then follow mm lines, each containing one positive integer. The integer on line i+1i+1 is XiX_i, the magic value of the item with index ii.

It is guaranteed that 1n150001 \le n \le 15000, 1m400001 \le m \le 40000, 1Xin1 \le X_i \le n. Each XiX_i is independently and uniformly generated within the valid range.

Output Format

Output mm lines, each containing 44 integers. The ii-th line contains 44 integers, which are the counts of item ii appearing as the AA, BB, CC, and DD items, respectively.

It is guaranteed that every number in the standard output does not exceed 10910^9. There must be exactly one space between any two adjacent numbers on the same line.

30 8
1
24
7
28
5
29
26
24
4 0 0 0
0 0 1 0
0 2 0 0
0 0 1 1
1 3 0 0
0 0 0 2
0 0 2 2
0 0 1 0
15 15
1 
2 
3 
4 
5
6 
7 
8 
9
10
11
12
13
14
15
5 0 0 0
4 0 0 0
3 5 0 0
2 4 0 0
1 3 0 0
0 2 0 0
0 1 0 0
0 0 0 0
0 0 0 0
0 0 1 0
0 0 2 1
0 0 3 2
0 0 4 3
0 0 5 4
0 0 0 5

Hint

[Sample Explanation 11]

There are 55 magic formations in total, namely:

  • Items 1,3,7,61,3,7,6, with magic values 1,7,26,291,7,26,29;
  • Items 1,5,2,71,5,2,7, with magic values 1,5,24,261,5,24,26;
  • Items 1,5,7,41,5,7,4, with magic values 1,5,26,281,5,26,28;
  • Items 1,5,8,71,5,8,7, with magic values 1,5,24,261,5,24,26;
  • Items 5,3,4,65,3,4,6, with magic values 5,7,28,295,7,28,29.

Take item 55 as an example. It appears once as the AA item and 33 times as the BB item. It does not appear as the CC or DD item. Therefore, the four numbers on that line are 1,3,0,01, 3, 0, 0.

In addition, if we view the output as an mm-by-44 matrix, then the sum of the mm numbers in each column should equal the total number of magic formations. Therefore, if your output does not satisfy this property, it must be incorrect. You can use this property to partially check the correctness of your output.

[Constraints]

Translated by ChatGPT 5