CF BUDDY
← Problems·

1305C · Kuroni and Impossible Calculation

1600 · brute force, combinatorics, math

Problem: To become the king of Codeforces, Kuroni has to solve the following problem.

He is given nn numbers a1,a2,,ana_1, a_2, \dots, a_n. Help Kuroni to calculate 1i<jnaiaj\prod_{1\le i<j\le n} |a_i - a_j|. As result can be very big, output it modulo mm.

If you are not familiar with short notation, 1i<jnaiaj\prod_{1\le i<j\le n} |a_i - a_j| is equal to a1a2a1a3|a_1 - a_2|\cdot|a_1 - a_3|\cdot \dots a1ana2a3a2a4\cdot|a_1 - a_n|\cdot|a_2 - a_3|\cdot|a_2 - a_4|\cdot \dots a2an\cdot|a_2 - a_n| \cdot \dots an1an\cdot |a_{n-1} - a_n|. In other words, this is the product of aiaj|a_i - a_j| for all 1i<jn1\le i < j \le n.

Input Format: The first line contains two integers nn, mm (2n21052\le n \le 2\cdot 10^5, 1m10001\le m \le 1000) — number of numbers and modulo.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (0ai1090 \le a_i \le 10^9).

Output Format: Output the single number — 1i<jnaiajmodm\prod_{1\le i<j\le n} |a_i - a_j| \bmod m.

Note: In the first sample, 85=33mod10|8 - 5| = 3 \equiv 3 \bmod 10.

In the second sample, 141545=341=120mod12|1 - 4|\cdot|1 - 5|\cdot|4 - 5| = 3\cdot 4 \cdot 1 = 12 \equiv 0 \bmod 12.

In the third sample, 141949=385=1201mod7|1 - 4|\cdot|1 - 9|\cdot|4 - 9| = 3 \cdot 8 \cdot 5 = 120 \equiv 1 \bmod 7.

Sample Cases

Case 1

Input

2 10
8 5

Output

3

Case 2

Input

3 12
1 4 5

Output

0

Case 3

Input

3 7
1 4 9

Output

1

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback