C, C

Source: Internet
Author: User

C, C
C-NP-Hard ProblemCrawling in process... Crawling failed Time Limit:2000 MSMemory Limit:262144KB64bit IO Format:% I64d & % I64u

Description

Pari wants to buy an expensive chocolate from Arya. She hasNCoins, the value ofI-Th coin isCI. The price of the chocolate isK, So Pari will take a subset of her coins with sum equalKAnd give it to Arya.

Looking at her coins, a question came to her mind: after giving the coins to Arya, what values does Arya can make with them? She is jealous and she doesn't want Arya to make a lot of values. So she wants to know all the valuesX, Such that Arya will be able to makeXUsing some subset of coins with the sumK.

Formally, Pari wants to know the valuesXSuch that there exists a subset of coins with the sumKSuch that some subset of this subset has the sumX, I. e. there is exists some way to pay for the chocolate, such that Arya will be able to make the sumXUsing these coins.

Input

The first line contains two integersNAndK(1 hour ≤ hourN, Bytes,KLimit limit ≤ limit 500)-the number of coins and the price of the chocolate, respectively.

Next line will containNIntegersC1, bytes,C2, middle..., middle ,...,CN(1 digit ≤ DigitCILimit ≤ limit 500)-the values of Pari's coins.

It's guaranteed that one can make valueKUsing these coins.

Output

First line of the output must contain a single integerQ-The number of suitable valuesX. Then printQIntegers in ascending order-the values that Arya can make for some subset of coins of Pari that pays for the chocolate.

Sample Input

Input
6 18
5 6 1 10 12 2
Output
16
0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18
Input
3 50
25 25 50
Output
3
0 25 50

Sample Output

 

Hint

 

Description

Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.

Suppose the graphGIs given. SubsetAOf its vertices is called a vertex cover of this graph, if for each edgeUvThere is at least one endpoint of it in this set, I. e. or (or both ).

Pari and Arya have won a great undirected graph as an award in a team contest. now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover.

They have agreed to give you their graph and you need to find two disjoint subsets of its verticesAAndB, Such that bothAAndBAre vertex cover or claim it's impossible. Each vertex shocould be given to no more than one of the friends (or you can even keep it for yourself ).

Input

The first line of the input contains two integersNAndM(2 cores ≤ CoresNLimit ≤ limit 100 0000000, 1 limit ≤ limitMLimit ≤ limit 100 limit 000)-the number of vertices and the number of edges in the prize graph, respectively.

Each of the nextMLines contains a pair of integersUIAndVI(1 hour ≤ hourUI, Zookeeper,VICommandid ≤ commandidN), Denoting an undirected edgeUIAndVI. It's guaranteed the graph won't contain any self-loops or multiple edges.

Output

If it's impossible to split the graph between Pari and Arya as they before CT, print "-1" (without quotes ).

If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integerKDenoting the number of vertices in that vertex cover, and the second line containsKIntegers-the indices of vertices. Note that becauseMVertex ≥1_1, vertex cover cannot be empty.

Sample Input

Input
4 2
1 2
2 3
Output
1
2
2
1 3
Input
3 3
1 2
2 3
1 3
Output
-1

Sample Output

 

Hint

In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish ).

In the second sample, there is no way to satisfy both Pari and Arya.

 

Question: Tell you xmod (c1, c2, c3...) and ask if you can find xmodk.

 

 

Idea: Determine whether the given c1, c2, c3, and medium quality factors can constitute a multiple of k.

Code:

 

#include <iostream>#include <cstdio>using namespace std;inline int gcd(int a,int b){  if(a%b==0)   return b;   return gcd(b,a%b);}inline int lcm(int a,int b){    return a/gcd(a,b)*b;}int main(){   int n,k;    while(cin>>n>>k)    {     int l=1;       int a;        for(int i=0;i<n;i++)        {   scanf("%d",&a);            int g=gcd(a,k);            l=lcm(l,g);        }        if(l==k)        printf("Yes\n");        else        printf("No\n");    }}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.