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.

为了成为Codeforce的王者,Kuroni必须解决以下问题。

给他n个数字a1,a2,…,an。 帮助Kuroni计算∏1≤i <j≤n| ai-aj |。 结果可能非常大,以模m形式输出。

如果您不熟悉缩写符号,,1≤i<j≤n| ai-aj | 等于| a1-a2 |⋅| a1-a3 |⋅…⋅| a1-an |⋅| a2-a3 |⋅| a2-a4 |⋅…⋅| a2-a |⋅…⋅| an-1- an |。 换句话说,这是| ai-aj |的乘积 对于所有1≤i<j≤n。

输入值
第一行包含两个整数n,m(2≤n≤2⋅105,1≤m≤1000)-数字和模数。

第二行包含n个整数a1,a2,…,an(0≤ai≤109)。

输出量
输出单个数字— ∏1≤i <j≤n| ai-aj | modm。


输入

2 10
8 5
输出
3
输入
3 12
1 4 5
输出
0
输入
3 7
1 4 9
输出
1
注意
在第一个样本中,| 8-5 | =3≡3mod10。

在第二个样本中,| 1-4 |⋅| 1-5 |⋅| 4-5 | =3⋅4⋅1=12≡0mod12。

在第三个样本中,| 1-4 |⋅| 1-9 |⋅| 4-9 | =3⋅8⋅5=120≡1mod7。

题目大意:给出一组数字a,比如n等于4时,ai<aj,求| a1-a2 | · … · | a3-a4 | %m的值。

解题思路:只需要判断n和m的关系即可。如果n>m,则一定有两个数%m的值时一样的,也就是最后的答案一定是0。为什么这么说呢,抽屉原理:有大于n个物品放入n个抽屉,则至少有一个抽屉里的东西不少于2个。n>m 有n个数,分别对m取模,则至少有两个数是一样的,即一定有至少两个数同余,同余的数相减一定是m的倍数,所以mod m一定为0。如果n<=m,暴力求解即可。
AC代码:

#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;
}

CodeForces 1305C-Kuroni and Impossible Calculation(抽屉原理)相关推荐

  1. CodeForces - 1305C Kuroni and Impossible Calculation(鸽巢原理)

    题目链接:点击查看 题目大意:给出 n 个数,输出两两绝对值之差相乘对 m 取模后的答案 题目分析:读完题后乍一看感觉 n 很大,不能 n * n 暴力解决,但是发现 m 非常小,因为有了 m 的限制 ...

  2. Ozon Tech Challenge 2020 (Div.1 + Div.2) C. Kuroni and Impossible Calcul 抽屉原理

    传送门 文章目录 题意: 思路: 题意: 给你一个数组ana_nan​,求∏1≤i<j≤n∣aj−ai∣modm\begin{matrix} \prod_{1\le i<j\le n} | ...

  3. Codeforce-Ozon Tech Challenge 2020-C. Kuroni and Impossible Calculation(鸽笼原理)

    To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a ...

  4. Kuroni and Impossible Calculation CodeForces - 1305C(鸽巢原理)

    To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a ...

  5. [codeforces 1359A] Berland Poker 抽屉原理

    Educational Codeforces Round 88 (Rated for Div. 2)  参赛人数19992 [codeforces 1359A]    Berland Poker   ...

  6. 【CodeForces - 485A】Factory (水题,抽屉原理,tricks)

    题干: One industrial factory is reforming working plan. The director suggested to set a mythical detai ...

  7. 牛客算法周周练2 B Music Problem(DP,抽屉原理,二进制拆分)

    链接:https://ac.nowcoder.com/acm/contest/5203/B 来源:牛客网 题目描述 Listening to the music is relax, but for o ...

  8. B. Combinatorics Homework(抽屉原理)

    Educational Codeforces Round 114 (Rated for Div. 2) 题意 给出字符a,b,c的数量,判断是否可以组成一个字符串,仅有m对相邻的字符相同.(需要用完所 ...

  9. poj2356(抽屉原理)

    题意:从输入的N个元素中找出是N的倍数的元素并且输出: 因为这个要求的是连续的数之和,先用sum数组求和:sum[1],sum[1]+sum[2],--,sum[1]+sum[2]+--+sum[n] ...

  10. POJ 2356 Find a multiple (抽屉原理)

    感觉这个题很不错,至少开始真的没想道可以用抽屉原理推出一个结论,然后把这题秒掉.... 已知有n个元素,sum[i]表示从1到i所有数的和...sum[i]%n可以得到一个剩余系,如果出现0,那么结果 ...

最新文章

  1. Xcode 7错误:“缺少iOS分发签名身份...”
  2. java删除第一个节点_访问单个节点的删除(Java)
  3. sdut-3102小鑫追女神
  4. 文件 在线压缩 技术
  5. 用Sql添加删除字段,判断字段是否存在的方法
  6. 3d点击_3D打印服务加工在医疗器械行业的应用
  7. 树(5)-----判断两颗树一样或者一棵树是否是另外一颗的子树
  8. 工具使用-curl/wget
  9. 离散数学:等价关系与集合覆盖
  10. MY CSDB BLOG 第一篇
  11. 火焰之纹章java武器代码_《火焰纹章回声:另一个英雄王》金手指全代码一览 代码大全...
  12. 高清 GJB-5000B,2021最新版发布,软件能力成熟度模型
  13. 我的世界服务器显示红心,我的世界手机版红心怎么恢复 | 手游网游页游攻略大全...
  14. 远程桌面连接计算机下拉记录清除,如何清除“远程桌面连接”中的历史记录
  15. 3.3 三角函数的积化和差与和差化积
  16. 软考中级 真题 2014年下半年 系统集成项目管理工程师 基础知识 上午试卷
  17. oracle查询当前归档scn_Oracle查询归档日志
  18. Spring系列第2篇:控制反转(IoC)与依赖注入(DI),晦涩难懂么?
  19. 计算机为什么检测不到u盘启动项,电脑无法识别U盘启动BIOS里面找不到U盘启动项...
  20. 商标被撤三了,重新注册有用吗?

热门文章

  1. 测试基础(三)No Risk, No Test,证实和证伪相结合
  2. 思维导图 基础篇(06)思维方法-曼陀罗思考法
  3. 论文阅读: Inertia Tensor Properties in Robot Dynamics Identification: A Linear Matrix Inequality Approac
  4. 【微信云开发】简记操作:删除云开发环境
  5. 葫芦娃手游服务器未响应,葫芦娃手游闪退解决方法_葫芦娃手游闪退原因_玩游戏网...
  6. cx_oracle clob字段入库报错ORA-24816: Expanded non LONG bind data supplied after actual LONG or LOB column
  7. 《第四部分-练习题:微信朋友圈、支付宝支付功能测试点》
  8. mysql支付账单怎么设计_订单与支付设计
  9. bzoj1208 [HNOI2004]宠物收养所
  10. Java使用PDFBox将多个PDF合并为单个PDF