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

    evenchoice = pow(2, even)
    if odd == 0:
        if P == 0: return evenchoice
        else: return 0
    else:
        oddchoice = pow(2, odd) // 2
    return evenchoice * oddchoice

if __name__ == '__main__':
    print(main())

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

Solution (Python):
import math


def combi(a, b):
    ans = math.factorial(a) / (math.factorial(a - b) * math.factorial(b))
    return ans


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

even = 0
odd = 0

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

even_n = 0
for i in range(0, even + 1):
    even_n += combi(even, i)
odd_n = 0
if P == 1:
    for i in range(1, odd + 1, 2):
        odd_n += combi(odd, i)
else:
    for i in range(0, odd + 1, 2):
        odd_n += combi(odd, i)

print(int(even_n * odd_n))

Solution (Python):
def main():
    n,p = map(int,input().split())
    ls = [int(x) for x in input().split()]
    flg = False

    for i in range(n):
        if ls[i]%2==1:
            flg = True
            break
    if flg :
        print(2**(n-1))

    else:
        if p == 0:
            print(2**n)
        else:
            print(0)
if __name__ == "__main__":
    main()

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

def main():
    N, P = map(int, input().split())
    a = list(map(int, input().split()))
    all_even = True
    for i in range(N):
        if a[i]&1:
            all_even = False
            break
    if all_even:
        if P:
            print(0)
        else:
            print(pow(2, N))
    else:
        print(pow(2, N-1))

if __name__ == "__main__":
    main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()


def nCr(n,r):
  if n<r:
    return 0
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

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

  la=[]
  lb=[]

  for x in l:
    if x%2==1:
      la.append(x)
    else:
      lb.append(x)

  
  bc=0
  for i in range(len(lb)+1):
    bc+=nCr(len(lb),i)
    

  ans=0
  for i in range(len(la)+1):
    if p==0:
      r=i*2
    else:
      r=i*2+1

    ans+=nCr(len(la),r)*bc

  return ans

print(main())

Solution (Python):
N, P = map(int, input().split())
a = list(map(int, input().split()))
odd = 0
for i in range(N):
    if a[i] % 2 != 0:
        odd += 1

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

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

n,p = map(int,input().split())
x = [int(i) for i in input().split()]
odd = 0
ans = 0
ans_tmp = 0
for i in x:
  if i%2:
    odd += 1

ans += 2**(n-odd)
tmp = odd//2
if p:
  if odd:
    for i in range(tmp):
      ans_tmp += cmb(odd,i*2+1)
else:
  if odd:
    tmp += 1
    for i in range(tmp):
      ans_tmp += cmb(odd,(i*2))
  else:
    ans_tmp = 1

ans *= ans_tmp
print(ans)

Solution (Python):
n, p = [ int(v) for v in input().split() ]
num_list = [ int(v)%2 for v in input().split() ]

dp_list = [ [ [0,0] for i in range(n+1) ] for j in range(n+1) ]
dp_list[0][0][0] = 1

for i, v in enumerate(num_list,1):
    dp_list[i][0] = [1,0]
    if v == 0:
        for j in range(1,n+1):
            if j == 1:
                dp_list[i][j][0] = dp_list[i-1][j][0] + 1
                dp_list[i][j][1] = dp_list[i-1][j][1]
            else:
                dp_list[i][j][0] = dp_list[i-1][j-1][0] + dp_list[i-1][j][0]
                dp_list[i][j][1] = dp_list[i-1][j-1][1] + dp_list[i-1][j][1]
    else:
        for j in range(1,n+1):
            if j == 1:
                dp_list[i][j][0] = dp_list[i-1][j][0] 
                dp_list[i][j][1] = dp_list[i-1][j][1] + 1
            else:
                dp_list[i][j][0] = dp_list[i-1][j-1][1] + dp_list[i-1][j][0]
                dp_list[i][j][1] = dp_list[i-1][j-1][0] + dp_list[i-1][j][1]


print(sum(list(zip(*dp_list[-1]))[p]))

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

import sys, math, fractions, itertools, collections, copy, heapq

MOD = 2  

def solve(N: int, P: int, A: "List[int]"):
    if len([a for a in A if a % 2 == 0]) == N:
        if P == 0:
            print(int(2**N))
        else:
            print(0)
    else:
        print(int(2**(N-1)))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    P = int(next(tokens))  
    A = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, P, A)

