#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 magic items, numbered . Each item has a magic value, denoted for the item with index . Each magic value is a positive integer not exceeding , and multiple items may share the same magic value.
The grand mage believes that a set of four items with indices forms a magic formation if and only if they satisfy , and . He calls these four items the item, item, item, and item of that magic formation, respectively.
Now, the grand mage wants to know, for each magic item, how many times it appears as the item in some magic formation, as the item, as the item, and as the item.
Input Format
The first line contains two positive integers separated by a space.
Then follow lines, each containing one positive integer. The integer on line is , the magic value of the item with index .
It is guaranteed that , , . Each is independently and uniformly generated within the valid range.
Output Format
Output lines, each containing integers. The -th line contains integers, which are the counts of item appearing as the , , , and items, respectively.
It is guaranteed that every number in the standard output does not exceed . 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 ]
There are magic formations in total, namely:
- Items , with magic values ;
- Items , with magic values ;
- Items , with magic values ;
- Items , with magic values ;
- Items , with magic values .
Take item as an example. It appears once as the item and times as the item. It does not appear as the or item. Therefore, the four numbers on that line are .
In addition, if we view the output as an -by- matrix, then the sum of the 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
京公网安备 11011102002149号