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 com(x,y):
    buns = 1
    bunb = 1
    for i in range(y):
        buns = buns * (x-i)
        bunb = bunb * (i+1)
    d = buns // bunb
    return d

n , p = map(int,input().split())
a = list(map(int,input().split()))
kisu = 0
gusu = 0
for i in a:
    if i % 2 == 0:
        gusu += 1
    if i % 2 == 1:
        kisu += 1

kar = 0
if p == 0:
    for i in range(0,kisu+1,2):
        kar += com(kisu,i)
    print(2**gusu * kar)
elif p == 1:
    for i in range(1,kisu+1,2):
        kar += com(kisu,i)
    print(2**gusu * kar)

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

odd = A.count(1)
even = N - odd
if odd:
    print(2 ** (N-1))
else:
    print(0 if P else 2 ** N)

Solution (Python):
import math
def naive_cmb(n, r):
    if r < 0 or r > n:
        return 0
    return (math.factorial(n) // math.factorial(r)) // math.factorial(n-r)

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

ans = 0
a = A.count(1)
b = A.count(0)

if P == 1:
    for i in range(1, a+1, 2):
        ans += naive_cmb(a, i)
    ans *= 2**b
else:
    for i in range(0, a+1, 2):
        ans += naive_cmb(a, i)
    ans *= 2**b

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 0
    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 = list(map(lambda x:x%2, A))
n0 = B.count(0)
n1 = B.count(1)
ans = 0
if P==0:
  for i in range(0,n0+1):
    for j in range(0,n1+1,2):
      ans += cmb(n0,i)*cmb(n1,j)
else:
  for i in range(0,n0+1):
    for j in range(1,n1+1,2):
      ans += cmb(n0,i)*cmb(n1,j)
print(ans)

Solution (Python):
import numpy as np
n,p = map(int,input().split())
A = np.array(list(map(int,input().split())))
flg = np.all(A%2==0)
print( 2**n if flg and p==0 else 0 if flg else 2**(n-1))

Solution (Python):
n, p, *a = map(int, open(0).read().split())
print([[2**n, 0][p], 2**~-n][sum(i%2 for i in a)>0])

Solution (Python):
import math
 
def combination(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)
 

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

t = list(map(int,input().split()))

gu = 0

ki = 0

for i in t:
    if i%2==0:
        gu += 1
    else:
        ki += 1

gukumi = 0

kikumi = 0

for i in range(1,gu+1):
    gukumi += combination(gu,i)

if p == 0:
    for i in range(2,ki+1,2):
        kikumi += combination(ki,i)
    ans = kikumi+1+gukumi
else:
    for i in range(1,ki+1,2):
        kikumi += combination(ki,i)
    ans = kikumi
    

ans += gukumi*kikumi

print(ans)

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

zero = ai.count(0)
one = ai.count(1)





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)]

tmp = 2**zero
ans = 0
for i in range(one//2+1):
    if p == 0:
        if i*2 > one:
            break
        ans += cmb(one,0+i*2)
    else:
        if i*2+1 > one:
            break
        ans += cmb(one,1+i*2)
print(int(ans*tmp))

Solution (Python):
import math
def combinations(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()))
n0=0
n1=0
ans=0
for i in range(len(a)):
  if a[i]%2:
    a[i]=1
    n1+=1
  else:
    a[i]=0
    n0+=1
s=sum(a)
for i in range(0,s+1,2):
  ans+=combinations(n1,i)
  if p==1 and s==0:
    print(0)
    exit()
print(ans*(2**n0))

Solution (Python):
import numpy as np
def combinations(n,k,mod=10**9+7):
    x,y = 1,1
    for i in range(k):
        x = (x*(n-i))%mod
        y = (y*(i+1))%mod
    y = pow(y,mod-2,mod)
    return (x*y)%mod

N,P = map(int,input().split())
a = np.array(list(map(int,input().split())))%2
a1 = np.count_nonzero(a==1)
a0 = np.count_nonzero(a==0)

ans = 0
for i in range(P,a1+1,2):
    ans += combinations(a1,i)

print(ans*(2**a0))

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

