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: Accepted)

//
//  main.cpp
//  Contests
//
//  Created by Roman Nikitin on 09.06.17.
//  Copyright © 2017 NikRom. All rights reserved.
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
#include <numeric>
#include <queue>
#include <chrono>
#include <functional>

using namespace std;

#define int long long
#define len(v) (int)v.size()
#define pb push_back
#define x first
#define y second

typedef long long ll;

namespace ConvenientStream {
    
    void useFiles(string s) {
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
    
    template <class T_First, class T_Second>
    ostream& operator<<(ostream& os, const pair<T_First, T_Second> &p) {
        os << p.first << " " << p.second;
        return os;
    }
    
    template <class T>
    ostream& operator<<(ostream& os, const vector<T> &v) {
        if (v.empty())
            return os;
        for (int i = 0; i < len(v) - 1; i++) {
            os << v[i] << " ";
        }
        os << v[len(v) - 1];
        return os;
    }
    
    template <class T>
    ostream& operator<<(ostream& os, const vector<vector<T>> &v) {
        if (v.empty())
            return os;
        for (int i = 0; i < len(v) - 1; i++) {
            os << v[i];
            os << endl;
        }
        os << v[len(v) - 1];
        return os;
    }
    
    
    template <class T_First, class T_Second>
    istream& operator>>(istream& is, pair<T_First, T_Second> &p) {
        is >> p.first >> p.second;
        return is;
    }
    
    template <class T>
    istream& operator>>(istream& is, vector<T> &v) {
        for (auto &x : v) {
            is >> x;
        }
        return is;
    }
    
    template<class T>
    istream &operator,(istream &is, T &obj) {
        is >> obj;
        return is;
    }
    
    template<class T>
    ostream &operator,(ostream &os, const T &obj) {
        return (os << obj);
    }
    
    const string nl = "\n";
    const string sp = " ";
    const string tb = "\t";
}

using namespace ConvenientStream;

void time_debug(function<void()> &f) {
    auto start_time = chrono::high_resolution_clock::now();
    f();
    auto end_time = chrono::high_resolution_clock::now();
    auto delta = chrono::duration_cast<chrono::milliseconds>(end_time - start_time);
    cout << "TIME: " << delta.count() << " ms" << endl;
}

int d[52][52];

signed main() {

    int n, p;
    cin >> n >> p;
    vector<int> mas(n);
    cin >> mas;
    
    d[0][0] = 1;
    d[0][1] = 0;
    
    for (int i = 0; i < n; i++) {
        if (mas[i] % 2) {
            d[i + 1][1] = d[i + 1][0] = d[i][1] + d[i][0];
        }
        else {
            d[i + 1][1] += d[i][1] * 2;
            d[i + 1][0] += d[i][0] * 2;
        }
    }
    
    cout << d[n][p];
    
    return 0;
}