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):
n,p=map(int,input().split())
arr=list(map(int,input().split()))
dp=[[0]*(n+1) for _ in range(2)]
dp[0][0]=1
for i in range(n):
  if arr[i]%2==0:
    dp[0][i+1]=dp[0][i]*2
    dp[1][i+1]=dp[1][i]*2
  else:
    dp[0][i+1]=dp[0][i]+dp[1][i]
    dp[1][i+1]=dp[0][i]+dp[1][i]
print(dp[p][n])

Solution (Python):
N, P = [int(x) for x in input().split()]
As = [int(x) for x in input().split()]

def combination(n, r):
    ans = 1
    for i in range(n, n - r, -1):
        ans *= i
    for i in range(r):
        ans //= (i + 1)
    return ans
n_e = len(list(filter(lambda x: x % 2 == 0, As)))
n_o = N - n_e

ans = 0
for i in range((1 if P == 1 else 0), n_o + 1, 2):
    ans += int(pow(2, n_e)) * combination(n_o, i)

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 P == 0:
  if even == N:
    print(2**N)
  else:
    print(2**(N-1))
    
else:
  if even == N:
    print(0)
  else:
    print(2**(N-1))

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

ODD=0
EVE=0

for i in range(N):
    if A[i]%2==1:
        ODD+=1
    else:
        EVE+=1
        
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**15+7 
N = 10**5
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 )