sum = [0, 0]
for i in input().split():
    sum[int(i)%2] += 1

def nCr(n, r):
    a, b = 1, 1
    for i in range(1, r+1):
        a *= n - (i-1)
        b *= i
    return a // b

ans = 0
if P == 0:
    for i in range(N+1):
        for j in range(0, i+1, 2):
            if sum[0] < i-j: continue
            if sum[1] < j: continue
            ans += nCr(sum[0], i-j) * nCr(sum[1], j)
else:
    for i in range(N+1):
        for j in range(1, i+1, 2):
            if sum[0] < i-j: continue
            if sum[1] < j: continue
            ans += nCr(sum[0], i-j) * nCr(sum[1], j)

print(ans)

Solution (Python):
def impossible(a,b,P):
    if(b == 0 and P == 1):
        return True
    if(a == 0 and b == 1 and P == 0):
        return True
    
    return False

def func():
    N,P = map(int,input().split())

    lists = list(map(int,input().split()))
    dp = [0] * 2

    for l in lists:
        if(l % 2 == 0):
            dp[0] += 1
        else:
            dp[1] += 1
    ans = 2 ** dp[0]
    if(dp[1] > 0):
        ans *= 2 ** (dp[1] - 1)
    else:
        ans *= 1

    if(impossible(dp[0],dp[1],P)):
        ans = 0

    print(ans)
func()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    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
    odd=N-even

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

resolve()

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

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

if odd_n == 0:
    if p == 0:
        print(2**n)
    else:
        print(0)

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

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()))
zero = 0
one = 0
for i in range(n):
    if a[i] % 2 == 0:
        zero += 1
    else:
        one += 1

if p == 0:
    count = 1
    r = 2
else:
    count = 0
    r = 1

while r <= one:
    count += comb(one, r)
    r += 2

print(2**zero*count)

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

from math import ceil
def comb(n,r):
    ans = 1
    for i in range(r):
        ans *= n-i
    for i in range(1,r+1):
        ans //= i
    return ans

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

if P%2==0:
    ans = 0
    for i in range(int(odd/2)+1):
        ans += comb(odd,2*i)
else:
    ans = 0
    for i in range(1,ceil(odd/2)+1):
        ans += comb(odd,2*i-1)
ans *= 2**even
print(ans)

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)
base=2**a0

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

if p==1:
  ans=0
  for i in range((a1+1)//2):
    b=combinations_count(a1, 2*i+1)
    ans+=base*b
  print(ans)
else:
  ans=0
  for i in range(a1//2+1):
    b=combinations_count(a1, 2*i)
    ans+=base*b
  print(ans)

Solution (Python):

from math import factorial
N, P = map(int, input().split())
A = list(map(int, input().split()))
odd, even = 0, 0
for i in range(N):
    if A[i] % 2 == 0:
        even += 1
    else:
        odd += 1
ans = 0
if P == 0:
    for i in range(0, odd+1, 2):
        ans += factorial(odd) // (factorial(i) * factorial(odd-i)) * 2**even
else:
    for i in range(1, odd, 2):
        ans += factorial(odd) // (factorial(i) * factorial(odd - i)) * 2**even
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()))

cnt_0 = sum([a % 2 == 0 for a in A])
cnt_1 = sum([a % 2 != 0 for a in A])

ans = 0

if P == 0:
    ans += 1
for k in range(1, N + 1):
    for i in range(0, k + 1):
        j = k - i
        if i > cnt_0 or j > cnt_1:
            continue
        if P == 0 and j % 2 == 0:
            ans += cmb(cnt_0, i) * cmb(cnt_1, j)
        elif P == 1 and j % 2 == 1:
            ans += cmb(cnt_0, i) * cmb(cnt_1, j)

print(ans)

Solution (Python):













n,p = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
ans = 0
fact = [1]*(n+1)

for i in range(1,n+1):
    fact[i] = fact[i-1]*i
def C(x,y):
    return fact[x]//fact[y]//fact[x-y]
    
    
for x in a:
    if x %2 == 1:
        cnt += 1
