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 (Python):
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


N, P = map(int, input().split())
A = list(map(int, input().split()))

odd = 0
even = 0
for i in range(N):
    if A[i] % 2 == 0:
        even += 1
    else:
        odd += 1
        
ans = 0
for i in range(P, odd+1, 2):
    ans += cmb(odd, i)
    
ans *= 2 ** even

print(ans)

Solution (Python):
N,P=map(int,input().split())
A=list(map(int,input().split()))
f=0
for i in range(N):
  if A[i]%2==1:
    f=1
if f==0:
  if P==0:
    print(2**N)
  else:
    print(0)
else:
  print(2**(N-1))

Solution (Python):
N, P = map(int, input().split())
A = list(map(int, input().split()))
def comb(x, y):
  m = c = 1
  for i in range(y):
    m *= x-i
    c *= y-i
  return m//c
even = odd = 0
for a in A:
  if a%2 == 0:
    even += 1
  else:
    odd += 1
ans = 0
for i in range(P, odd+1, 2):
  ans += comb(odd, i)
print(pow(2, even) * ans)

Solution (Python):
N, P = map(int, input().split())
A = list(map(int, input().split()))
def comb(x, y):
  m = c = 1
  for i in range(y):
    m *= x-i
    c *= y-i
  return m//c
even = odd = 0
for a in A:
  if a%2 == 0:
    even += 1
  else:
    odd += 1
if P == 0:
  ans = 0
  for i in range(0, odd+1, 2):
    ans += comb(odd, i)
  print(pow(2, even) * ans)
else:
  ans = 0
  for i in range(1, odd+1, 2):
    ans += comb(odd, i)
  print(pow(2, even) * ans)

Solution (Python):
N,P = map(int,input().split())
a_ls = list(map(int, input().split()))