if __name__ == '__main__':
    main()

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

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



if P == 0: 
    ans = 2 ** A_0 
    if A_1 >= 1:
        tmp = 0
        
        for i in range(0, A_1 + 1, 2):
            tmp += conbination(A_1, i)
        ans *= tmp
else:
    ans = 2 ** A_0 
    tmp = 0
    
    for i in range(1, A_1 + 1, 2):
        
        tmp += conbination(A_1, i)
    ans *= tmp

print (ans)

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

dp = [[0, 0] for i in range(N)]

dp[0][0] = 1
dp[0][A[0] % 2] += 1

for i in range(1, N):
    dp[i][0] = dp[i - 1][0]
    dp[i][1] = dp[i - 1][1]
    dp[i][A[i] % 2] += dp[i - 1][0]
    dp[i][(A[i] + 1) % 2] += dp[i - 1][1]

print(dp[N - 1][P])

Solution (Python):
n, p = map(int, input().split())
A = list(map(int, input().split()))
even = len(list(filter(lambda x: x%2==0, A)))
odd = len(list(filter(lambda x: x%2==1, A)))
even_ans = 2 ** even
if odd == 0:
    if p == 0:
        odd_ans = 1
    else:
        odd_ans = 0
else:
    odd_ans = 2 ** odd // 2
print(even_ans * odd_ans)

Solution (Python):
n,p,*a=map(int,open(0).read().split());print(2**~-n*(any(x%2for x in a)or(1^p)*2))

Solution (Python):
n,p,*a=map(int,open(0).read().split());print(2**~-n*(any(x%2for x in a)or -2*~-p))

Solution (Python):
n,p,*a=map(int,open(0).read().split());print(int(2**n*(1^p,.5)[any(x%2for x in a)]))

Solution (Python):
n,p,*a=map(int,open(0).read().split());m=2**n
print((-m*~-p,m//2)[any(x%2for x in a)])

Solution (Python):
n,p,*a=map(int,open(0).read().split())
if any(i%2 for i in a):print(2**~-n)
else:
	if p:
		print(0)
	else:
		print(2**n)

Solution (Python):
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
if p == 0:
    if o == 0:
        print(2 ** n)
    else:
        print(2 ** (n - 1))
else:
    if o == 0:
        print(0)
    else:
        print(2 ** (n - 1))

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

nck = [[0 for i in range(100)] for j in range(100)]
def cb(n,m):
    if n == m:
        nck[n][m] = 1
    elif m == 0:
        nck[n][m] = 1
    else:
        if nck[n][m] == 0:
            nck[n][m] = cb(n-1,m-1) + cb(n-1,m)
    return nck[n][m]
b0 = b.count(0)
b1 = b.count(1)
if p == 0:
    s = 0
    for i in range(b1+1):
        if i%2 == 0:
            s+=cb(b1,i)*(2**b0)
    print(s)
else:
    s = 0
    for i in range(b1+1):
        if i%2 == 1:
            s += cb(b1,i)*(2**b0)
    print(s)

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

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

odd = 0
even = 0
for x in a:
    if x % 2 == 0:
        even += 1
    else:
        odd += 1
ans = 0
if odd == 0:
    if p == 1:
        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()))
check = True
for i in range(n):
    if a[i]%2 == 1:
        check = False
    
if check:
    if p == 1:
        print(0)
    else:
        print(2**n)
else:
    print(2**(n-1))

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,p = map(int,sys.stdin.readline().split())
a = list(map(int,sys.stdin.readline().split()))
fact = [1]*51
for i in range(1,51):
    fact[i] = fact[i-1]*i
def comb(n,r):
    return fact[n]//fact[n-r]//fact[r]
x = list(map(lambda x:x % 2,a))
c = x.count(1)
ans = 0
if p:
    for i in range(c+1):
        if i % 2:
            for j in range(n-c+1):
                ans += comb(c,i)*comb(n-c,j)
else:
    for i in range(c+1):
        if i % 2 == 0:
            for j in range(n-c+1):
                ans += comb(c,i)*comb(n-c,j)
print(ans)

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

o = sum(A)
e = N-o

fac = [1]*(N+1)
for i in range(1,N+1): fac[i] = fac[i-1]*i

def comb(n,k): return fac[n]//fac[k]//fac[n-k]