if p :
    for i in range(1,n+100,2):
        if i >cnt:break
        ans += C(cnt,i)*(2**(n-cnt))
else:
    for i in range(0,n+100,2):
        if i > cnt:break
        ans += C(cnt,i)*(2**(n-cnt))
print(ans)

Solution (Python):
n,p = map(int,input().split())
a  = list(map(int,input().split()))
cnt = 0
for x in a:
    if x%2:cnt+=1
if cnt == 0:
    if p:ans = 0
    else:ans = 2**n
else:
    ans = 2**(n-1)
print(ans)

Solution (Python):
n,p = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
ans = 0
fact = [1]*(n+1)

for i in range(1,n+1):
    fact[i] = fact[i-1]*i
def C(x,y):
    return fact[x]//fact[y]//fact[x-y]
    
    
for x in a:
    if x %2 == 1:
        cnt += 1
if p :
    for i in range(1,n+100,2):
        if i >cnt:break
        ans += C(cnt,i)*(2**(n-cnt))
else:
    for i in range(0,n+100,2):
        if i > cnt:break
        ans += C(cnt,i)*(2**(n-cnt))
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

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

for i, a in enumerate(A):
	if a%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][1]+dp[i][0]
		dp[i+1][1] = dp[i][0]+dp[i][1]

print(dp[N][P])

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

fact = [0]*(51)
fact[0] = 1

for i in range(1, 51):
	fact[i] = i*fact[i-1]

def Conv(n, r):
	return fact[n]//fact[r]//fact[n-r]

C = Counter([x%2 for x in A])

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

ans *= pow(2, C[0])
print(ans)

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

def ncr(n, r, p):
  num = den = 1
  for i in range(r):
    num = (num * (n - i)) % p
    den = (den * (i + 1)) % p
  return (num * pow(den, p - 2, p)) % p
p=10**9+7
odd = sum(A)
even = N- odd

ans = 0
if P == 0:
  c = 0
  for i in range(0, odd+1, 2):
    c += ncr(odd, i, p)
  ans += pow(2, even) * c

else:
  c = 0
  for i in range(1, odd+1, 2):
    c += ncr(odd, i, p)
  ans += pow(2, even) * c
    
print(ans)

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

odd_cnt = L.count(1)
eve_cnt = L.count(0)

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

Solution (Python):
from math import factorial


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


n,p=map(int,input().split())
A=list(map(int,input().split()))
A=[A[i]%2 for i in range(n)]

cnt=A.count(0)
ans=0
for i in range(p,n-cnt+1,2):
    ans +=cmb(n-cnt,i)
print(ans*(2**cnt))

Solution (Python):
from math import factorial


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


n,p=map(int,input().split())
A=list(map(int,input().split()))
A=[A[i]%2 for i in range(n)]

cnt=A.count(0)
B=2**cnt

ans=0
for i in range(p,n-cnt+1,2):
    ans +=cmb(n-cnt,i)
print(ans*B)

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

x=dict()
x[0]=0
x[1]=0
for i in range(K):
    if A[i]%2==0:
        x[0]+=1
    else:
        x[1]+=1
if x[1]==0:
    if P==0:
        print(2**K)
    else:
        print(0)
    exit()
print(2**(K-1))

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

    odd_cnt = 0
    even_cnt = 0

    for a in A:
        if a % 2 == 0:
            even_cnt += 1
        else:
            odd_cnt += 1
    
    odd_perm = 0
    for r in range(0,odd_cnt+1,2):
        odd_perm += n_combination(odd_cnt, r)
    
    if P == 0:
        print(odd_perm * pow(2,even_cnt))
    else:
        print(pow(2,N) - (odd_perm * pow(2,even_cnt)))
        
def n_combination(n, r):
    numer_sum = 1
    denom_sum = 1
    for i in range(r):
        numer_sum *= n - i
        denom_sum *= r - i
    
    return numer_sum // denom_sum
if __name__ == '__main__':
    solve()

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

Solution (Python):
n,p = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

a_odd = [x for x in a if x % 2 == 1]

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

