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):
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
n,p=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
odd=0
even=0
ans=0
for i in range(n):
    if a[i]%2==0:
        even+=1
    else:
        odd+=1
if p==0:
    cnt=odd
    if cnt%2!=0:
        cnt-=1
    while cnt>=0:
        ans+=combinations_count(odd, cnt)
        cnt-=2
    ans*=2**even
else:
    cnt=odd
    if cnt%2==0:
        cnt-=1
    while cnt>=0:
        ans+=combinations_count(odd, cnt)
        cnt-=2
    ans*=2**even
print(ans)

Solution (Python):
from math import factorial as f
def comb(n, k):
  return f(n)//(f(k) * f(n-k))
n, p = map(int, input().split())
A = list(map(int, input().split()))
o, e = 0, 0
for i in A:
  if i%2:
    o += 1
  else:
    e += 1
t = 0
for i in range(p, o+1, 2):
  t += comb(o, i)
ans = 2**e * t
print(ans)

Solution (Python):
N,MOD = 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

P = [1]

for i in range(ODD):
    P.append(P[-1]*(i+1))

ans = 0

for i in range(ODD+1):
    if i%2 == MOD:
        ans += P[ODD]//(P[i]*P[ODD-i])

print(2**EVEN*ans)

Solution (Python):

import sys










from scipy.misc import comb 
import numpy as np 


def main():
    n, p = [int(x) for x in sys.stdin.readline().split()]
    a = np.array(sys.stdin.readline().split(), np.int64)
    a %= 2
    a.sort()
    count0 = np.searchsorted(a, 1)
    count1 = n - count0

    ans = 0
    if p == 1:
        for i in range(count0+1):
            for j in range(1, count1+1, 2):
                ans += comb(count0, i, exact=True) * comb(count1, j, exact=True)
    else:
        for i in range(count0+1):
            for j in range(0, count1+1, 2):
                ans += comb(count0, i, exact=True) * comb(count1, j, exact=True)
    
    print(ans)





if __name__ == "__main__":
    main()

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

Solution (Python):
from math import factorial
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=2**even
k=0
if P==0:
  k=0
else:
  k=1
tmp=0
for i in range(k,odd+1,2):
  tmp+=factorial(odd)//factorial(odd-i)//factorial(i)

print(ans*tmp)

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



















import sys

sys.setrecursionlimit(2000)


def inpl():
    return list(map(int, input().split()))



def cmb(n, r):
    
    if n < r:
        return 0
    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 gcd(a, b):
    
    while b > 0:
        a, b = b, a % b

    return a


def lcm(a, b):
    
    return a * b // gcd(a, b)


N, P = inpl()
A = inpl()

odd = sum(a % 2 == 1 for a in A)
even = sum(a % 2 == 0 for a in A)

if P == 1 and odd == 0:
    print(0)
    exit()

print(
    sum(cmb(odd, i) for i in range(P, odd + 1, 2)) * sum(
        cmb(even, j) for j in range(even + 1)))

Solution (Python):
from scipy.misc import comb

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

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

s_even = 0
for i in range(even+1):
    s_even += comb(even, i, exact=True)

s_odd = 0
ans = 0
if p == 0:
    for i in range(odd+1)[::2]:
        s_odd += comb(odd, i, exact=True)
        ans = s_even * s_odd
else:
    for i in range(odd)[1::2]:
        s_odd += comb(odd, i, exact=True)
        ans = s_even * s_odd

print(ans)

Solution (Python):
def nCr(n, r):
    r = min(r, n-r)
    numerator=1
    for i in range(n,n-r,-1):
        numerator*=i
    denominator=1
    for i in range(r,1,-1):
        denominator*=i
    return numerator//denominator
n,p=map(int,input().split())
a,b,e,o=list(map(int,input().split())),0,0,0
for i in range(len(a)):
    if a[i]%2==0:
        e+=1
    else:
        o+=1