dp = [[0,0] for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    next = (a_ls[i-1])%2
    if next == 0:
        dp[i][0] += 2 * dp[i-1][0]
        dp[i][1] += 2 * dp[i-1][1]
    else:
        dp[i][0] += dp[i-1][0] + dp[i-1][1]
        dp[i][1] += dp[i-1][0] + dp[i-1][1]
print(dp[-1][P])

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n,p = I()
A = [2 if i%2==0 else 1 for i in I()]
a = set(A)



if p == 0:
    if len(a)==1 and 2 in a:
        print(2**n)
    else:
        print(2**(n-1))
else:
    if len(a)==1 and 2 in a:
        print(0)
    else:
        print(2**(n-1))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7

    n,p=MI()
    lis=LI()
    ev=0
    od=0
    for i in range(n):
        if lis[i]%2==0:
            ev+=1
        else:
            od+=1
    ans=0
    for i in range(od+1):
        if i%2==p:
            ans+=factorial(od)//factorial(i)//factorial(od-i)
    ans*=2**ev
    print(ans)

            
        
        







if __name__=="__main__":
    main()

Solution (Python):

def resolve():
    
    N, P = map(int, input().split())
    A = list(map(int, input().split()))

    odds = sum([1 for a in A if a % 2 == 1])

    ans = 0
    if odds == 0:
        if P == 0:
            ans = 2 ** N
    else:
        ans = 2 ** (N - 1)

    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

inf = 10 ** 18
mod = 10 ** 9 + 7




def ruijo(n, l, mod):
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


def cmb(n, r, mod):
    if r == 1:
        return n
    elif (n == r or r == 0):
        return 1
    else:
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return ruijo(n, n - r + 1, mod) * g2[r] % mod


mod = 10 ** 18 + 7  
N = 10 ** 3
g1 = [1, 1]  
g2 = [1, 1]  
inverse = [0, 1]  

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

n,p = lr()
a = [x%2 for x in lr()]
odd_n = sum(a)
even_n = n-odd_n
ans = 0
if p%2 == 0:
    for i in range(0,odd_n+1,2):
        ans += cmb(odd_n, i, mod)
else:
    for i in range(1,odd_n+1,2):
        ans += cmb(odd_n, i, mod)
ans = (2**even_n)*ans
print(ans)

Solution (Python):
n,p=map(int,input().split())
a=[i%2 for i in map(int,input().split())]

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

oishii = a.count(1)

c = sum([cmb(oishii,i) for i in range(p,oishii+1,2)])

print(c*2**(n-oishii))

Solution (Python):
N, P = map(int, input().split())
A = list(map(int, input().split()))
def comb(n, k):
  ret = 1
  for i in range(1, k+1):
    ret = ret * (n+1-i) // i
  return ret
Even = 0
Odd = 0
for a in A:
  if a % 2 == 0:
    Even += 1
  else:
    Odd += 1
ans = 0
while P <= Odd:
  ans += comb(Odd, P)
  P += 2
print(ans * 2 ** Even)

Solution (Python):
N, P = map(int, input().split())
A = [int(i)&1 for i in input().split()]
o = A.count(1)
e = N-o
on = en = 0
def ncr(n, r):
    r = min(r,n-r)
    res=1
    d=1
    for i in range(r):
        res*=n-i
        d *= i + 1
    return res//d

for r in range(e+1):
    en+=ncr(e,r)
for r in range(P, o+1, 2):
    on+=ncr(o,r)

print(on*en)

Solution (Python):
import sys
def input():
  return sys.stdin.readline().rstrip()

N,P=map(int,input().split())
A=list(map(int,input().split()))

temp=0
for i in range(N):
  if A[i]%2==1:
    temp+=1
if temp==0:
  print(1<<N if P == 0 else 0)
else:
  print(1<<(N-1))

Solution (Python):
n, p = map(int, input().split()); a = list(map(int, input().split()))
s = t = u = 0; b = [1]
for i in range(n):
    if a[i]%2 == 0: s += 1
    else: t += 1
for i in range(1, n+1):
    b.append(b[-1]*i)
if p == 0:
    for i in range(0, t//2*2+1, 2):
        u += b[t]//b[i]//b[t-i]
else:
    for i in range(1, (t+1)//2*2, 2):
        u += b[t]//b[i]//b[t-i]
print(2**s*u)

Solution (Python):
import math
from scipy.special import comb
n, p = map(int, input().split())
aa = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
  if aa[i] % 2 == 0:
    even.append(aa[i])
  else:
    odd.append(aa[i])
    
x = len(odd)
y = len(even)


sum1 = 0
for i in range(0, x+1, 2):
  sum1 += comb(x,i)
sum2 = 0
for i in range(1, x+1, 2):
  sum2 += comb(x,i)
  
if p == 0:
  ans = int((2 ** y) * sum1)
else:
  ans = int((2 ** y) * sum2)
print(ans)

Solution (Python):
n,p = map(int, input().split())
a = list(map(int, input().split()))

odd = 0
even = 0

for i in range(n):
  if a[i]%2 == 0:
    even += 1
  else:
    odd += 1

if odd == 0:
  if p == 1:
    print(0)
  else:
    print (2**n)
else:
  print (2**(n-1))

Solution (Python):
import sys









MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n, p = read_ints()
    a = read_int_list()
    for x in a:
        if x % 2 == 1:
            print(pow(2, n - 1))
            break
    else:
        print(0 if p == 1 else pow(2, n))

if __name__ == '__main__':
    Main()

Solution (Python):
n, p = map(int, input().split())
a = list(map(int, input().split()))

m = len([x for x in a if x & 1])

if m == 0:
  if p == 0:
    ans = 2 ** n
  else:
    ans = 0
else:
  ans = 2 ** (n - 1)

print(ans)

Solution (Python):

import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,p=map(int,input().split())
A=list(map(int, input().split()))
AA = [0]*n
for i in range(n):
    if A[i]%2:
        AA[i]=1
sumA = sum(AA)
res1 = 0
for i in range(p,sumA+1,2):
    res1 += comb(sumA,i)
res0 = 2**(n-sumA)

print(res1*res0)

Solution (Python):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, p = map(int, input().split())
A = list(map(lambda x: int(x) % 2, input().split()))
x = A.count(0)
y = n - x
if p == 1:
    cnt = 0
    for i in range(y + 1):
        if i % 2 == 1:
            cnt += combinations_count(y, i)
    print(2 ** x * cnt)
else:
    cnt = 0
    for i in range(y + 1):
        if i % 2 == 0:
            cnt += combinations_count(y, i)
    print(2 ** x * cnt)

Solution (Python):
import sys
from functools import reduce
from operator import mul



def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def cmb(n: int, r: int):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def main():
    n, p = input_int_list()
    A = input_int_list()
    even = 0
    odd = 0
    for a in A:
        if a % 2 == 1:
            odd += 1
        else:
            even += 1

    if p == 1:
        ans = 2**even
        tmp = 0
        for i in range(1, odd + 1, 2):
            tmp += cmb(odd, i)
        print(ans * tmp)
    elif p == 0:
        ans = 2**even
        tmp = 0
        for i in range(0, odd + 1, 2):
            tmp += cmb(odd, i)
        print(ans * tmp)
    return


if __name__ == "__main__":
    main()

Solution (Python):
n, p = map(int, input().split())
a = list(map(int, input().split()))
a1 = []
a2 = []
for i in range(n):
    if a[i] % 2 == 0:
        a2.append(a[i])
    else:
        a1.append(a[i])
if len(a2) == n:
    if p == 0:
        print(2**n)
    else:
        print(0)
else:
    print(2**(n-1))

Solution (Python):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N,P = map(int,input().split())
A = list(map(int, input().split()))
oddC = 0
evenC = 0
for a in A:
    if a % 2 == 1:
        oddC += 1
    else:
        evenC += 1
c = 0
if P == 0:
    oddcombi = 0
    for i in range(oddC+1):
        if i % 2 == 1:
            continue
        oddcombi += combinations_count(oddC,i)
    evencombi = 0
    for i in range(evenC+1):
        evencombi += combinations_count(evenC,i)
    print(oddcombi*evencombi)
else:
    oddcombi = 0
    for i in range(oddC+1):
        if i % 2 == 0:
            continue
        oddcombi += combinations_count(oddC,i)
    evencombi = 0
    for i in range(evenC+1):
        evencombi += combinations_count(evenC,i)
    print(oddcombi*evencombi)

Solution (Python):
import sys, math
from functools import lru_cache
from collections import defaultdict
from decimal import Decimal
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N, P = mi()
    A = list(mi())

    if all(a%2==0 for a in A):
        print(0 if P else pow(2, N))
    else:
        print(pow(2, N-1))


if __name__ == '__main__':
    main()

Solution (Python):
import math
n,p=map(int,input().split())
a=list(map(int,input().split()))
odd=0
even=0
for i in range(n):
  if a[i]%2==0:
    even+=1
  else:
    odd+=1
ans=0
t=1
while t<=odd:
  res=math.factorial(odd)//(math.factorial(t)*math.factorial(odd-t))
  t+=2
  if even!=0:
    w=0
    while w<=even:
      res1=math.factorial(even)//(math.factorial(w)*math.factorial(even-w))
      w+=1
      ans+=res*res1
  else:
    ans+=res
if p==1:
  print(ans)
else:
  print(2**n-ans)

Solution (Python):
import math


def combination(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N, P = map(int, input().split())
A = list(map(int, input().split()))

odd = 0
even = 0
for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1

ans = 0
for i in range(P, odd+1, 2):
    tmp = combination(odd, i)
    for j in range(0, even+1):
        ans += tmp * combination(even, j)
print(ans)

Solution (Python):
import math

n, p = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))

zero_count = 0
one_count = 0

for num in a:
    if num % 2 == 0:
        zero_count += 1
    else:
        one_count += 1

coef = 2 ** zero_count

ans = 0

for i in range(one_count + 1):
    if i % 2 != p:
        continue
        
    ans += math.factorial(one_count) // math.factorial(one_count - i) // math.factorial(i)
print(ans * coef)

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))