Solution (Python):
import sys
from math import factorial
def main():
    packages, remainder = receiveInputData()

    packages.countOddAndEven()

    even_ways = packages.calculateEvenWays()
    odd_ways_remainder0, odd_ways_remainder1 = packages.calculateOddWays()

    if remainder.isZero():
        print(even_ways * odd_ways_remainder0)
        return

    print(even_ways * odd_ways_remainder1)






class Package():
    def __init__(self, packages_list, packages_num):
        if not isinstance(packages_list, list):
            print('Package Class argument error')
            sys.exit(1)

        
        if packages_num < 1 or packages_num > 50:
            print('Package Class Restriction error')
            print(packages_num)
            sys.exit(1)

        self.packages = packages_list
        self.packages_num = packages_num

    
    def countOddAndEven(self):
        self.packages_num_of_odd_biscuits  = 0
        self.packages_num_of_even_biscuits = 0
        for pack_i, biscuits_num in enumerate(self.packages):
            if biscuits_num % 2 == 0:
                self.packages_num_of_even_biscuits += 1
            else:
                self.packages_num_of_odd_biscuits += 1

    
    
    
    def calculateEvenWays(self):
        return 2 ** self.packages_num_of_even_biscuits

    def calculateOddWays(self):
        count_combination_list = self.calculateCombination(self.packages_num_of_odd_biscuits)

        
        
        selected_even_odds = sum(count_combination_list[::2])

        
        
        selected_odd_odds = sum(count_combination_list[1::2])

        return selected_even_odds, selected_odd_odds

    def calculateCombination(self,n):
        
        select_ways_of_odd = [1]
        for select_num in range(1,n + 1):
            n_C_i = factorial(n) // (factorial(select_num) * factorial(n - select_num))
            select_ways_of_odd.append(n_C_i)
        return select_ways_of_odd











class Remainder():
    def __init__(self, remainder_0or1):
        if not isinstance(remainder_0or1, int):
            print('Remainder Class argument error')
            sys.exit(1)

        
        if remainder_0or1 != 0 and remainder_0or1 != 1:
            print('Remainder Class Restriction error')
            sys.exit(1)

        self.remainder = remainder_0or1


    def isZero(self):
        if self.remainder == 0:
            return True
        return False


def receiveInputData():

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

    return Package(A, N), Remainder(P)

if __name__ == '__main__':
    main()

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

Solution (Python):
n,p=map(int,input().split())
a=[int(x)%2 for x in input().split()]
even=0
for aa in a:
    if aa%2==0:
        even+=1

if even==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 = list(map(int, input().split()))


even_count = 0
odd_count = 0


for a in a_list:
    if a%2==0:
        even_count += 1
    else:
        odd_count += 1

if even_count==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(lambda x:int(x)%2,input().split()))
DP = [[0]*1000 for i in range(N+1)]
DP[0][0] = 1
for i in range(1,N+1):
    DP[i][0] = 1
    x = A[i-1]
    if x==0:
        DP[i][1] = DP[i-1][1]
    else:
        DP[i][1] = DP[i-1][1]+DP[i-1][0]
    for j in range(2,900):
        if x==0:
            DP[i][j] = DP[i-1][j-2]+DP[i-1][j]
        else:
            DP[i][j] = DP[i-1][j-1]+DP[i-1][j]
cnt = 0
for i in range(1000):
    if i%2==P:
        cnt += DP[N][i]
print(cnt)

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

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

odd = []
even = []
for i, aa in enumerate(a):
    if aa % 2 == 0:
        even.append(aa)
    else:
        odd.append(aa)
e = len(even)
o = len(odd)
ans = 2 ** e
od_list = [1]
bunsi = 1
bunbo = 1

