You are given a sequence of numbers a1, a2, ..., an, and a number m.

Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.

Input

The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.

The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).

Output

In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.

Examples

Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES

Note

In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.

In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.

In the third sample test you need to choose two numbers 3 on the ends.

In the fourth sample test you can take the whole subsequen

OJ-ID:
CodeForce 577B

author:
Caution_X

date of submission:
20191019

tags:
dp

description modelling:
给一个序列,找一个子序列使之mod m =0

major steps to solve it:
dp[i]:表示取模后得到了i
1.遍历序列,对每一个元素更新dp,判断能否得到dp[0]

AC code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[],dp[],tmp[];
int main()
{
ll n,m;
scanf("%lld%lld",&n,&m);
for(int i=;i<n;i++) {
scanf("%lld",&a[i]);
}
for(int i=;i<n;i++) {
if(dp[]) break;
for(int j=;j<=m-;j++) {
if(dp[j]) {
tmp[(j+a[i])%m]=;
}
}
tmp[a[i]%m]=;
for(int j=;j<=m-;j++) {
dp[j]=tmp[j];
}
}
if(dp[]) printf("YES\n");
else printf("NO\n");
return ;
}

CodeForce 577B Modulo Sum的更多相关文章

  1. Codeforces 577B Modulo Sum

    http://codeforces.com/problemset/problem/577/B 题意:有n个数,求有无一个子序列满足和是m的倍数 思路:用模下的背包做,发现n是十的六次方级别,但是有个神 ...

  2. Codeforces 577B Modulo Sum:数学 结论【选数之和为m的倍数】

    题目链接:http://codeforces.com/problemset/problem/448/C 题意: 给你n个数字,给定m. 问你是否能从中选出若干个数字,使得这些数字之和为m的倍数. 题解 ...

  3. codeforces 577B. Modulo Sum 解题报告

    题目链接:http://codeforces.com/problemset/problem/577/B 题目意思:就是给出 n 个数(a1, a2, ..., an) 和 m,问能不能从这 n 个数中 ...

  4. CF 577B Modulo Sum

    题意:给一个长度为n的正整数序列,问能不能找到一个不连续的子序列的和可以被m整除. 解法:抽屉原理+dp.首先当m<n时一定是有答案的,因为根据抽屉原理,当得到这个序列的n个前缀和%m时,一定会 ...

  5. codeforces 577B B. Modulo Sum(水题)

    题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. cf319.B. Modulo Sum(dp && 鸽巢原理 && 同余模)

    B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  7. Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp

    B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...

  8. Modulo Sum(背包 + STL)

     Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  9. Codeforces Round #319 (Div. 2) B. Modulo Sum 抽屉原理+01背包

    B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

随机推荐

  1. jQuery 源码分析(十六) 事件系统模块 底层方法 详解

    jQuery事件系统并没有将事件监听函数直接绑定到DOM元素上,而是基于数据缓存模块来管理监听函数的,事件模块代码有点多,我把它分为了三个部分:分底层方法.实例方法和便捷方法.ready事件来讲,好理 ...

  2. Annotation-specified bean name 'userDaoImpl' for bean class [***] conflicts with existing, non-compatible bean definition of same name and class [***]

    使用Spring开发的时候报错如下: Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionExcept ...

  3. 用友的SPS定义

    基于标准产品的支持服务(Standard Product Support,SPS).主要包括:更新升级(软件补丁更新与产品升级).问题解决(产品问题在线或热线解析).知识转移(用友到客户的知识传递). ...

  4. Python切片中的误区与高级用法

    众所周知,我们可以通过索引值(或称下标)来查找序列类型(如字符串.列表.元组...)中的单个元素,那么,如果要获取一个索引区间的元素该怎么办呢? 切片(slice)就是一种截取索引片段的技术,借助切片 ...

  5. 真机调试(A valid provisioning profile for this executable was not found.)

    这个问题是因为provisioning的问题,因为真机没有加入到账号下面的原因 解决步骤 1.吧identifier复制然后再平开开发中心 2.点击+号添加设备保存 3.在develope中选中保存即 ...

  6. linux系统管理-输入输出

    目录 linux系统管理-输入输出 参数传递xargs linux系统管理-输入输出 重定向 将原本要输出到屏幕上的数据信息,重新定向到指定的文件中 运行程序,或者输入一个命令:默认打开4个文件描述符 ...

  7. hi3559v100 sdk中双系统AMP架构的初步了解

    hi3559v100是海思推出的camera soc处理器.采用的是双核处理器.一个是a7,运行的linux3.18内核.一个是a17使用的是huaweiliteos操作系统,Hi3559V100 系 ...

  8. Python格式化输出和深浅复制

    字符串的四种拼接方法,常用格式化 deepcopy(深复制) bytes 和 bytearray 的基本用法 字符串拼接 使用 + 格式化字符串 使用join 用单引号内的字符来拼接,参数填一个整体 ...

  9. yum / rpm 指令无反应

    当yum 或者 rpm 指令执行后没有任何反馈,可尝试执行以下指令: # rm -f /var/lib/rpm/__db.00* # 删除rpm数据文件 # rpm –rebuilddb # 重建rp ...

  10. AWVS破解安装

    参考大佬@pirogue的安装步骤及awvs安装包,@pandahks的安装依赖,在本地虚拟机安装awvs,艰辛历程记录如下. 虚拟机操作系统:CentOS Linux release 7.7.190 ...