N,P = mint()
A = lint()
odd = len([a for a in A if a%2!=0])
if odd==0:
    print(0 if P else 2**N)
else:
    print(2**(N-1))

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))

N,P = mint()
A = lint()
even = len([a for a in A if a%2==0])
odd = N-even
if odd==0:
    print(0 if P else 2**N)
else:
    print(2**(N-1))

Solution (Python):

N,P = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A,reverse = False)


dp = [[0]*2 for _ in range(N+1)]


dp[0] = [1,0]

for v in range(1,N+1):
    
    if A[v-1]%2 == 0:
        dp[v][0] = dp[v-1][0]*2
        dp[v][1] = dp[v-1][1]*2
    
    else:
        
        dp[v][0] = dp[v-1][1] + dp[v-1][0]
        dp[v][1] = dp[v-1][0] + dp[v-1][1]
print(dp[N][P])

Solution (Python):
import itertools
import math
from math import factorial

N,P = list(map(int, input().split()))
As = list(map(int, input().split()))


odd = 0
even = 0

for A in As:
    if(A % 2 == 0):
        even += 1
    else:
        odd += 1



even_combi = 0

for i in range(even+1):
    even_combi += math.factorial(even) // math.factorial(i) // math.factorial(even-i)







odd_combi = 0

if(P == 0):
    for i in range(0,odd + 1,2):
        odd_combi += math.factorial(odd) // math.factorial(i) // math.factorial(odd-i)

