Problem:
Score : 200 points

Problem Statement

There are N bags of biscuits. The i-th bag contains A_i biscuits.

Takaki will select some of these bags and eat all of the biscuits inside.
Here, it is also possible to select all or none of the bags.

He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2.
How many such ways to select bags there are?

Constraints

1 \leq N \leq 50

P = 0 or 1

1 \leq A_i \leq 100

Input

Input is given from Standard Input in the following format:

N P
A_1 A_2 ... A_N

Output

Print the number of ways to select bags so that the total number of biscuits inside is congruent to P modulo 2.

Sample Input 1

2 0
1 3

Sample Output 1

2

There are two ways to select bags so that the total number of biscuits inside is congruent to 0 modulo 2:

Select neither bag. The total number of biscuits is 0.

Select both bags. The total number of biscuits is 4.

Sample Input 2

1 1
50

Sample Output 2

0

Sample Input 3

3 0
1 1 1

Sample Output 3

4

Two bags are distinguished even if they contain the same number of biscuits.

Sample Input 4

45 1
17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26

Sample Output 4

17592186044416

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

//AtCoder Grand Contest 017 E - Jigsaw

#include <cstdio>
#include <iostream>
#include <cmath>

using namespace std;

int qr(){int ret = 0,f=1;char ch =getchar();while(!isdigit(ch))f=ch=='-'?-1:1,ch=getchar();while(isdigit(ch))ret=ret*10+ch-'0',ch=getchar();return ret*f;}

#define maxN 100005
#define maxH 205

int indegree[maxH<<2],outdegree[maxH<<2];
int active[maxH<<2];
void read(int x,int y){
    indegree[y]++;
    outdegree[x]++;
}
int f[maxH<<1];
void init(){
    for(int i = 1;i<=(maxH<<1);i++)
        f[i] = i;
}
int gf(int x){
    if(f[x] == x) return x;
    else return f[x] = gf(f[x]);
}
int mer(int x,int y){
    x = gf(x);y = gf(y);
    if(x == y) return 0;
    f[x] = y;
    return 1;
}
int main(){
    init();
    int N = qr(),H = qr();
    int NN = 0;
    int t1,t2,t3,t4,t5,t6;//上 t + maxN 下 t + maxN + maxH
    for(int i = 1;i<=N;i++){
        t1 = qr(),t2 = qr(),t3 = qr(),t4 = qr();
        if(!t3) t5 = t1+H;else t5 = -t3+H;
        if(!t4) t6 = -t2+H;else t6 = t4+H;
        indegree[t6]++;
        outdegree[t5]++;
        if(!active[t5])
            NN++;
        if(!active[t6])
            NN++;
        active[t5] = active[t6] = 1;
        NN -= mer(t5,t6);
    }
    if(NN!=1){
        cout << "NO";
        return 0;
    }
    int mark=1;
    for(int i = 1;i<=H;i++){
        if(indegree[i]<outdegree[i])
            mark=0;
        if(indegree[H+i]>outdegree[H+i])
            mark=0;
    }
    if(mark)
        cout << "YES";
    else cout << "NO";
    /*
    int a=0,b=0;
    for(int i = maxN;i<=maxN + 500;i++){
        if(indegree[i] == outdegree[i])
            continue;
        else {
            if(abs(indegree[i]-outdegree[i])!=1) {cout << "NO";return 0;}
            else {
                //if(i<=maxN+maxH) {
                    if(indegree[i] > outdegree[i])
                        a++;
                    else b++;
                //}else{
                //    if(indegree[i] > outdegree[i])
                //        b++;
                //    else a++;
                //}
            }
            if(a == 2||b == 2){cout << "NO";return 0;}
        }
    }
    if(a == b){cout << "YES";}
    else {cout << "NO";}
    */
    return 0;
}