ans = 0
for i in range(P,o+1,2):
  ans += comb(o,i)

ans *= 2**e
print(ans)

Solution (Python):
import numpy as np
N, P = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A)
A = A % 2
A = list(A)
count0 = A.count(0)
count1 = A.count(1)



if P == 0 and count1 % 2 == 0:
    tmp = max(1, 2**(count1-1)) * 2**count0

elif P == 0 and count1 % 2 == 1:
    tmp = max(1, 2**(count1-1)) * 2**count0

elif P == 1 and count1 % 2 == 0:
    tmp = max(1, 2**(count1-1))* 2**count0

elif P == 1 and count1 % 2 == 1:
    tmp = max(1, 2**(count1-1)) * 2**count0 

if count1 == 0 and P ==1:
    tmp = 0

print(round(tmp))

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

Solution (Python):
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = 0
e = 0
for i in c:
    if i % 2 == 0:
        d += 1
    else:
        e += 1
if e == 0:
    if b == 0:
        print(2 ** a)
    else:
        print(0)
else:
    print(2 ** (a - 1))

Solution (Python):
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from copy import *

def Com(n, k):
    p, q = 1, 1
    for i in range(n-k+1, n+1):
        p *= i
    for i in range(2, k+1):
        q *= i
    return p//q

N, P = map(int, input().split())
A = list(map(int, input().split()))
o = 0
for x in A:
    if x % 2:
        o += 1
e = N-o
if P == 0:
    ans = int(pow(2, e))
    t = 1
    for i in range(2, o+1):
        if i % 2 == 0:
            t += Com(o, i)
    print(ans*t)
else:
    if o == 0:
        print(0)
    else:
        ans = int(pow(2, e))
        t = 0
        for i in range(1, o+1):
            if i % 2:
                t += Com(o, i)
        print(ans*t)

Solution (Python):

def main():
    n, p = tuple(map(int, input().rstrip().split()))
    A = tuple(map(lambda x: int(x) % 2, input().rstrip().split()))
    if sum(A) == 0:  
        print(2 ** n if p == 0 else 0)
    else:
        print(2 ** (n - 1))


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    n, p = tuple(map(int, input().rstrip().split()))
    A = tuple(map(int, input().rstrip().split()))
    e = sum(i % 2 == 0 for i in A)  
    if e == n:
        print(2 ** n if p == 0 else 0)
    else:
        print(2 ** (n - 1))


if __name__ == "__main__":
    main()

Solution (Python):
n,p=map(int,input().split())
l=list(map(int,input().split()))
l=[i%2 for i in l]
nodd=sum(l)
neven=n-nodd
ans=2**(neven+max(0,nodd-1))
if p==1:
    ans=2**n-ans
print(ans)

Solution (Python):
a, b = map(int, input().split())
c = list(map(int, input().split()))
e_odd = False
for i in c:
    if i % 2 == 1:
        e_odd = not e_odd
        break
if not e_odd:
    if b == 1:
        print(0)
    else:
        print(2 ** a)
else:
    print(2 ** (a-1))

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

Solution (Python):

def get_fact(n):
    temp = 1
    fac = [1]
    for i in range(1, n + 1):
        temp *= i
        fac.append(temp)
    return fac
def get_comb(n):  

    fac = get_fact(n)
    com  = [["error" for _ in range(n+1)] for _ in range (n + 1)]
    for i in range(n + 1):
        for j in range(i + 1):
            if  i >= j:
                com[i][j] = fac[i] // (fac[i-j] * fac[j])

    return com

N ,P  =list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))
As = list(map(lambda x :x%2 ,As))
one = As.count(1)
zero =As.count(0)
ans = 0
com = get_comb(N)
z = 0
for i  in range(zero + 1):
    z += com[zero][i]
o = 0
if P == 0:
    for i in range(0,one + 1 , 2):
        o += com[one][i]
else:
    for i in range(1,one + 1 , 2):
        o += com[one][i]
print(o * z)

Solution (Python):
n,p=map(int,input().split())
l=list(map(int,input().split()))
o=sum(1 for i in l if i%2==1)
e=len(l)-o
if o==0:
  if p==0:print(2**n)
  else:print(0)
else:
  print(2**(n-1))

Solution (Python):
N, P = map(int, input().split()) 
A = [0 if a % 2 == 0 else 1 for a in list(map(int, input().split()))]
odd = A.count(1)
even = A.count(0)