for i in range((o-p)//2+1):
    b+=nCr(o,p+2*i)
print(b*(2**e))

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

B = [A[i] % 2 for i in range(len(A))]
I, O = 0, 0
for i in range(len(B)):
  if B[i] == 1:
    I += 1
  else:
    O += 1
def fact(n):
  L = [1]
  for f in range(n):
    L.append(L[f]*(f+1))
  return L[n]
def nCr(n, r):
  return fact(n) // (fact(r) * fact(n-r))
S = 0
if P == 1:
  for q in range(1, I+1, 2):
    S += nCr(I, q)
elif P == 0:
  for q in range(0, I+1, 2):
    S += nCr(I, q)
print(S * 2 ** O)

Solution (Python):
N, P = map(int, input().split())
odd = sum([1 for x in list(map(int, input().split())) if x & 1])

even = N - odd

answer = 0
if odd == 0:
    if P == 0:
        answer = 2 ** even
    else:
        answer = 0
else:
    answer = 2 ** even * 2 ** (odd-1)
print(answer)

Solution (Python):
import numpy as np

n, p = map(int, input().split())
a = np.array(list(map(int, input().split())))
a = np.sum(a[a % 2 == 1])

if a == 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()))

tmp = -1
for i in range(N):
    if A[i] % 2 != 0:
        tmp = i
        break

if tmp == -1:
    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()))
even = 0
odd = 0
for i in range(len(a)):
         if a[i] % 2 == 0:
                  even += 1
         else:
                  odd += 1
if p == 1 and odd == 0:
         print(0)
else:
         print((2**(max(0,odd-1)))*(2**even))

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

print(ans)

Solution (Python):
from scipy.misc import comb
N, P = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * N
for i in range(N):
    B[i] = A[i] % 2

num_1 = sum(B)
num_0 = N - num_1
cnt_num_1 = 0
for i in range(1, num_1+1, 2):
    cnt_num_1 += comb(num_1, i, exact=True) * (2 ** num_0)

if P == 1:
    print(cnt_num_1)
else:
    print(2 ** N - cnt_num_1)

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

cnt = {}
cnt[0] = 0
cnt[1] = 0
for i in range(n):
    cnt[a[i] % 2] += 1
tmp_ans= 1
for _ in range(cnt[0]):
    tmp_ans *= 2
ans = 0
for i in range(cnt[1] + 1):
    if i % 2 == p:
        tmp = 1
        for j in range(i):
            tmp *= (cnt[1] - j)
        for j in range(i):
            tmp //= (j+1)
        ans += tmp
print(ans * tmp_ans)

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

def comb(n,r):
    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

N,P=map(int,input().split())
A=list(map(lambda x:int(x)%2,input().split()))
A0,A1=A.count(0),A.count(1)
if P==1:
    if not A1:
        print(0)
        exit()
value0=0
for i in range(0,A0+1):
    value0+=comb(A0, i)
value1=(1 if not P else 0)
for i in range(2-P,A1+1,2):
    value1+=comb(A1, i)
print(value0*value1)

Solution (Python):

N, P = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(N):
    a[i] = a[i] % 2

g = a.count(1)
if g == 0:
    if P == 0:
        ans = 2 ** N
else:
    ans = 2 ** (N - 1)

print(ans)

Solution (Python):

import math

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

odd_n = 0
even_n = 0

for a in a_list:
    if a % 2 == 0:
        even_n += 1
    else:
        odd_n += 1


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


if P == 0:
    odd_p = 1
    if odd_n > 0:
        
        for i in range(2, odd_n + 1, 2):
            odd_p += C(odd_n, i)
    even_p = 2 ** even_n
    p = odd_p * even_p
else:
    odd_p = 0
    if odd_n > 0:
        
        for i in range(1, odd_n + 1, 2):
            odd_p += C(odd_n, i)

    even_p = 2 ** even_n
    p = odd_p * even_p

ans = p

print(ans)

Solution (Python):
a,b = [int(i) for i in input().split()]

l = [int(i) for i in input().split()]

l2 = [i for i in l if i %2 == 1]

if not l2 :
    print(2**a if b % 2 == 0 else 0)
else:
    print(2**(a-1))

