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. Java内功心法,Set集合的详解

    本人免费整理了Java高级资料,涵盖了Java.Redis.MongoDB.MySQL.Zookeeper.Spring Cloud.Dubbo高并发分布式等教程,一共30G,需要自己领取.传送门:h ...

  2. Flask 教程 第一章:Hello, World!

    本文翻译自The Flask Mega-Tutorial Part I: Hello, World! 一趟愉快的学习之旅即将开始,跟随它你将学会用Python和Flask来创建Web应用.上面的视频包 ...

  3. XML的互相序列化对象

    using System.Xml.Serialization; using System.IO; using System.Xml; namespace Common { public class X ...

  4. nRF24L01+如何检测信道被占用-RSSI寄存器实战分享

    检测信道占用的需求场景 在使用nRF24L01模块做一对多或多对一的组网通信中,大家都会担心一个问题就是在发送的时候,希望不要有其他的模块也进行发送,因为这样就会使无线信号发生碰撞,信道被堵塞,造成通 ...

  5. MySQL 设置表注释

    新增表增加注释 CREATE TABLE sys_tables ( owner ) NOT NULL COMMENT '归属用户', table_name ) NOT NULL COMMENT '表名 ...

  6. [b0036] python 归纳 (二一)_多进程数据共享和同步_服务进程Manager

    # -*- coding: utf-8 -*- """ 多进程数据共享 服务器进程 multiprocessing.Manager 入门使用 逻辑: 20个子线程修改共享 ...

  7. python生产者和消费者模式实现(三)进程池方式

    注意:如果要使用Pool(进程池方式)创建进程,就需要使用multiprocessing.Manager()中的 Queue(),而不是multiprocessing.Queue() import t ...

  8. 渗透测试学习 十、 MSsql注入下

    大纲:MySQL介绍及操作 MySQL注入原理 MySQL注入其他操作 一.MySQL介绍及操作 介绍 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle ...

  9. 如何将MagicaVoxel模型导入UE4中(1)

    前言 当初在选择自己项目的美术风格时,由于自己的美术基础实在是太差,所以选择了体素风格来构建(其实还是MagicaVoxel的建模操作很容易上手),但是将自己千辛万苦做好的模型导入至项目中时,出现了这 ...

  10. JSON理解(一篇就够了)

    可以看看视频讲解,视频几十分钟就结束了 JSON 1.什么是json 其实是一种数据格式的规范,与开发的语言无关,轻量级的数据格式 全称JavaScript Object Notation 2.优点: ...