#P2119. Magic War: Counting Magic Array Occurrences
Magic War: Counting Magic Array Occurrences
Magic War: Counting Magic Array Occurrences
During the once-in-sixty-years magic war, the great magician gathers magical energy from nearby magic fields. He possesses m magical items numbered from 1 to m, and each item has a magic value denoted by (X_i) (a positive integer not exceeding n). Note that several items might share the same magic value.
The magician defines a magic array (or formation) if and only if there exist four distinct items with indices (a, b, c, d) such that (X_a < X_b < X_c < X_d) and the following two conditions hold:
1. (X_b - X_a = 2,(X_d - X_c))
2. (X_b - X_a < \frac{X_c - X_b}{3}) (equivalently, (3(X_b - X_a) < X_c - X_b)).
In such a case, the items (a, b, c, d) are designated as items A, B, C, and D of that magic array, respectively.
Your task is to determine, for each of the m magical items, how many times it appears as an A item, as a B item, as a C item, and as a D item, across all possible magic arrays.
inputFormat
The first line contains two integers (m) and (n) (the number of magical items and the maximum possible magic value, respectively).
The second line contains (m) positive integers (X_1, X_2, \ldots, X_m), where each (X_i) denotes the magic value of the i-th item.
outputFormat
Output (m) lines. The i-th line should contain four integers separated by a single space, representing the number of times the i-th item appears as the A item, B item, C item, and D item in all valid magic arrays, respectively.
sample
4 11
1 3 10 11
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
</p>