for i in range(1,o+1):
    bunsi *= o - i + 1
    bunbo *= i
    od_list.append(bunsi//bunbo)
even_i = od_list[::2]
odd_i = od_list[1::2]


if p == 0:
    print(ans * sum(even_i))
    
else:
    print(ans * sum(odd_i))

Solution (Python):

class BiCoeff(object):
    def __init__(self, MAX, m):
        super(BiCoeff, self).__init__()
        fac = [0]*MAX
        finv = [0]*MAX
        inv = [0]*MAX

        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2,MAX):
            fac[i] = (fac[i-1]*i)%m
            inv[i] = m - (inv[m%i] * (m//i))%m
            finv[i] = (finv[i-1] * inv[i])%m

        self.MAX = MAX
        self.m = m
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def calc(self,n,k):
        if n<k:
            return 0
        if n<0 or k<0:
            return 0
        return (self.fac[n] * (self.finv[k]*self.finv[n-k])%self.m)%self.m

n,p = map(int, input().split())
al = list(map(int, input().split()))
bicoeff = BiCoeff(10**5,10**9+7)

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

r1 = 2**even
r2 = 0
for k in range(odd+1):
    if k%2==p:
        r2 += bicoeff.calc(odd, k)
print(r1*r2)

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

is_odd = False
for ai in a:
    if ai % 2 == 1:
        is_odd = True
        break

if is_odd:
    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,=map(int, input().split())
p = [0,0]
for a in A: p[a&1] += 1
even,odd=p[0],p[1]

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

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

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

if list(filter(lambda x:(x % 2 == 1), A)):
    print(2 ** (N -1))
else:
    if P == 0:
        print(2 ** N)
    else:
        print(0)

Solution (Python):
import math
n,p = map(int,input().split())
a = list(map(int,input().split()))
a = list(map(lambda x:x%2, a))
a0 = 0
a1 = 0
for i in range(n):
    if a[i] == 0:
        a0 += 1
    else:
        a1 += 1
if p == 0:
    cnt = 0
    for i in range(0, a1+1, 2):
        cnt += math.factorial(a1) // (math.factorial(i)*math.factorial(a1-i))
    print(2**a0*cnt)
else:
    cnt = 0
    for i in range(1,a1+1,2):
        cnt += math.factorial(a1) // (math.factorial(i) * math.factorial(a1 - i))
    print(2 ** a0 * cnt)

Solution (Python):
from math import factorial
N, P = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: x % 2, A))
counter = {'0': 0, '1': 0}
for a in A:
    c_a = str(a)
    counter[c_a] += 1

ans = 2 ** counter['0']
tmp = factorial(counter['1'])
tmp_ans = 0
for i in range(0 + P,counter['1'] + 1,2):
    tmp_ans += tmp / factorial(i) / factorial(counter['1'] - i)
print(int(tmp_ans * ans))

Solution (Python):
def main():
    N, P = (int(i) for i in input().split())
    A = [int(i) % 2 for i in input().split()]
    from collections import Counter
    c = Counter(A)
    if P == 0:
        odd = 2**(c[1]-1) if c[1] > 0 else 0
        even = 2**c[0]
        if 0 < odd:
            even *= odd
    else:
        odd = 2**(c[1]-1) if c[1] > 0 else 0
        even = 2**c[0]
        odd *= even
    print(odd if P == 1 else even)


if __name__ == '__main__':
    main()

Solution (Python):
from math import factorial
def cmb(n,r):
    if n-r<0:
        return 0
    else:
        return factorial(n) // factorial(r) // factorial(n - r)
        

n,p,*a=map(int,open(0).read().split())

odd=sum(i%2 for i in a)
even=n-odd


x=sum(cmb(even,i)for i in range(even+1))
y=sum(cmb(odd,i)for i in range(p,odd+1,2))
print(x*y)

Solution (Python):
def main():
    N, P = (int(i) for i in input().split())
    A = [int(i) % 2 for i in input().split()]
    from collections import Counter
    c = Counter(A)
    odd = 2**(c[1]-1) if c[1] > 0 else 0
    even = 2**c[0]
    if 0 < odd:
        even *= odd
    print(odd*2**c[0] if P == 1 else even)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np


def nCr(n, r, mod = 10**9+7):
    r = min(n-r, r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod


n, p = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=np.int)
A %= 2

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

base = 2 ** even
if p == 0:
    odd_to_even = 0
    for select in range(0, odd+1, 2):
        pattern = nCr(odd, select)
        odd_to_even += pattern

    print(base * odd_to_even)