Solution (Python):
Num=[1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800,87178291200,1307674368000,20922789888000,355687428096000,6402373705728000,121645100408832000,2432902008176640000,51090942171709440000,1124000727777607680000,25852016738884976640000,620448401733239439360000,15511210043330985984000000,403291461126605635584000000,10888869450418352160768000000,304888344611713860501504000000,8841761993739701954543616000000,265252859812191058636308480000000,8222838654177922817725562880000000,263130836933693530167218012160000000,8683317618811886495518194401280000000,295232799039604140847618609643520000000,10333147966386144929666651337523200000000,371993326789901217467999448150835200000000,13763753091226345046315979581580902400000000,523022617466601111760007224100074291200000000,20397882081197443358640281739902897356800000000,815915283247897734345611269596115894272000000000,33452526613163807108170062053440751665152000000000,1405006117752879898543142606244511569936384000000000,60415263063373835637355132068513997507264512000000000,2658271574788448768043625811014615890319638528000000000,119622220865480194561963161495657715064383733760000000000,5502622159812088949850305428800254892961651752960000000000,258623241511168180642964355153611979969197632389120000000000,12413915592536072670862289047373375038521486354677760000000000,608281864034267560872252163321295376887552831379210240000000000,30414093201713378043612608166064768844377641568960512000000000000,1551118753287382280224243016469303211063259720016986112000000000000,80658175170943878571660636856403766975289505440883277824000000000000,4274883284060025564298013753389399649690343788366813724672000000000000,230843697339241380472092742683027581083278564571807941132288000000000000,12696403353658275925965100847566516959580321051449436762275840000000000000,710998587804863451854045647463724949736497978881168458687447040000000000000,40526919504877216755680601905432322134980384796226602145184481280000000000000,2350561331282878571829474910515074683828862318181142924420699914240000000000000,138683118545689835737939019720389406345902876772687432540821294940160000000000000]

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

tmp=0
total=0
for i in A:
    tmp+=i%2
R=N-tmp

K=1
for i in range(1,R+1):
    K+=Num[R]//(Num[R-i]*Num[i])