if (P == 1 and odd == 0 ):
    ans = 0
elif odd == 0:
    ans = 2**(len(A))
else:
    ans = 2**(len(A)-1)

print(ans)

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

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

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

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

N, P = map(int, input().split())
A = [int(i)%2 for i in input().split()]
m = Counter(A)
num0 = m[0]
num1 = m[1]
num = 0
if P == 0:
    for i in range(num1+1):
        if i%2 == 0:
            num += combinations_count(num1, i)
    print((2**num0)*num)
else:
    for i in range(num1+1):
        if i%2 == 1:
            num += combinations_count(num1, i)
    print((2**num0)*num)

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

odd = sum(A)
even = N - odd
import math

def Comb(a,b):
    if a>= b:
        return int(math.factorial(a)/(math.factorial(b)*math.factorial(a-b)))
    else:
        return 0
if P == 0:
    ans = 2**N
    for i in range(1,odd+1,2):
        ans -= Comb(odd,i)*(2**even)
    print(ans)
else:
    ans = 0
    for i in range(1,odd+1,2):
        ans += Comb(odd,i)*(2**even)
    print(ans)

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

e = 0
o = 0
for a in A:
    if a % 2 == 0:
        e += 1
    else:
        o += 1

if P == 1:
    print((2**e)*((2**o)//2))
else:
    print(2**N-(2**e)*((2**o)//2))

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


def comb(x, y):
    if y < 0 or y > x or x < 0:
        return 0
    ret = 1
    for i in range(1, y+1):
        ret *= x+1-i
        ret //= i
    return ret


ans = 0
for i in range(p, oc+1, 2):
    ans += comb(oc, i)
print(ans*2**zc)

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

Solution (Python):
n,p = map(int,input().split())
an = [int(i) for i in input().split()]
dpo = [0]*n
dpe = [0]*n

if an[0] % 2 == 0:
  dpe[0] = 2
else:
  dpo[0] = 1
  dpe[0] = 1
  
for i in range(1,n):
  if an[i] % 2 == 0:
    dpe[i] = dpe[i-1] * 2
    dpo[i] = dpo[i-1] * 2
  else:
    dpe[i] = dpe[i-1] + dpo[i-1]
    dpo[i] = dpo[i-1] + dpe[i-1]
if p:
  print(dpo[n-1])
else:
  print(dpe[n-1])

Solution (Python):
import math

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

o_cnt = 0
e_cnt = 0

for i in range(n):
    if a[i] % 2 == 1:
        o_cnt += 1
    else:
        e_cnt += 1

ans = 0
for i in range(o_cnt//2):
    ans += (math.factorial(o_cnt)//(math.factorial(i*2+p)*math.factorial(o_cnt-i*2-p)))*2**e_cnt
    if i == o_cnt//2-1:
        if p == 0:
            ans += (math.factorial(o_cnt)//(math.factorial((i+1)*2+p)*math.factorial(o_cnt-(i+1)*2-p)))*2**e_cnt
        print(ans)

if o_cnt == 0:
    if p == 0:
        print(2**e_cnt)
    else:
        print(0)

Solution (Python):
from math import factorial as f
n,p=map(int,input().split())
a=[i%2 for i in list(map(int,input().split()))]
e=a.count(0);o=a.count(1)
def c(x,y):
    return f(x)//(f(x-y)*f(y))
v=0
for i in range(e+1):
  v+=c(e,i)
w=0
t=0 if p==0 else 1
for i in range(t,o+1,2):
  w+=c(o,i)
print(v*w)

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

for i in range(n):
    A[i]%=2
zero=A.count(0)
if zero==n and p==0:
    print(2**n)
elif zero==n and p==1:
    print(0)
else:
    print(2**(n-1))

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

odd = 0 
even = 0

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

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

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

N,P = [int(x) for x in input().split()]
A = [int(x)%2 for x in input().split()]
cnt_odd = 0
cnt_even = 0
cnt = 0
for i in A:
    if(i==1):
        cnt_odd+=1
    else:
        cnt_even+=1
if(cnt_odd==0):
    if(P==1):
        print(0)
    else:
        print(1<<cnt_even)
else:
    i = 0
    while(cnt_odd>=i*2+P):
        cnt+=combinations_count(cnt_odd,i*2+P)*(1<<cnt_even)
        i+=1
    print(cnt)

Solution (Python):
def combination(n, r):
    r = min(r, n-r)
    tmp = 1
    for i in range(r):
        tmp *= (n-i)
    for i in range(r):
        tmp //= (i+1)
    return tmp


def main():
    N, P = map(int, input().split())
    A = list(map(int, input().split()))
    odds = 0
    for a in A:
        if a % 2 == 1:
            odds += 1
    ans = 0
    for i in range(P, odds+1, 2):
        ans += combination(odds, i)
    ans *= 2**(N-odds)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n,p,*a=map(int,open(0).read().split());print(2**~-n*any(b&1for b in a)or(1^p)*2**n)

Solution (Python):
n,p,*a=map(int,open(0).read().split());print(2**~-n*any(b&1for b in a)or(1^p)*2**n)

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

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

Solution (Python):
from functools import reduce

def binom(n, r):
    if n < r or n < 0 or r < 0: return 0
    
    if n - r < r: r = n - r
    if r == 0: return 1
    elif r == 1: return n

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

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

N, P = map(int, input().split())
*A, = map(int, input().split())
even = 0; odd = 0;
for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1
ans = 2**even
temp = 0
if P == 0:
    for i in range(0, odd+1, 2):
        temp += binom(odd, i)
else:
    for i in range(1, odd+1, 2):
        temp += binom(odd, i)
ans *= temp
print(ans)

Solution (Python):
from math import factorial

def comb(m, n):
    return factorial(m) // factorial(n) // factorial(m-n)

def solve(n, p, a):
    n_odd = len(list(filter(lambda _:_%2, a)))
    n_even = n - n_odd
    v = 2**n_even
    w = sum([comb(n_odd, k) for k in range(p, n_odd+1, 2)])
    return v * w

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

Solution (Python):
from math import factorial

def comb(m, n):
    return factorial(m) // factorial(n) // factorial(m-n)

def solve(n, p, a):
    n_odd = len(list(filter(lambda _:_%2, a)))
    n_even = n - n_odd
    v = 2**n_even
    w = sum([comb(n_odd, k) for k in range(p, n_odd+1, 2)])
    return v * w

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

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

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

a1 = a.count(1)
a0 = a.count(0)

if a1>0:
    print(2**a0*2**(a1-1))
else:
    if p == 1:
        print(0)
    else:
        print(2**a0)

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

odd = sum(x&1 for x in A)

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

print(answer)

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

Solution (Python):
from sys import stdin
from scipy.misc import comb
import numpy as np
N,P = [int(x) for x in stdin.readline().rstrip().split()]
data = [int(x) for x in stdin.readline().rstrip().split()]
even = 0
odd  = 0
for i in data:
    if i % 2 == 0:
        even += 1
    else:
        odd  += 1
ans = 0
if P == 0:
    for j in range(0,odd+1,2):
        ans += (comb(odd,j,exact=True) * 2 ** even)
else:
    for j in range(1,odd+1,2):
        ans += (comb(odd,j,exact=True) * 2 ** even)

print(ans)

Solution (Python):
import math
n, p = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
odd = 0; even = 0
for item in a:
    if item % 2 == 0:
        even += 1
    else:
        odd += 1
if p == 0:
    ans = 1
    for i in range(1, odd // 2 + 1):
        ans += math.factorial(odd) // math.factorial(i*2) // math.factorial(odd - i * 2)
    print(pow(2,even) * ans)
elif p == 1:
    ans = 0
    for i in range(odd // 2):
        ans += math.factorial(odd) // math.factorial(i*2 + 1) // math.factorial(odd - (i * 2 + 1))
    print(pow(2,even) * ans)

Solution (Python):
num_bags, congr_factor = list(map(int, input().split()))
bags = list(map(int, input().split()))
odd_bags = len([bag for bag in bags if (bag % 2 == 1)])

if congr_factor == 0 and odd_bags == 0:
  print(2 ** num_bags)
elif congr_factor == 1 and odd_bags == 0:
  print(0)
else:
  print(2 ** (num_bags-1))

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
from math import factorial
n,p=map(int,input().split())
l=np.asarray(list(map(int,input().split())))
l%=2
o=np.sum(l)
e=n-o
def comb(n,r):
    return factorial(n)//factorial(n-r)//factorial(r)
ans=0
for i in range(p,o+1,2):
    ans+=comb(o,i)*(2**e)
print(ans)

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

c0=a.count(0)
c1=n-c0

def c(n,m):
    import math
    if n-m<0:
        return 0
    return(math.factorial(n)//math.factorial(n-m)//math.factorial(m))

q=0
for i in range(c0+1):
    q+=c(c0,i)


i=p
ans=0
while i<=c1:
    ans+=c(c1,i)*q
    i+=2
print(ans)

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

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

Solution (Python):

"""
A - Biscuits
https://atcoder.jp/contests/agc017/tasks/agc017_a

"""
import sys

from math import factorial

def solve(N, P, A):
    even = len([a for a in A if a%2==0])
    odd = len([a for a in A if a%2==1])
    ans = 0
    if P == 0:
        for i in range(0, odd+1, 2):
            ans += 2 ** even * factorial(odd) // factorial(odd - i) // factorial(i)
    else:
        for i in range(1, odd+1, 2):
            ans += 2 ** even * factorial(odd) // factorial(odd - i) // factorial(i)
    return ans


def main(args):
    N, P = map(int, input().split())
    A = [int(a) for a in input().split()]
    ans = solve(N, P, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

Solution (Python):
def check(a):
    for i in a:
        if i%2:
            return True
    return False

n,p = map(int, input().split())
a = list(map(int,input().split()))
if check(a):
    print(2**(n-1))
elif p==0:
    print(2**n)
else:
    print(0)

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

def frac(x):
    l = len(f)
    if not(l > x) :
        for i in range(x-l+1):
            f.append(f[-1]*(l+i))
    return f[x]

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

a = 0
while P <= odd:
    a += frac(odd) // frac(P) // frac(odd-P)
    P += 2
print(a * 2 ** even)

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

E = 2**even
if P == 0:
    O = 1
    o = 1
    for i in range(2, odd+1, 2):
        o = int(o*(odd+1-i)*(odd+2-i)/i/(i-1))
        O += o
else:
    O = odd
    o = odd
    for i in range(3, odd+1, 2):
        o = int(o*(odd+1-i)*(odd+2-i)/i/(i-1))
        O += o
print(E*O)

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

Solution (Python):
def nCr(n, r):
    ret = 1
    for i in range(1, n+1):
        ret *= i
    for i in range(1, r+1):
        ret //= i
    for i in range(1, n-r+1):
        ret //= i
    return ret

n, p = map(int, input().split())
a = map(int, input().split())
even, odd = 0, 0

for i in a:
  if i & 1:
    odd += 1
  else:
    even += 1

c_even = 2**even
c_odd = 0

start = 1 if p else 0

while start <= odd:
    c_odd += nCr(odd, start)
    start += 2

print(c_even * c_odd)

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

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

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

Solution (Python):
import math

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

n, p = map(int, input().split())
a = [(int(i) % 2) for i in input().split()]
e_num = a.count(0)
o_num = a.count(1)
all_pattern = 2 ** n
o_p = 2 ** (e_num)
o_pattern = o_p
if o_num >= 2:
    for i in range(2, o_num + 1, 2):
        o_pattern += (combinations_count(o_num, i) * o_p)
e_pattern = all_pattern - o_pattern
if p == 1:
    print(e_pattern)
else:
    print(o_pattern)

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

e = sum(x % 2 == 0 for x in a)
o = sum(x % 2 == 1 for x in a)

if n == 1:
    ans = int(a[0] % 2 == p)
elif p == 1 and o == 0:
    ans = 0
else:
    ans = max((2 ** o) // 2, 1) * 2 ** e

print(ans)

Solution (Python):
import math
n,p=map(int,input().split())
A=[int(i) for i in input().split()]
def com(i,j):
  return math.factorial(i)//math.factorial(i-j)//math.factorial(j)
k=0
for a in A:
  if a%2==0:
    k+=1
ans=2**k
mult=0
for i in range((n-k)//2+1):
  mult+=com(n-k,2*i)
ans*=mult
print(ans if p==0 else 2**n-ans)

Solution (Python):
n,p = map(int,input().split())
A = [int(i)%2 for i in input().split()]
from collections import Counter
from math import factorial 
D = Counter(A)
one = 0
for i in range(p%2,D[1]+1,2):
    one += factorial(D[1])//(factorial(i)*factorial(D[1]-i))
print((2**D[0])*one)

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

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