else:
    for i in range(1, odd + 1 , 2):
        odd_combi += math.factorial(odd) // math.factorial(i) // math.factorial(odd-(i))

print(odd_combi*even_combi)

Solution (Python):
N, P = map(int, input().split())
A = list(map(int, input().split()))
B = [a % 2 for a in A]
count_0 = B.count(0)
count_1 = B.count(1)

if count_1 == 0:
    if P == 0:
        ans = 2 ** N
    else:
        ans = 0
else:
    ans = 2 ** (N - 1)
print(ans)

Solution (Python):
import math


N, P = map(int, input().split())
A = list(map(int, input().split()))
B = [a % 2 for a in A]
count_0 = B.count(0)
count_1 = B.count(1)


def comb_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


x = y = 0
if count_0 == 0:
    x = 1
else:
    if P == 1 and count_1 == 0:
        x = 0
    else:
        for i in range(count_0 + 1):
            x += comb_count(count_0, i)

if count_1 == 0:
    y = 1
else:
    if P == 0:
        for i in range(0, count_1 + 1, 2):
            y += comb_count(count_1, i)
    else:
        for i in range(1, count_1 + 1, 2):
            y += comb_count(count_1, i)

print(x * y)

Solution (Python):
n,p = map(int,input().split())
a = list(map(int,input().split()))
odd = 0
even = 0
for ai in a:
    if(ai%2==0):
        even += 1
    else:
        odd += 1

if(p==1)&(odd==0):
    print(0)
elif(p==0)&(odd==0):
    print(2**n)
else:
    print(2**(n-1))

Solution (Python):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,p=map(int,input().split())
a=[int(x)%2 for x in input().split()]
z=a.count(0)
o=a.count(1)
onum=0
if p:
  i=1
  while i<=o:
    onum+=combinations_count(o, i)
    i+=2
else:
  i=0
  while i<=o:
    onum+=combinations_count(o, i)
    i+=2
print((2**z)*onum)

Solution (Python):
N,P=map(int,input().split())
A=list(map(int,input().split()))
x,y=1,0
for a in A:
    if a%2:
        x,y=x+y,x+y
    else:
        x,y=x*2,y*2
print(y if P else x)

Solution (Python):
import math



def C(n, r):
    ret = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    return ret




def sum_C(n, R):
    nCr_0 = 1

    s = nCr_0
    for r in range(min(n, R)):
        nCr_1 = nCr_0 * (n - r) // (r + 1)
        nCr_0 = nCr_1
        s += nCr_1

    return s



def list_conb(n, R):
    nCr_0 = 1

    ret = [nCr_0]
    for r in range(min(n, R)):
        nCr_1 = nCr_0 * (n - r) // (r + 1)
        ret.append(nCr_1)
        nCr_0 = nCr_1

    return ret


def main():
    N, P = map(int, input().split())
    A = list(map(int, input().split()))

    A = [a % 2 for a in A]

    n_1 = sum(A)
    n_0 = N - n_1

    
    

    c = 0
    
    if P == 0:
        r = range(0, n_1 + 1, 2)
    else:
        r = range(1, n_1 + 1, 2)

    for i in r:  
        if N - i < 0:
            break
        c += C(n_1, i) * sum_C(n_0, N - i)

    print(c)


main()

Solution (Python):
import math
n,p = map(int,input().split())
ls = list(map(int,input().split()))
lo = []
le = []
def combinations_count(n, r): 
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in ls:
    if i % 2 == 0:
        le.append(i)
    else:
        lo.append(i)
x = len(lo)
y = len(le)
if p == 0:
    a = 1
    if x != 0:
        if x % 2 == 0:
            r = x
        else:
            r = x - 1
        a = 0
        for j in range(0,r+1,2):
            a += combinations_count(x, j)
    b = 1
    if y != 0:
        b = 0
        for k in range(y+1):
            b += combinations_count(y, k)
    print(a*b)
