To become the king of Codeforces, Kuroni has to solve the following problem.
He is given n numbers a1,a2,…,an. Help Kuroni to calculate ∏1≤i<j≤n|ai−aj|. As result can be very big, output it modulo m.
If you are not familiar with short notation, ∏1≤i<j≤n|ai−aj| is equal to |a1−a2|⋅|a1−a3|⋅ … ⋅|a1−an|⋅|a2−a3|⋅|a2−a4|⋅ … ⋅|a2−an|⋅ … ⋅|an−1−an|. In other words, this is the product of |ai−aj| for all 1≤i<j≤n.
Input
The first line contains two integers n, m (2≤n≤2⋅105, 1≤m≤1000) — number of numbers and modulo.
The second line contains n integers a1,a2,…,an (0≤ai≤109).
Output
Output the single number — ∏1≤i<j≤n|ai−aj|modm.
Examples
Input
2 10
8 5
Output
3
Input
3 12
1 4 5
Output
0
Input
3 7
1 4 9
Output
1
Note
In the first sample, |8−5|=3≡3mod10.
In the second sample, |1−4|⋅|1−5|⋅|4−5|=3⋅4⋅1=12≡0mod12.
In the third sample, |1−4|⋅|1−9|⋅|4−9|=3⋅8⋅5=120≡1mod7.
In order to become king of Codeforce, Kuroni must address the following issues.
Give him a n numbers a1, a2, ..., an. Help Kuroni computing Π1≤i <j≤n | ai-aj |. The results can be very large, the output modulo m form.
If you are unfamiliar abbreviations ,, 1≤i <j≤n | ai-aj | equal | a1-a2 | ⋅ | a1-a3 | ⋅ ... ⋅ | a1-an | ⋅ | a2-a3 | ⋅ | a2- a4 | ⋅ ... ⋅ | a2-a | ⋅ ... ⋅ | an-1- an |. In other words, this is | ai-aj | product for all 1≤i <j≤n.
The input value
of the first line contains two integers n, m (2≤n≤2⋅105,1≤m≤1000) - Digital and analog to digital.
The second line contains n integers a1, a2, ..., an (0≤ai≤109).
Output
outputs a single digital - Π1≤i <j≤n | ai-aj | modm.
Example
input
2 10
. 8. 5
outputs
3
Input
3 12 is
1. 4. 5
Output
0
Input
3. 7
1. 4. 9
outputs
a
note
in the first sample, | 8-5 | = 3≡3mod10.
In a second sample, | 1-4 | ⋅ | 1-5 | ⋅ | 4-5 | = 3⋅4⋅1 = 12≡0mod12.
In a third sample, | 1-4 | ⋅ | 1-9 | ⋅ | 4-9 | = 3⋅8⋅5 = 120≡1mod7.
Title effect: given a set of numbers a, when n is equal to 4 such as, ai, seeking <aj | a1-a2 | · ... · | a3-a4 | value of% m.
Outline of Solution: Analyzing the relationship can only n and m. If n> m, the values of both must have the same number of% m, which is the last answer must be 0. Why do you say, drawer principle: there are more than n objects into n-drawer, the drawer has at least one thing no less than two. n> m have the number n, modulo m, respectively, at least two numbers are the same, i.e., must have at least two congruent numbers, with the remainder of the subtraction must be a multiple of m, so that a certain mod m 0. If n <= m, violence can be solved.
AC Code:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int _max=2e5+50;
using LL = long long;
int a[_max];
int main()
{
int n,m;
while(cin>>n>>m)
{
for(int i=1;i<=n;i++)
cin>>a[i];
LL ans=1;
if(n>m)
ans=0;
else
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
{
ans*=abs(a[i]-a[j])%m;
ans%=m;
}
cout<<ans<<endl;
}
//system("pause");
return 0;
}