if P==1:
    O=0
    E=1
    for i in range(EVE):
        E+=cmb(EVE,i,mod)
        E%=(10**15+7)
        
    for i in range((ODD+1)//2):
        O+=cmb(ODD,1+2*i,mod)
        
        
    ans=(E*O)%(10**15+7)
    print(ans)
else:
    O=0
    E=1
    for i in range(EVE):
        E+=cmb(EVE,i,mod)
        E%=(10**15+7)
        
    for i in range((ODD)//2+1):
        O+=cmb(ODD,2*i,mod)
        
        
    ans=(E*O)%(10**15+7)
    print(ans)

Solution (Python):
n,p=map(int,input().split())
l=list(map(lambda x:int(x)%2,input().split()))
a,b=0,0
for i in l:
  if i>0:
    a+=1
  else:
    b+=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 = [(int(a)) % 2 for a in input().split()]

DP = [[0, 0] for _ in range(N)] 
DP[0][A[0]] += 1
DP[0][0] += 1
for i in range(1, N):
    if A[i] == 0:
        DP[i][0] = DP[i-1][0] * 2
        DP[i][1] = DP[i-1][1] * 2
    else:
        DP[i][0] = DP[i-1][1] + DP[i-1][0]
        DP[i][1] = DP[i-1][0] + DP[i-1][1]
print(DP[N-1][P])

Solution (Python):
N,P = map(int,input().split())
A = list(map(int,input().split()))
A = [i%2 for i in A]
zero = A.count(0)
one = A.count(1)
ans = 0
def combinations(n, r):
    import math as ma
    return ma.factorial(n)//(ma.factorial(n-r)*ma.factorial(r))

if P == 0:
    ans += 2**zero
    a = 0
    for i in range(one//2):
        a += combinations(one, 2*(i+1))
    ans += a*(2**zero)
else:
    ans += 2**zero
    a = 0
    for i in range(one//2):
        a += combinations(one, 2*(i+1))
    ans += a*(2**zero)
    ans = 2**N - ans
print(ans)

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

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

odda = 0
for a in alist:
  if a % 2 == 1:
    odda += 1

if odda == 0:
  if p == 0:
    print(pow(2, n))
  else:
    print(0)
else:
  print(pow(2, n-1))

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 as fact

N, P = map(int, input().split())
A = [int(_) for _ in input().split()]
oddcnt = 0
evencnt = 0
for i in A:
    if i % 2 == 1:
        oddcnt += 1
    else:
        evencnt += 1

even = 2**evencnt
odd = 0
if P == 0:
    for i in range(0, oddcnt+1, 2):
        odd += fact(oddcnt) // (fact(i)*fact(oddcnt-i))
else:
     for i in range(1, oddcnt+1, 2):
        odd += fact(oddcnt) // (fact(i)*fact(oddcnt-i))

print(even*odd)

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

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

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

print(ans)

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

k = len(list(filter(lambda x: x % 2 == 0, A)))
l = len(list(filter(lambda x: x % 2 == 1, A)))

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

Solution (Python):
n,p=map(int,input().split())
a = list(map(int,input().split()))
k=0
for a_ in a:
    if not a_%2==0:
        k=1
        break
if k:
    print(1<<(n-1))
else:
    print(0) if p==1 else print(1<<n)

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

ev = 0
ad = 0
for i in A:
  if i % 2 == 0:
    ev += 1
  else:
    ad += 1

if P == 1:
  if ad == 0:
    print("0")
    exit()
  

f = [1, 1]
for i in range(2, ad + 1):
  f.append(f[-1] * i)
num = 0
for i in range(P, ad + 1, 2):
  num += f[ad] // (f[i] * f[ad - i])

print(pow(2, ev) * num)

Solution (Python):
import numpy as np 
N, P = map(int, input().split())
A = np.array(list(map(int, input().split())))

even = ((A % 2) == 0).sum()
odd = len(A) - even
flag = True

if (P == 1) & (odd == 0):
  print(0)
  flag = False

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

Solution (Python):


import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, p = LI()
    A = LI()

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

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


print(main())

Solution (Python):


import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, p = LI()
    A = LI()

    sum_a = sum(A)
    
    dp = [0] * (sum_a + 1)
    dp[0] = 1
    for i in range(n):
        for j in range(sum_a + 1)[::-1]:
            if j - A[i] < 0:
                break
            if dp[j - A[i]]:
                dp[j] += dp[j - A[i]]

    return sum([dp[i] if i % 2 == p else 0 for i in range(sum_a + 1)])


print(main())

Solution (Python):






'''
問題
i番目の袋にビスケットがAi個入っている
i=1,2,...,N
0個以上の袋をえらび袋の中のビスケットをすべて食べる
食べるビスケットの総数を2で割った余りがPになるような袋の選び方は?
ただしNは1以上50以下

考察
Aiのうち偶数がa個で奇数がN-a個あったとすると
偶数のものは何個えらんでもよい: 2**a通り
奇数のものは2で割った余りがPになるように選べばよい
N-aが奇数のときP=0,1両方に対して2**(N-a-1)通り
N-aが偶数のときもパスカルの三角形を考えるとP=0,1両方に対して2**(N-a-1)通り
よって...
N-a=0のときはP=1なら答えは0
N-a=0のときはP=0なら答えは2**N
N-a>0のときはPによらず答えは2**(N-1)
'''

N,P = map(int,input().split(' '))
odds = [int(x)%2 for x in input().split(' ')].count(1)

if odds > 0:
	print(str(int(2**(N-1))))
elif P == 1:
	print('0')
elif P == 0:
	print(str(int(2**(N))))

Solution (Python):
import math
N, P = map(int, input().split())
A = list(map(int, input().split()))
odd = 0
even = 0

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

for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1
even_cmb = 1
for i in range(1, even+1):
    even_cmb += nCr(even, i)

if P == 0:
    odd_cmb = 1
    for i in range(2, odd+1):
        if i % 2 != 0:
            continue
        odd_cmb += nCr(odd, i)
    ans = even_cmb * odd_cmb
else:
    odd_cmb = 0
    for i in range(1, odd+1):
        if i % 2 == 1:
            odd_cmb += nCr(odd, i)
    ans = even_cmb * odd_cmb
print(ans)
exit()

Solution (Python):
N,P = map(int,input().split())
Odd = sum([int(i)%2 for i in input().split()])
Even = N-Odd

def f_C(x,y):
    ans = 1
    for i in range(y):  
        ans *= x-i
    for i in range(y):  
        ans //= i+1
    return(ans)

ans = 2**Even
tmp = 0
for i in range(P,Odd+1,2):
    tmp += f_C(Odd,i)
print(ans*tmp)

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

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 == 1:
        odd += 1
    else:
        even += 1

def nCr(n:int ,r: int) -> int:
    r,v = min(n-r,r),1
    for i in range(r):
        v = (v * (n-i) // (i+1))
    return v

ans = 0
for j in range(1,N+1,2):
    if j > odd:
        break
    ans += nCr(odd,j) * (2**even)

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

Solution (Python):
from math import factorial


def perm(r, c):
    return factorial(r) // factorial(r - c)


def comb(r, c):
    return perm(r, c) // factorial(c)


N, P = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x % 2, a))
a = list(sorted(a))

cnt_0 = a.count(0)
cnt_1 = a.count(1)

ans = 0
if P == 0:
    for j in range(0, cnt_1 + 1, 2):
        ans += comb(cnt_1, j) * (2 ** cnt_0)
else:
    
    for j in range(1, cnt_1 + 1, 2):
        ans += comb(cnt_1, j) * (2 ** cnt_0)
print(ans)

Solution (Python):
import math

def cc(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()))
o = 0
e = 0
s = 0
for i in a:
  if i%2:
    o += 1
  else:
    e += 1
if p:
  for j in range(1,o+1,2):
    s += cc(o, j)
else:
  for k in range(0,o+1,2):
    s += cc(o, k)
print(s*2**e)

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

Solution (Python):
import collections
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def combi(a,b):
	num = 1
	for j in range(b):
		num = num*(a-j)//(j+1)
	return num

N,P = IL()
A = IL()

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

zero = 1
if even != 0:
	for i in range(1,even+1):
		zero += combi(even,i)

if P == 1:
	ans = 0
	for i in range(1,odd+1,2):
		ans += combi(odd,i)*zero
else:
	ans = 0
	for i in range(0,odd+1,2):
		ans += combi(odd,i)*zero

print(ans)

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

if(odd!=0):
    odd-=1
ans = (2**even) * (2**(odd))

if(b==0):
    print(ans)
else:
    print(2**a - ans)

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

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

Solution (Python):
n, p = map(int, input().split())
A = [int(i) for i in 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 == 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()))
c = 0
for a in A:
    c += a%2
if c == 0:
    print(2**N if P == 0 else 0)
else:
    print(2**(N-1))

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:
        print(0)
    else:
        print(2 ** N)
else:
    print(2 ** (N - 1))

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

if all(a%2==0 for a in A):
    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()))