if(tmp%2==P):
    total=K
    for i in range(2,tmp+1,2):
        total+=(Num[tmp]//(Num[tmp-i]*Num[i]))*K
else:
    for i in range(1,tmp+1,2):
        total+=(Num[tmp]//(Num[tmp-i]*Num[i]))*K

print(total)

Solution (Python):
n,p=map(int,input().split())
b=list(map(int,input().split()))
odd=[0]*(len(b)+1)
even=[0]*(len(b)+1)
even[0]=1
for i in range(len(b)):
  if b[i]%2==0:
    even[i+1]=even[i]*2
    odd[i+1]=odd[i]*2
  else:
    even[i+1]=odd[i]+even[i]
    odd[i+1]=odd[i]+even[i]

print((even[-1],odd[-1])[p])

Solution (Python):
import math
def nCr(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()))
E = 0
O = 0
for i in A:
    if i % 2 == 0:
        E += 1
    else:
        O += 1
ans = 1
ans *= 2**E
if P == 0:
    ans2 = 1
    for i in range(O // 2):
        i += 1
        i *= 2
        ans2 += nCr(O,i)
else:
    ans2 = 0
    for i in range((O+1) // 2):
        i *= 2
        i += 1
        ans2 += nCr(O,i)
print (ans * ans2)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def conb(n,r): 
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n,p = inpl()
a = inpl()
res = 0
odd = 0
even = 0
for i in a:
    if i%2:
        odd += 1
    else:
        even += 1

tmp = 0 if p == 0 else 1
for i in range(tmp,odd+1,2):
    for j in range(0,even+1):
        res += conb(odd,i) * conb(even,j)
print(res)

Solution (Python):
import math

def nCr(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()))

E = 0
O = 0

for i in A:

    if i % 2 == 0:
        E += 1
    else:
        O += 1

ans = 1

ans *= 2**E


if P == 0:

    ans2 = 1

    for i in range(O // 2):

        i += 1
        i *= 2

        ans2 += nCr(O,i)

else:

    ans2 = 0

    for i in range((O+1) // 2):

        i *= 2
        i += 1

        ans2 += nCr(O,i)

print (ans * ans2)

Solution (Python):
import math

def nCr(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()))

E = 0
O = 0

for i in A:

    if i % 2 == 0:
        E += 1
    else:
        O += 1

ans = 1

ans *= 2**E


if P == 0:

    ans2 = 1

    for i in range(O // 2):

        i += 1
        i *= 2

        ans2 += nCr(O,i)

else:

    ans2 = 0

    for i in range((O+1) // 2):

        i *= 2
        i += 1

        ans2 += nCr(O,i)

print (ans * ans2)

Solution (Python):
n,p,*a=map(int,open(0).read().split())
if len([i for i in a if i%2])==0:
    print(2**n*(p^1))
else:
    print(2**(n-1))

Solution (Python):
N, P = map(int, input().split())
A = list(map(int, input().split()))
A = [i % 2 for i in A]

def cmb(n, r):
    p, q = 1, 1
    for i in range(r):
        p = p * (n - i)
        q = q * (i + 1)
    return p // q


even = A.count(0)
odd = A.count(1)

if odd == 0:
    if P == 0:
        print(2 ** N)
    else:
        print(0)
else:
    if P == 0 and even == 0 and odd == 1:
        print(0)
    elif P == 0:
        n = 2
        cnt = 1
        while n <= odd:
            cnt += cmb(odd, n)
            n += 2
        print(2 ** even * cnt)
    else:
        n = 1
        cnt = 0
        while n <= odd:
            cnt += cmb(odd, n)
            n += 2
        print(2 ** even * cnt)

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

def C(u,d):
    a=1
    b=1
    for i in range(d):
        a*=(u-i)
        b*=(d-i)
    return a//b

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

ans=0
for i in range(odd+1)[P%2::2]:
    ans+=C(odd,i)

temp=0
for i in range(even+1):
    temp+=C(even,i)
    
print(int(ans*temp))

Solution (Python):
n, p = map(int,input().split())
src = list(map(int, input().split()))
even_count = 0 
odd_count = 0 
for s in src:
    if s%2 == 0:
        even_count += 1
    else:
        odd_count += 1
if p == 1 and odd_count == 0:
    print(0)
elif odd_count == 0:
    print(2**even_count)
else:
    print(2**even_count*2**(odd_count-1))

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

for i in range(n):
    A[i] %= 2

C = [[0] * (n+1) for i in range(n+1)]

C[0][0] = 1
for i in range(n):
    for j in range(i+1):
        C[i+1][j] += C[i][j]
        C[i+1][j+1] += C[i][j]

ans = 0
n0 = A.count(0)
n1 = A.count(1)
for i in range(p, n+1, 2):
    for j in range(n0+1):
        ans += C[n1][i] * C[n0][j]
print(ans)

Solution (Python):
from sys import exit, stdin
N, P = [int(_) for _ in stdin.readline().rstrip().split()]
A = [int(_) for _ in stdin.readline().rstrip().split()]

for a in A:
    if a % 2 == 1:
        print(2**(N-1))
        exit()
if P == 1:
    print(0)
else:
    print(2**N)

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

Solution (Python):
def f(n):
    N=1
    for i in range(n):
        N=N*(i+1)
    return N

def C(n,x):
    return f(n)//(f(x)*f(n-x))
    
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 p % 2 == 0:
    x=0
    for i in range(odd//2+1):
        x+=C(odd,i*2)
    print((2**even) * x)
else:
    x=0
    for i in range(odd//2):
        x+=C(odd,i*2+1)
    print((2**even) * x)

Solution (Python):
n,p=map(int,input().split())
a=list(map(int,input().split()))
e=o=0
def c(a,b):
	w=1
	for i in range(a-b+1,a+1):
		w*=i
	for i in range(b):
		w//=(i+1)
	return w
for i in range(n):
	if a[i]%2==0:
		e+=1
	else:
		o+=1
if p==0:
	ans=2**e
	q=0
	for i in range(o//2+1):
		q+=c(o,2*i)
	print(ans*q)
else:
	ans=2**e
	q=0
	for i in range((o+1)//2):
		q+=c(o,2*i+1)
	print(ans*q)

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

even, odd = 0, 0

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

if n == even:
    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()))

class Combination:
    def __init__(self, size):
        self.size = size
        self.fact = [1] * size
        for i in range(1, size):
            self.fact[i] = i * self.fact[i - 1]

    def ncr(self, n, r):
        if r > n or n < 0 or r < 0:
            return 0
        return self.fact[n] // self.fact[r] // self.fact[n - r]

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

ans = 0
comb = Combination(N + 100)
if P == 0:  
    for o in range(0, odd + 1, 2):
        for e in range(even + 1):
            ans += comb.ncr(odd, o) * comb.ncr(even, e)
else:
    for o in range(1, odd + 1, 2):
        for e in range(even + 1):
            ans += comb.ncr(odd, o) * comb.ncr(even, e)

print(ans)

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

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

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

Solution (Python):
N, P = map(int,input().split())
A = list(map(int,input().split()))
dp = [[[0 for k in range(2)] for j in range(N+1)] for i in range(N+1)] 
dp[1][0][0] = 1
if(A[0] % 2 == 0):
    dp[1][1][0] = 1
else:
    dp[1][1][1] = 1
for i in range(2, N+1):
    for j in range(i+1):
        if(j == 0):
            dp[i][j][0] = 1
        else:
            if(A[i-1] % 2 == 0):
                dp[i][j][0] = dp[i-1][j-1][0] + dp[i-1][j][0]
                dp[i][j][1] = dp[i-1][j-1][1] + dp[i-1][j][1]
            else:
                dp[i][j][0] = dp[i-1][j-1][1] + dp[i-1][j][0]
                dp[i][j][1] = dp[i-1][j-1][0] + dp[i-1][j][1]
ans = 0
if(P == 0):
    for i in range(N+1):
        ans += dp[N][i][0]
else:
    for i in range(N+1):
        ans += dp[N][i][1]
print(str(ans))

Solution (Python):
import math
def combi(n, r):
  if n >= r:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  elif r == 0:
    return 1
  else:
    return 0

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

eo = ["e" if i % 2 == 0 else "o" for i in A]
e_num = eo.count("e")
o_num = eo.count("o")

o = [i for i in range(o_num + 1) if i % 2 == 0]
e = [i for i in range(o_num + 1) if i % 2 == 1]


if P == 0:
  oo = 0
  for i in o:
    oo += combi(o_num, i)
  ans = 2**e_num * oo
else:
  ee = 0
  for i in e:
    ee += combi(o_num, i)
  ans = 2**e_num * ee

print(ans)

Solution (Python):
N, P = map(int, input().split())
As = list(map(int, input().split()))
nE = 0
nO = 0
for A in As:
  if A%2 == 0:
    nE += 1
  else:
    nO += 1

r = 0

for k in range(0 if P == 0 else 1, nO+1, 2):
  c = 1
  for i in range(1, k+1):
    c = c*(nO+1-i)//i
  r += c
r = r*2**nE
print(r)

Solution (Python):
N, P = list(map(int, input().split()))
A = list(map(int, input().split()))
has_odd = False
for a in A:
    if a % 2 != 0:
        has_odd = True
        break
if not has_odd:
    if P == 0:
        print(2**N)
        exit()
    else:
        print(0)
        exit()
else:
    print(2 ** (N - 1))

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

    dp = [[0, 0] for i in range(n + 1)]
    dp[0][0] = 1  
    for i in range(n):
        if a[i] % 2 == 0:
            dp[i + 1][0] = dp[i][0]*2
            dp[i+1][1] = dp[i][1]*2
        else:
            dp[i + 1][0] = dp[i][0] + dp[i][1]
            dp[i + 1][1] = dp[i][0] + dp[i][1]

    print(dp[n][p])


if __name__ == '__main__':
    main()

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

    dp = [[0, 0] for i in range(n + 1)]
    dp[0][0] = 1
    for i in range(n):
        if a[i] % 2 == 0:
            dp[i + 1][0] += dp[i][0]*2
            dp[i+1][1] += dp[i][1]*2
        else:
            dp[i + 1][0] += dp[i][0] + dp[i][1]
            dp[i + 1][1] += dp[i][0] + dp[i][1]

    print(dp[n][p])


if __name__ == '__main__':
    main()

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

    ans = 0
    even, odd = 0, 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))


if __name__ == '__main__':
    main()

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n, p = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    has_odd = False
    for v in a:
        if v % 2 != 0:
            has_odd = True
            break
    if p == 0:
        if has_odd:
            print(2 ** (n - 1))
        else:
            print(2 ** n)
    else:
        if has_odd:
            print(2 ** (n - 1))
        else:
            print(0)


if __name__ == '__main__':
    slove()

Solution (Python):
from scipy.misc import*
N,P,*A=map(int,open(0).read().split());O=sum(a%2for a in A)
print(2**(N-O)*sum(comb(O,2*i+P,exact=1)for i in range(O//2+1)))

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

for a in A:
    if a % 2 == 0:
        n += 1

if n == N:
    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()))
n = 0

for a in A:
    if a % 2 == 0:
        n += 1

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

print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



def comb(n, r):
    if r > n: return 0
    fact = 1
    for i in range(n-r+1, n+1):
        fact *= i


    divisor = 1
    for j in range(1, r+1):
        divisor *= j


    return fact // divisor




n, p = LI()
L = [i%2 for i in LI()]
ans = 0
odd_cnt = L.count(1)
even_cnt = L.count(0)
for k in range(p, odd_cnt+1, 2):
    ans += comb(odd_cnt, k) * 2 ** even_cnt



print(ans)

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()))
B=[len(A)-sum(A),sum(A)]

ans=0
for i in range(P,B[1]+1,2):
  ans+=combinations_count(B[1],i)
ans*=2**B[0]
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
import fractions

from math import factorial
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

def main():
    _,P = map(int, input().split())
    A = list(map(int, input().split()))
    even = 0
    odd = 0
    for a in A:
        if a%2 == 0:
            even += 1
        else:
            odd += 1
    x = 0
    if P==0:
        for i in range(0,odd+1,2):
            x += combinations_count(odd, i)
        print(2**even*x)
    else:
        for i in range(1,odd+1,2):
            x += combinations_count(odd, i)
        if x == 0:
            print(0)
        else:
            print(2**even*x)

if __name__ == '__main__':
    main()

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 = list(filter(lambda n:n%2==1, A))
even = list(filter(lambda n:n%2==0, A))
O = len(odd)
E = len(even)
O_a = 0
E_a = 0

for i in range(O+1):
    if i % 2 == 0:
        E_a += combination(O,i)
    else:
        O_a += combination(O,i)

if P == 0:
    print(int(2**E * E_a))
else:
    print(int(2**E * O_a))

Solution (Python):
def resolve():
    n, p = map(int, input().split())
    a = list(map(int, input().split()))
    if len([ai for ai in a if ai % 2 == 0]) == n:
        print(2 ** n if p == 0 else 0)
        return 2 ** n if p == 0 else 0
    else:
        print(2 ** (n - 1))
        return 2 ** (n - 1)


if __name__ == "__main__":
    resolve()

Solution (Python):
import math

def main():
    N,P = map(int,input().split())
    A = list(map(int,input().split()))
    odd = []
    even = []
    for i in A:
        if i%2 == 0:
            even.append(i)
        else:
            odd.append(i)

    num_even = 2**len(even)
    def combination(n,r):
        return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

    count = 0
    lo = len(odd)
    if P == 0:
        for i in range(lo//2+1):
            count += combination(lo,2*i)
        print(num_even*count)
    else:
        for i in range(-(-lo)//2):
            count += combination(lo,2*i+1)
        print(num_even*count)

if __name__ == "__main__":
    main()

Solution (Python):
from math import factorial
N, P = map(int, input().split())

A = list(map(lambda x: int(x) % 2, input().split()))

n0 = A.count(0)
n1 = A.count(1)
ans0 = 2 ** n0
ans1 = 0
for i in range(P, n1 + 1, 2):
    ans1 += factorial(n1) // (factorial(i) * factorial(n1 - i))
print(ans0 * ans1)

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

Solution (Python):
import numpy as np
import math
n, p = map(int, input().split())
a = np.array([int(i) for i in input().split()])
even = len(a[a%2 == 0])
odd = len(a[a%2 == 1])
def combinations(n,c):
    return math.factorial(n)//(math.factorial(n-c)*math.factorial(c))
if p == 0:
    x = 1
    for i in range(2,odd+1,2):
        x += combinations(odd,i)
    print(x*2**even)
else:
    if odd == 0:
        print(0)
    else:
        x = 0
        for i in range(1,odd+1,2):
            x += combinations(odd,i)
        print(x*2**even)

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

if total==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()))
dp=[[0]*2 for i in range(n+1)]
dp[0][0]=1
dp[0][1]=0
for i in range(1,n+1):
	if a[i-1]%2==1:
		dp[i][1]=dp[i-1][0]+dp[i-1][1]
		dp[i][0]=dp[i-1][1]+dp[i-1][0]
	else:
		dp[i][1]=dp[i-1][1]*2
		dp[i][0]=dp[i-1][0]*2
print(dp[n][p])

Solution (Python):

def main():
    N, P, *A = map(int, open(0).read().split())
    total = sum(i % 2 for i in A)
    if total == 0:  
        flg = P == 0
        print(2 ** N if flg else 0)
    else:
        print(2 ** (N - 1))


if __name__ == "__main__":
    main()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n,p = LI()
    a = LI()
    o = 0
    for i in a:
        o += i%2
    e = n-o
    ans = (1<<e)*((1<<o)>>((o!=0)|(p!=0)))
    print(ans)
    return

def B():

    return


def C():

    return


def D():

    return


def E():

    return


def F():

    return


if __name__ == "__main__":
    A()