else:
    if x != 0:
        if x % 2 == 0:
            r = x - 1
        else:
            r = x
        a = 0
        for j in range(1,r+1,2):
            a += combinations_count(x, j)
    else:
        a = 0
    b = 1
    if y != 0:
        b = 0
        for k in range(y+1):
            b += combinations_count(y, k)
    print(a*b)

Solution (Python):
n, p = map(int, input().split())
A = list(map(int, input().split()))
even = 0
odd = 0

for i in range(n):
    if A[i] % 2 == 0:
        even += 1
    else:
        odd += 1

even_answer = 2 ** even

check = p


def kaijo(i):
    if (i == 1) or (i == 0):
        return 1
    return i * kaijo(i - 1)


odd_answer = 0
while check <= odd:
    
    odd_answer = odd_answer + (kaijo(odd) / kaijo(check) / kaijo(odd - check))
    
    check += 2

print(int(odd_answer * even_answer))

Solution (Python):
N, P = map(int, input().split())
A = list(map(int, input().split()))

dic = {"even":0, "odd":0}
for i in range(N):
    if A[i] % 2 == 0:
        dic["even"] += 1
    else:
        dic["odd"]  += 1

if dic["odd"] == 0:
    if P == 1:
        print(0)
    else:
        print(2 ** dic["even"])

else:
    print(2 ** (N-1))

Solution (Python):
n,p = map(int, input().split())
lis = list(map(int, input().split()))

odd = [i for i in lis if i % 2==1]
even = [i for i in lis if i % 2 == 0]

if len(odd) == 0:
    if p == 0:
        print(2**n)
    else:
        print(0)
else:
    odd_m = len(odd)
    even_m = len(even)
    t1 = 2**even_m
    t2 = 2**(odd_m-1)
    print(t1*t2)

Solution (Python):
from math import factorial

N,P=map(int,input().split())
A=list(map(int,input().split()))

num_k=0
num_g=0
for i in range(N):
    if A[i]%2==0:
        num_g+=1
    else:
        num_k+=1

n=num_k//2
ans_k=0
for i in range(0,n*2+1,2):
    ans_k+=factorial(num_k)/factorial(i)/factorial(num_k-i)

ans_g=2**(num_g)

ans=int(ans_k*ans_g)

if P==0:
    print(ans)
else:
    ans=2**N-ans
    print(ans)

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  


N,P = MI()
A = LI()

x = sum(A[i] % 2 == 0 for i in range(N))  
y = N-x  

if y == 0:
    print(0 if P == 1 else 2**x)
else:
    print(2**(x+y-1))

Solution (Python):
N, P = map(int, input().split())
A = list(map(int, input().split()))
MAX_C = 100

def comb_dp():
    """
    dpテーブルを作ってnCkを計算.
    modのpは素数でなくてよい.
    1 <= k <= n <= 2000程度
    O(MAX_C ** 2).
    """
    Com = [[0]*MAX_C for _ in range(MAX_C)]
    Com[0][0] = 1
    for i in range(1, MAX_C):
        
        Com[i][0] = 1
        for j in range(1, MAX_C):
            
            Com[i][j] = (Com[i-1][j-1] + Com[i-1][j])
        
    return Com
Com = comb_dp()
if P == 0:
    is_even = [A[i]%2==0 for i in range(N)]
    num_e = is_even.count(True)
    num_o = N-num_e
    tmp1 = 0
    tmp2 = 0
    for i in range(0, num_e+1):
        tmp1 += Com[num_e][i]
    for i in range(0, num_o+1, 2):
        tmp2 += Com[num_o][i]
    print(tmp1*tmp2)
else:
    is_even = [A[i]%2==0 for i in range(N)]
    num_e = is_even.count(True)
    num_o = N-num_e
    tmp1 = 0
    tmp2 = 0
    for i in range(0, num_e+1):
        tmp1 += Com[num_e][i]
    for i in range(1, num_o+1, 2):
        tmp2 += Com[num_o][i]
    print(tmp1*tmp2)

Solution (Python):
from scipy.special import comb
N, P = map(int, input().split())
A = list(map(int, input().split()))
MAX_C = 100















        