else:
    odd_to_odd = 0
    for select in range(1, odd+1, 2):
        pattern = nCr(odd, select)
        odd_to_odd += pattern

    print(base * odd_to_odd)

Solution (Python):
N, P = map(int,input().split())
A = list(map(int,input().split()))
B = [A[k]%2 for k in range(N)]
dp = [[0,0] for k in range(N+1)]
dp[0][0] = 1

for k in range(N):
    if B[k] == 0:
        dp[k+1][0] = dp[k][0]*2
        dp[k+1][1] = dp[k][1]*2
    else:
        dp[k+1][0] = dp[k][0] + dp[k][1]
        dp[k+1][1] = dp[k][0] + dp[k][1]

print(dp[N][P])

Solution (Python):
import sys

def comb(n, r):
    ans = 1
    for i in range(r): ans *= (n - i)
    for i in range(r): ans //= (i + 1)
    return ans

def solve():
    input = sys.stdin.readline
    N, P = map(int, input().split())
    A = [int(a) for a in input().split()]
    even, odd = 0, 0
    for a in A:
        if a % 2 == 0: even += 1
        else: odd += 1
    
    even_Chose = 0
    odd_Chose = 0
    for i in range(even + 1): even_Chose += comb(even, i)
    for i in range(odd + 1):
        if i % 2 == P: odd_Chose += comb(odd, i)
    print(even_Chose * odd_Chose) 

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
import math

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

odd = list(filter(lambda x:(x % 2 == 1), A))
even = list(filter(lambda x:(x % 2 == 0), A))


odd_num = len(odd)
even_num = len(even)

ans = 0

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


ans = 0
for o in range(0, odd_num + 1):
    for e in range(0, even_num + 1):
        
        if P == 0:
            if o % 2 == 0:
                
                ans += comb(odd_num, o) * comb(even_num, e)
        else:
            if o % 2 == 1:
                ans += comb(odd_num, o) * comb(even_num, e)

print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False


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

N = 200  
mod = pow(10, 50) + 7
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)


n, p = MAP()
a = LIST()
arr = [i % 2 for i in a]
num1 = sum(arr)
num0 = n - num1
ans = 0
for i in range(n + 1): 
    for j in range(i + 1): 
        if j % 2 == p:
            ans += cmb(num1, j) * cmb(num0, i - j)
print(ans)

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

cnt_odd = sum([int((Ai % 2) == 1) for Ai in A])
cnt_evn = N - cnt_odd

ptn_evn = 1 << cnt_evn

tab_ncr = [1]
ncr_tmp = 1
for i in range(cnt_odd):
    ncr_tmp *= (cnt_odd - i)
    ncr_tmp //= (i + 1)
    tab_ncr.append(ncr_tmp)

ans = 0


for i in range(cnt_odd + 1):
    if i % 2 != P: continue
    
    ans += (ptn_evn * tab_ncr[i])

print(ans)

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

A = [a%2 for a in A]

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

ans = 0
import math
if p == 0:
    for i in range(o+1):
        if i%2 == 0:
            ans += math.factorial(o)//(math.factorial(i)*math.factorial(o-i))
    ans *= 2**e
else:
    for i in range(o+1):
        if i%2 == 1:
            ans += math.factorial(o)//(math.factorial(i)*math.factorial(o-i))
    ans *= 2**e
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
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: odd += 1
  else: even += 1
if P:
  print(int((pow(2, odd - 1) * pow(2, even) * (odd > 0))))
else:
  print(max(1, pow(2, odd - 1)) * pow(2, even))

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

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

Solution (Python):



if False:
    N=int(input())
    A=[int(i) for i in input().split()]
    ans=[(i,a) for i,a in enumerate(A)]
    ans.sort(key=lambda x: x[1],reverse=True)
    for i in range(N): print(ans[i][0]+1)


if True:
    N,P=map(int,input().split())
    A=[int(i) for i in input().split()]
    flag=True 
    for a in A:
        if a%2==1:
            flag=False
            break
    if flag:
        if P==0:
            print(2**N)
        else:
            print(0)
    else:
        print(2**(N-1))