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

inputCopy

2 10

8 5

outputCopy

3

inputCopy

3 12

1 4 5

outputCopy

0

inputCopy

3 7

1 4 9

outputCopy

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.

这就是个鸽笼原理,m<=1000

#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
} #define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 200005
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
int a;
int b[1005], flag;
vector<pair<int, int>> c;
int main()
{
int n, m;
read(n), read(m);
for (int i = 0; i < n; i++)
{
read(a);
int mo = a % m;
b[mo]++;
c.push_back(make_pair(mo, a));
if (b[mo] >= 2)
flag = 1;
// cout << mo << endl;
}
if (flag)
{
puts("0");
return 0;
}
int ans = 1;
for (int i = 0; i < c.size(); i++)
{
for (int j = i + 1; j < c.size(); j++)
{
if (c[i].second > c[j].second)
{
ans *= (c[i].first - c[j].first + m);
}
else
{
ans *= (-c[i].first + c[j].first + m);
}
ans %= m;
}
}
cout << ans << endl;
}

最新文章

  1. C#中 反射中的Assembly(装载程序集):
  2. javascript面向对象(2)
  3. SQL Pass北京举办第11次线下活动,欢迎报名(本次活动特别邀请了来自微软总部Xin Jin博士)
  4. package
  5. 数字字符与金钱RMB之间的转换
  6. Android4.0强制横屏竖屏
  7. 【LeetCode练习题】Merge Sorted Array
  8. c# ThreadPoold使用心得
  9. 经典算法题每日演练——第十六题 Kruskal算法
  10. php的数组与字符串的转换函数整理
  11. Winform DataGridView修改数据源界面不刷新问题
  12. JAVA RPC (三) 之thrift序列化协议入门杂谈
  13. Luogu P2463 [SDOI2008]Sandy的卡片
  14. DevExpress 之 GridControl 自定义列
  15. AI学习吧-公钥私钥、沙箱环境
  16. Windows Defender还原误删文件
  17. 过滤IP地址的正则表达式
  18. [原创] Keil uVision5 下载程序 add flash programming algorithm选项缺少需要的算法解决办法
  19. 检查Makefile中的tab
  20. fzyjojP2931 乱搞

热门文章

  1. 一键创建以太坊ERC20代币教程
  2. 用最新的版本,蹦最野的迪~~~IDE写大数据程序避坑指南
  3. 使用 python 查看谁没有交作业
  4. 天天写order by,你知道Mysql底层执行原理吗?
  5. gdb调试工具常用命令 &amp;&amp; kdb
  6. 2020-3-3 20175110王礼博 《网络对抗技术》Exp1 PC平台逆向破解
  7. 漏洞复现环境集锦-Vulhub
  8. AJ学IOS(21)UIApplication设置程序图标右上⾓红⾊数字_联⺴指⽰器等
  9. 【Java】FlowControl 流程控制
  10. stand up meeting 12/01/2015