cnt = 0
for x in a:
    if x % 2 == 0:
        cnt += 1
        
if cnt == n:
    if p == 0:
        print(2**n)
    else:
        print(0)
else:
    print(2**n//2)

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

Solution (Python):
n,p=map(int,input().split())
flag=0;a=list(map(int,input().split()))
ans=0
for i in range(n):
  if a[i]%2!=0:
    flag=1

if flag==0 and p==0:
  ans=2**n
elif flag==0 and p==1:
  ans=0

if flag==1:
  ans=2**(n-1)
print(ans)

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
T = 2**Even
S = 0
if P == 0:
  for i in range(Odd//2+1):
    S += math.factorial(Odd)//((math.factorial(Odd-2*i))*math.factorial(2*i))
  print(S*T)
else:
  for j in range(Odd//2):
    S += math.factorial(Odd)//((math.factorial(Odd-2*j-1))*math.factorial(2*j+1))
  print(S*T)

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

k = A.count(1)
l = A.count(0)

if P == 0:
    if k == 0:
        print(2**l)
        exit()
    ans = 1
    ans = 2**(k-1+l)
else:
    if k == 0:
        print(0)
        exit()
    else:
        ans = 1
        ans = 2**(k-1+l)

print(ans)

Solution (Python):
import math
n,p = map(int, input().split())
aa = list(map(int, input().split()))

aa = list(map(lambda x:x%2, aa))
odd = aa.count(1)
even = aa.count(0)
ans = 2**even




pattern = 0
for i in range(p, odd+1, 2):
    
    pattern += math.factorial(odd) // (math.factorial(i)*math.factorial(odd-i))
print(ans*pattern)

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

def cmb(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,*a=map(int,open(0).read().split())
b=[i for i in a if i%2==0]
c=[i for i in a if i%2==1]
ans=0
x=0
for s in range(len(b)+1):
  x+=cmb(len(b),s)
if p==0:
  for s in range(0,len(c)+1,2):
    ans+=x*cmb(len(c),s)
  print(ans)
else:
  for s in range(1,len(c)+1,2):
    ans+=x*cmb(len(c),s)
  print(ans)

Solution (Python):
n,p = map(int,input().split())
A = list(map(int,input().split()))
A = [_ % 2 for _ in A ]
k = A.count(1)
if k == 0:
    if p == 0:
        print(2**n)
    else:
        print(0)
else:
    print(2**(n-1))

Solution (Python):
n,m=map(int, input().split())
a=list(map(int, input().split()))
for i in range(n):
  a[i]%=2
if sum(a)>0:print(2**(n-1))
else:
    if m==0:print(2**n)
    else:print(0)

Solution (Python):
from math import factorial
def comb(n,r):
    return factorial(n)//(factorial(n-r)*factorial(r))
n,p=map(int,input().split())
A=list(map(int,input().split()))
cnt_odd=0
cnt_even=0
for i in range(n):
    if A[i]%2:
        cnt_odd+=1
    else:
        cnt_even+=1
ans=0
for i in range(p%2,cnt_odd+1,2):
    ans+=2**cnt_even*comb(cnt_odd,i)
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 = [int(m) for m in input().split()]
k = 0
for i in range(n):
    if a[i] % 2 == 0:
        k += 1

if p == 1:
    tmp = 0
    for i in range(1, n - k + 1, 2):
        tmp += comb(n - k, i)
    print((2 ** k) * tmp)
else:
    tmp = 0
    for i in range(0, n - k + 1, 2):
        tmp += comb(n - k, i)
    print((2 ** k) * tmp)

Solution (Python):
from math import factorial

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

l = [0, 0]
for a in A:
    l[a%2] += 1

even = (2**l[0])*sum(factorial(l[1])//factorial(l[1]-i)//factorial(i) for i in range(0, l[1]+1, 2))

if P:
    print(2**N-even)
else:
    print(even)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, P = map(int, input().split())
f = [1]*(N+1)
for i in range(1, N):
    f[i+1] = f[i]*(i+1)

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

odd = A.count(1)
even = N-odd

ans = 0

even_sum = 2**even
odd_sum_even = sum([f[odd]//(f[v]*f[odd-v]) for v in range(0, odd+1, 2)])
odd_sum_odd = sum([f[odd]//(f[v]*f[odd-v]) for v in range(1, odd+1, 2)])
if P == 0:
    ans = even_sum*odd_sum_even if even_sum * \
        odd_sum_even != 0 else max(even_sum, odd_sum_even)
else:
    if odd_sum_odd == 0:
        ans = 0
    else:
        ans = even_sum*odd_sum_odd if even_sum * \
            odd_sum_odd != 0 else max(even_sum, odd_sum_odd)

print(ans)

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


n,p = (int(i) for i in input().split())
a = list(int(i) for i in input().split())
odd = 0
even = 0
ans = 0
for i in range(n):
  if a[i]%2 == 0: even+=1
  else:odd += 1
if even == n:
  if p == 0: print(2**n)
  else:print(0)
else:
  print(2**(n-1))

Solution (Python):


"""
参考：https://img.atcoder.jp/agc017/editorial.pdf
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, P = MAP()
aN = LIST()

has_odd = False
for i in range(N):
    if aN[i] % 2 == 1:
        has_odd = True
        break
if not has_odd:
    if P == 0:
        print(2 ** N)
    else:
        print(0)
else:
    print(2 ** (N-1))

Solution (Python):


import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def nCr(n, r):
    
    r = min(r, n-r)
    return factorial(n) // (factorial(r) * factorial(n-r))

N, P = MAP()
aN = LIST()


for i in range(N):
    aN[i] %= 2
c = Counter(aN)

ans = 0

if P == 0:
    
    for i in range(0, c[1]+1, 2):
        ans += nCr(c[1], i)
else:
    
    for i in range(1, c[1]+1, 2):
        ans += nCr(c[1], i)

print(ans * 2**c[0])

Solution (Python):
import collections, scipy.misc, numpy
n, p = map(int, input().split())
a = numpy.array(list(map(int, input().split())))
a %= 2
c = collections.Counter(a)
ans = 0
for i in range(p, c[1] + 1, 2):
    ans += 2 ** c[0] * scipy.misc.comb(c[1], i, exact=True)
print(ans)

Solution (Python):
import collections, scipy.misc, numpy
n, p = map(int, input().split())
a = numpy.array(list(map(int, input().split())))
a %= 2
c = collections.Counter(a)
ans = 0
for i in range(p, c[1] + 1, 2):
    ans += 2 ** c[0] * scipy.misc.comb(c[1], i, exact=True)
print(ans)

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

for i in range(n):
    a[i] %= 2
c = collections.Counter(a)
zero = c[0]
one = c[1]
ans = 0
if p == 0:
    s = 0
else:
    s = 1
for i in range(s, one + 1, 2):
    ans += 2 ** zero * scipy.misc.comb(one, i, exact=True)

print(ans)

Solution (Python):
n,r=map(int,input().split())
c=[i%2for i in list(map(int,input().split()))]
p=sum(c)
print(0if p==0 and r!=0else(2**n if p==0 and r!=1else (2**(n-1))))

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

Solution (Python):
import math

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

b = 0
c = 0

for i in range(N):
    if A[i]%2==1:
        b = b+1
    else:
        c = c+1

if P==1:
    k=1
else:
    k=0
  
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)   
 
def C(n, r):
    return P(n, r)//math.factorial(r)
    
ans = 0
tmp = 2**c

while k<=b:
    ans = ans + tmp*C(b, k)
    k = k+2

print(ans)

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

def cmb(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(int, input().split()))
b = [i%2 for i in a]
n1 = b.count(1)
zero = 2 ** (n-n1)
r = 1
one = 0
while r <= n1:
  one += cmb(n1,r)
  r += 2
if p == 0:
  print(2**n - zero*one )
else:
  print(zero * one)

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

Solution (Python):
from collections import Counter
def combination(n, r): 
    r = min(n-r, r)
    result = 1
    for i in range(n, n-r, -1):
        result *= i
    for i in range(1, r+1):
        result //= i
    return result
n,p = map(int,input().split())
a =list(map(int,input().split()))
for i in range(n):
    a[i] = a[i]%2
b = Counter(a)
c = b[1]
d = b[0]
ans = 0
if p ==0:
    for i in range(0,c+1,2):
        ans += combination(c,i)
else:
    for i in range(1,c+1,2):
        ans += combination(c, i)
ans *= 2**d
print(ans)

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

for i in input().split():
    if int(i) % 2 == 0:
        continue
    else:
        print(2 ** (N - 1))
        break
else:
    if P == 0:
        print(2 ** N)
    else:
        print(0)

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

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, P] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    E_count = 0
    O_count = 0
    for i in range(N):
        if int(input_raw[i]) % 2 == 0:
            E_count += 1
        else:
            O_count += 1

    if P == 1:
        if O_count==0:
            print 0;
            return

    if O_count > 0:
        print (2**E_count ) * (2 ** (O_count - 1))
    else:
        print (2**E_count )


if __name__ == '__main__':
    main()

Solution (Python):

import math

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

    e_count, o_count = 0, 0
    for dum in a:
        if dum % 2 == 0:
            e_count += 1
        else:
            o_count += 1

    total = 0
    if p == 0:
        dum = 1
        for i in range(o_count // 2):
            n = (i + 1) * 2
            dum += (math.factorial(o_count) // (math.factorial(o_count - n) * math.factorial(n)))
        total += (2 ** e_count) * dum

    elif p == 1:
        if o_count == 0:
            pass
        else:
            dum = 0
            for i in range((o_count + 1) // 2):
                n = (i * 2) + 1
                dum += (math.factorial(o_count) // (math.factorial(o_count - n) * math.factorial(n)))
            total += (2 ** e_count) * dum

    print(total)


if __name__ == "__main__":
    main()

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

numOdd = sum([A % 2 for A in As])

if numOdd == 0:
    print([2 ** N, 0][P])
else:
    print(2 ** (N - 1))

Solution (Python):

import sys
input = sys.stdin.readline

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

    A = list(map(lambda x: x % 2, A))
    if A.count(1):
        ans = pow(2,N-1)
    else:
        if P == 0:
            ans = pow(2,N)
        else:
            ans = 0

    print(ans)

if __name__ == '__main__':
    main()

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

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

ans = 0

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

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

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

n, p = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]


binary = 0
nonBinary = 0
for i in range(n):
    if a[i] % 2 == 0:
        binary += 1
    else:
        nonBinary += 1
if p == 0:
    count = 0
    for i in range(nonBinary+1):
        if i % 2 == 0:
            count += combinations_count(nonBinary, i)
    count *= 2 ** binary
    print(count)
else:
    count = 0
    for i in range(1, nonBinary + 1):
        if i % 2 == 1:
            count += combinations_count(nonBinary, i)
    count *= 2 ** binary
    print(count)

Solution (Python):
N,P = map(int, input().split())
A = list(map(lambda x:int(x)%2, input().split()))
A0 = A.count(0)
A1 = A.count(1)
if P == 1:
    if A1 == 0:
        print(0)
    else:
        print(2**(A1-1)*2**A0)
else:
    if A1 == 0:
        print(2**A0)
    else:
        print(int(2**(A1-1)*2**A0))

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

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

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

Solution (Python):
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def main() -> None:
    n, p = [next_int() for _ in range(2)]
    odd = even = 0

    for i in range(n):
        a = next_int()
        odd += a % 2
        even += (a % 2) ^ 1

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


if __name__ == '__main__':
    main()

Solution (Python):
N, P = map(int, input().split())
A = list(map(lambda x:int(x)%2, input().split()))
one = A.count(1)
zero = A.count(0)
if P == 1:
    if one == 0:
        print(0)
    else:
        print(2**(one-1)*2**zero)
else:
    if one == 0:
        print(2**zero)
    else:
        print(int(2**(one-1)*2**zero))

Solution (Python):
N, P = [int(_) for _ in input().split()]
A = [int(_) % 2 for _ in input().split()]
dp_e = 1
dp_o = 0
for a in A:
    if a:
        dp_e += dp_o
        dp_o = dp_e
    else:
        dp_e *= 2
        dp_o *= 2
if P:
    print(dp_o)
else:
    print(dp_e)