if P == 0:
    is_even = [A[i]%2==0 for i in range(N)]
    num_e = is_even.count(True)
    num_o = N-num_e
    tmp1 = 0
    tmp2 = 0
    for i in range(0, num_e+1):
        tmp1 += comb(num_e, i, exact=True)
    for i in range(0, num_o+1, 2):
        tmp2 += comb(num_o, i, exact=True)
    print(tmp1*tmp2)
else:
    is_even = [A[i]%2==0 for i in range(N)]
    num_e = is_even.count(True)
    num_o = N-num_e
    tmp1 = 0
    tmp2 = 0
    for i in range(0, num_e+1):
        tmp1 += comb(num_e, i, exact=True)
    for i in range(1, num_o+1, 2):
        tmp2 += comb(num_o, i, exact=True)
    print(tmp1*tmp2)

Solution (Python):
N,P = map(int,input().split())
A = list(map(int,input().split()))
C = [0,0]
for i in range(N):
    if A[i]%2==0:
        C[0] += 1
    else:
        C[1] += 1
if C[1]==0 and P==1:
    print(0)
elif C[1]==0 and P==0:
    print(2**C[0])
else:
    print((2**C[0])*(2**(C[1]-1)))

Solution (Python):
import math
n, p, *a = map(int, open(0).read().split())


def c(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


memo = [0, 0]
for i in range(n):
    memo[a[i] % 2] += 1



ans = 0
if p == 0:
    for i in range(0, memo[1] + 1, 2):
        ans += c(memo[1], i) * pow(2, memo[0])
else:
    for i in range(1, memo[1] + 1, 2):
        ans += c(memo[1], i) * pow(2, memo[0])

print(ans)

Solution (Python):
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    N,P = map(int,input().split())
    A = list(map(int,input().split()))
    num1 = 0
    num0 = 0
    for i in range(N):
        tmp = A[i]%2
        if tmp == 0:
            num0 += 1
        else:
            num1 += 1
    
    ans2 = 0
    for i in range(num0+1):
        ans2 += comb(num0,i)

    if P == 1:
        syo = num1//2
        amari = num1%2
        tmp = syo + amari
        i = 1
        ans = 0
        for j in range(tmp):
            ans += comb(num1,i)
            i += 2


        ans = ans*ans2
        return ans

    else:
        syo = num1//2
        tmp = syo+1
        i = 0
        ans = 0
        
        for j in range(tmp):
            
            if i == 0:
                ans += 1
                i += 2
            else:
                ans += comb(num1,i)
                i += 2

        ans = ans*ans2
        return ans


print(main())

Solution (Python):
n,p=map(int,input().split())
a=list(map(int, input().split()))
from math import factorial
o=0;e=0
for i in a:
    if i%2==0:e+=1
    else:o+=1
if p==0:
    odds=0
    for i in range(0,o+1,2):
        odds+=factorial(o)//factorial(i)//factorial(o-i)
else:
    odds=0
    for i in range(1,o+1,2):
        odds+=factorial(o)//factorial(i)//factorial(o-i)
print(odds*2**e)

Solution (Python):
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,p = map(int,input().split())
s = list(map(int,input().split()))
x,y,ans = 0,0,0
for i in s:
    if i%2 == 0:
        x += 1
    else:
        y += 1

if p == 1:
    k = 0
    for i in range(1,y+1,2):
        k += comb(y,i)
    g = 0
    for i in range(x+1):
        g += comb(x,i)
    print(k*g)
else:
    g = 0
    for i in range(x+1):
        g += comb(x,i)
    k = 0
    for i in range(0,y+1,2):
        k += comb(y,i)
    print(k*g)

Solution (Python):
n,p=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=a[i]%2
one=sum(a)
zero=n-one
if p==1 and one==0:
    print(0)
    exit()
if p==0 and one==0:
    print(2**n)
    exit()
print(2**(n-1))

Solution (Python):
n, p = map(int, input().split())
arr = list(map(int, input().split()))

a = sum([x % 2 == 1 for x in arr])
b = n - a


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p


MOD = 10**18 + 7
N = 10**6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

start = p


ans = 0
for i in range(p, a + 1, 2):
    for j in range(b + 1):
        ans += cmb(a, i, MOD) * cmb(b, j, MOD)

print(ans)