Problem:
 Score : 200 points    Problem Statement There are N bags of biscuits. The i -th bag contains A_i biscuits.  Takaki will select some of these bags and eat all of the biscuits inside.
Here, it is also possible to select all or none of the bags.  He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2 .
How many such ways to select bags there are?      Constraints  1 \leq N \leq 50  P = 0 or 1  1 \leq A_i \leq 100         Input Input is given from Standard Input in the following format:  N  P  A_1  A_2 ... A_N       Output Print the number of ways to select bags so that the total number of biscuits inside is congruent to P modulo 2 .        Sample Input 1 2 0
1 3      Sample Output 1 2  There are two ways to select bags so that the total number of biscuits inside is congruent to 0 modulo 2 :   Select neither bag. The total number of biscuits is 0 .  Select both bags. The total number of biscuits is 4 .        Sample Input 2 1 1
50      Sample Output 2 0       Sample Input 3 3 0
1 1 1      Sample Output 3 4  Two bags are distinguished even if they contain the same number of biscuits.       Sample Input 4 45 1
17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26      Sample Output 4 17592186044416

Solution (Python):
from math import factorial
n,p = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
x = 0
for i in a:
	if i%2==0: x+=1
y = n-x
if p==0:
	num,fy = 0,factorial(y)
	for i in range(0,y+1,2):
		num += fy//(factorial(i)*factorial(y-i))
	print((2**x)*num)
else:
	num,fy = 0,factorial(y)
	for i in range(1,y+1,2):
		num += fy//(factorial(i)*factorial(y-i))
	print((2**x)*num)

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

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

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

print(ans)

Solution (Python):
N,P=map(int,input().split())
nums = list(map(int,input().split()))
even,odd = 0,0
for num in nums:
  if num%2 == 0:
    even +=1
  else:
    odd +=1
if odd == 0:
  if P == 1:
    print(0)
  else:
    print(2**even)
else:
  print((2**even)*(2**odd)//2)

Solution (Python):
'''
方針：各Aiをそれぞれ見て、いくつ偶数があっていくつ奇数があるかを数える。
以下偶数がX個、奇数がY個あるとする。(X+Y=N,0≦X,Y)
そしてこの問題は偶数の集合の中からの選ぶことと奇数の集合の中から選ぶことを独立に考えることができる。
よって（偶数の集合からの選び方）×（奇数の集合からの選び方）で求めることができる。
（偶数の集合からの選び方）については、どのように選んでも全体の合計を2で割った余りは変わらないので全事象を考えることができる。
よって2^Xである。
（奇数の集合からの選び方）についてはY個のうちk個（k≡P mod 2）である場合の数の合計なので
Σ[k:0→Y and k≡P mod 2]C(Y,k)である。
ただし、C(Y,k)は二項係数を表していて、Σ[k:0→Y and k≡P mod 2]は0≦k≦Nかつk≡P mod 2であるものすべてを足し合わせたという意味である。
'''
def C(n,m):
    S=1
    for i in range(1,n+1):
        S=S*i
    for i in range(1,m+1):
        S=S//i
    for i in range(1,n-m+1):
        S=S//i
    return S
N,P=map(int,input().split())
A=[int(i) for i in input().split()]
X=0;Y=0


for i in range(N):
    if A[i]%2==0:
        X+=1
    else:
        Y+=1
Z=0
for i in range(Y+1):
    if i%2==P:
        Z+=C(Y,i)
print(Z*2**(X))

Solution (Python):
def C(n,m):
    S=1
    for i in range(1,n+1):
        S=S*i
    for i in range(1,m+1):
        S=S//i
    for i in range(1,n-m+1):
        S=S//i
    return S
N,P=map(int,input().split())
A=[int(i) for i in input().split()]
X=0;Y=0


for i in range(N):
    if A[i]%2==0:
        X+=1
    else:
        Y+=1
Z=0
for i in range(Y+1):
    if i%2==P:
        Z+=C(Y,i)
print(Z*2**(X))

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

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

Solution (Python):
def combination(total, selected):
    foo = 1
    for i in xrange(selected):
        foo *= total-i
        foo /= i+1
    return foo

def process(a, p):
    odds = 0
    even = 0
    for x in a:
        if (x%2)==0:
            even += 1
        else:
            odds += 1
    foo = 0
    for i in xrange(p, odds+1, 2):
        foo += combination(odds, i)
    foo *= 1<<even
    return foo

def main():
    n, p = [int(x) for x in raw_input().strip().split()]
    a = [int(x) for x in raw_input().strip().split()]
    print process(a, p)

if __name__ == '__main__':
    main()

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


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

num1 = A.count(1)
num0 = A.count(0)

if P == 0:
	if num1 <= 1:
		print(2 ** (num0))
	else:
		print(2 ** (num0 + num1 - 1))
else:
	if num1 == 0:
		print(0)
	else:
		print(2 ** (num0 + num1 - 1))

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

C = {(0,0):1}
def comb(n,k):
    if n == 0 or k == 0 or k == n:
        return 1
    else:
        if (n,k) in C:
            return C[(n,k)]
        else:
            C[(n,k)] = comb(n-1,k) + comb(n-1,k-1)
            return C[(n,k)]
m = 0
if P == 0:
    for i in range(0,odd+1,2):
        m += int(comb(odd,i))
else:
    for i in range(1,odd+1,2):
        m += int(comb(odd,i))
print(m*(2**even))

Solution (Python):
def cmb(n, k):
  s = 1
  for j in range(n - k + 1, n + 1, 1):
    s *= j
  for j in range(1, k+1):
    s //= j
  return s

n, p = map(int, input().split())
aa = list(map(lambda x: int(x) % 2, input().split()))
odd = sum(aa)
even = n - odd
if p == 0:
  c = 2**even * sum(cmb(odd, k) for k in range(0, odd+1, 2))
  print(c)
else:
  c = 2**even * sum(cmb(odd, k) for k in range(1, odd+1, 2))
  print(c)

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

s = 1; t = 0
for a in A:
    if a % 2:
        s, t = s+t, s+t
    else:
        s, t = 2*s, 2*t
print([s, t][P])

Solution (Python):
n,p=map(int,input().split())
a=list(map(lambda x: x%2, map(int,input().split())))
e=a.count(0)

ans=2**(n-1)
if p==1 and e==n:
    ans=0
if p==0 and e==n:
    ans=2**n
print(ans)

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

b, c = a.count(1), a.count(0)
d = 2 ** b // 2  * 2 ** c 
if p == 1:
    print(d)
else:
    print(2 ** n - d)

Solution (Python):
N, P = map(int,input().split())
bis = list(map(int, input().split()))
if P == 0:
    ans = 2 ** N
else:
    ans = 0

for i in range(N):
    if bis[i] % 2 == 1:
        ans = 2 ** (N-1)
        break
print(ans)

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

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

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

temp1 = 0
for e in range(even + 1):
    temp1 += nCr(even, e)

temp2 = 0
if P == 0:
    for o in range(odd + 1):
        if o % 2 == 0:
            temp2 += nCr(odd, o)
else:
    for o in range(odd + 1):
        if o % 2 != 0:
            temp2 += nCr(odd, o)
ans = temp1 * temp2
print(ans)

Solution (Python):
import math

def fact(x):
    return math.factorial(x)

N, P = map(int, raw_input().split())
A = map(int, raw_input().split())
ec = sum(map(lambda n: 1 - (n & 1), A))
oc = sum(map(lambda n: (n & 1), A))
ocv = [i for i in range(oc + 1)]
ocv = map(lambda n: fact(oc) / (fact(n) * fact(oc - n)), ocv)
print pow(2, ec) * sum(ocv[P::2])

Solution (Python):
import itertools

N, P = [int(i) for i in input().split()]
biscuits = [int(i) for i in input().split()]
even = 0
odd = 0
buffer_count = 1
even_c = 1

for i in biscuits:
    if i % 2 == 0:
        even += 1
    elif i % 2 == 1:
        odd += 1

if P == 0:
    
    odd_c = 1
elif P == 1:
    
    odd_c = 0

if even > odd:
    for i in range(1, even+1):
        even_c += 2 ** (i-1)
        if i == odd:
            buffer_count = even_c
elif odd >= even:
    for i in range(1, odd+1):
        buffer_count += 2 ** (i-1)
        if i == even:
            even_c = buffer_count

if P == 0:
    
    if buffer_count > 2:
        odd_c = (buffer_count / 2)
elif P == 1:
    
    if buffer_count > 1:
        odd_c = (buffer_count / 2)

print(int(even_c * odd_c))

Solution (Python):
from collections import Counter
import itertools
import math

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

d = Counter()
for a in alist:
    d[a % 2] += 1



zeros = 2 ** d[0]


ones = 0
if p == 0:
    for i in range(d[1]+1):
        if i % 2 == 0:
            ones += math.factorial(d[1]) // (math.factorial(d[1] - i) * math.factorial(i))
        
        
else:
    for i in range(d[1]+1):
        if i % 2 == 1:
            ones += math.factorial(d[1]) // (math.factorial(d[1] - i) * math.factorial(i))
        
        




print(zeros * ones)

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

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

even = 0
for ai in a:
  if ai % 2 == 0:
    even += 1
 
odd = len(a) - even
ans = 0

for x in range(0, even + 1):
    for y in range(0, odd + 1):
        if (y % 2 == p):
            ans += C(even, x) * C(odd, y)
print ans

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

solve()

Solution (Python):
input1 = list(map(int,input("").split(" ")))
A = list(map(int,input("").split(" ")))
N = input1[0]
P = input1[1]

even = []
odd = []
for a in A:
	if a % 2 == 0:
		even.append(a)
	else:
		odd.append(a)

if len(odd) == 0:
	if P == 0:
		result = 2**N
	else:
		result = 0
else:
	result = 2**len(even) * 2**(len(odd)-1)

print(result)

Solution (Python):

input1s = input()
input2s = input()

input1 = [int(i) for i in input1s.split(' ')]
N = input1[0]
P = input1[1]
array = [int(i) for i in input2s.split(' ')]

count = 0

for i in range(len(array)):
  if(array[i]%2 == 1):
    count = 1

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

Solution (Python):
import sys

N, P = map(int, input().split())
A = list(map(int, input().split()))
dp = [[1 - i for _ in range(N + 1)] for i in range(2)]

for i in range(N):
    
    dp[0][i + 1] = dp[0][i]
    dp[1][i + 1] = dp[1][i]

    
    if A[i] % 2:
        dp[0][i + 1] += dp[1][i]
        dp[1][i + 1] += dp[0][i]
    else:
        dp[0][i + 1] += dp[0][i]
        dp[1][i + 1] += dp[1][i]

print(dp, file=sys.stderr)
print(dp[P][N])

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def nCr_table(n):
    table = [[None] * (n + 1) for _ in range(n + 1)]
    for i in range(n + 1):
        for j in range(i + 1):
            if j == 0 or j == i:
                table[i][j] = 1
            else:
                table[i][j] = table[i - 1][j - 1] + table[i - 1][j]
    return table


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

    nCr = nCr_table(100)

    e, o = 0, 0
    for a in A_list:
        e += a % 2 == 0
        o += a % 2 == 1

    a = 0
    for i in range(0, e + 1):
        a += nCr[e][i]
    if P == 0:
        b = sum([nCr[o][i] for i in range(0, o + 1, 2)])
        print(a * b)
    else:
        b = sum([nCr[o][i] for i in range(1, o + 1, 2)])
        print(a * b)

if __name__ == '__main__':
    main()

Solution (Python):
def biscuits():
	n,p = map(int, raw_input().split(" "))
	a = map(int, raw_input().split(" "))
	from math import pow
	has_odd = False
	for item in a:
		if item%2!=0:
			has_odd = True
			break
	if not has_odd:
		if p==0:
			print int(pow(2, n))
		else:
			print 0
	else:
		print int(pow(2, n-1))

if __name__ == "__main__":
	biscuits()

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==1: odd+=1
if odd==0:
  if P==1: 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()))
odd=0
for i in range(N):
  if A[i]%2==1: odd+=1
if odd==0:
  if P==1: print(0)
  else: print(2**N)
else:
  print(2**(N-1))

Solution (Python):
N,P=list(map(int,input().strip().split(' ')))
A=list(map(int,input().strip().split(' ')))
import math
odd=0
even=0
for i in range(len(A)):
    if A[i]%2==0:
        even+=1
    else:
        odd+=1
ans=0
def bino(a,b):
    return math.factorial(a)//(math.factorial(a-b)*math.factorial(b))


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

Solution (Python):
from math import factorial


def nCk(n, k):
    return factorial(n) // factorial(k) // factorial(n-k)


N, P = map(int, input().split())
A = [int(x) & 1 for x in input().split()]
even, odd = A.count(0), A.count(1)
print((1 << even) * sum(nCk(odd, i) for i in range(P == 1, odd + 1, 2)))

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

n_even = len(list(filter(lambda x: x % 2 == 0, A)))
n_odd = N - n_even
ans = (2 ** max(0, n_odd - 1)) * (2 ** n_even)
if P == 1 and n_odd == 0:
    print(0)
else:
    print(ans)

Solution (Python):
(n, k) = tuple(map(lambda x: int(x), input().split(' ')))
x = input().split(' ')
cnt = 0
for i in range(0, n):
    if int(x[i]) % 2 == 1: cnt += 1

ans = 2 ** (n - cnt)
if cnt % 2 == 1:
    ans *= 2 ** (cnt - 1)
else:
    cur = cnt
    if k == 0: cur = 1
    counter = cur
    for m in range(k, cnt - 1, 2):
        
        cur = cur * (cnt - m) * (cnt - m - 1) // ((m + 1) * (m + 2)) 
        
        counter += cur
    ans *= counter
print(ans)

Solution (Python):
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input().split())
 
n, p = rli()
a = rli()
 
odd = 0
even = 0
for i in a:
    if(i % 2 == 0):
        even += 1
    else:
        odd += 1
ans = 2**max(0, odd-1)*2**(even)
if(p == 1 and odd == 0):
    ans = 0
print(ans)

Solution (Python):





import sys, re

def solve(N, P, A):
  m = len([a for a in A if a % 2 != 0])  
  if m > 0:
    return 2 ** (N-1)
  else:
    return 2 ** N if P == 0 else 0

def splitIntoNums(line):
  words = re.split(r'\s+', line.strip())
  return [int(w) for w in words]  

while True:
  l1 = sys.stdin.readline()
  l2 = sys.stdin.readline()
  if not l1: break
  N, P = splitIntoNums(l1)
  A    = splitIntoNums(l2)
  if len(A) != N: raise
  print(solve(N, P, A))

Solution (Python):
from collections import Counter
from scipy.misc import comb

n, p = map(int, input().split())
ac = Counter(int(x) & 1 for x in input().split())
print(sum(comb(ac[1], c, exact=True) for c in range(p, ac[1] + 1, 2)) << ac[0])

Solution (Python):
from collections import Counter
from scipy.misc import comb

n, p = map(int, input().split())
ac = Counter(int(x) & 1 for x in input().split())

ans = 0

for c in range(p, ac[1] + 1, 2):
    ans += comb(ac[1], c, exact=True)

ans <<= ac[0]

print(ans)

Solution (Python):
n, a = list(map(int, input().strip().split(' ')))
d = list(map(int, input().strip().split(' ')))

even = sum([1 for i in d if i%2==0])
odd  = sum([1 for i in d if i%2==1])
ret = 0
if odd == 0:
    if a == 0:
        ret = 2**even
else:
    ret = (2**even) * (2**(odd-1))
print(ret)

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

Solution (Python):
import math

def C(n, r):
    if (n == r or r == 0):
        return 1
    if (r > n):
        return 0
    f = math.factorial

    ret = f(n) / (f(r) * f(n - r))
    return int(ret)


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

odd = even = ans = 0

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

print("")

for i in range(n + 1):
    for j in range(i + 1):
        if (p == 1 and j % 2 == 1) or (p == 0 and j % 2 == 0):
            ans += C(even, i - j) * C(odd, j)

print(ans)

Solution (Python):
def f():
 for x in a:
  if x%2==0:
   continue
  else:
   return False
 return True

n,p=map(int,raw_input().split())
a=map(int,raw_input().split())

if f()==True and p==0:
 print 2**n
elif f()==True and p==1:
 print 0
else:
 print 2**(n-1)

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

for a in A:
    if a%2==0:
        l0 +=1
    else:
        l1 +=1

if P==1 and l1==0:
    print(0)
elif P==0 and l1==0:
    print(2**N)
else:
    print(2**(N-1))

Solution (Python):
n,p=map(int,input().split())
a=list(map(int,input().split()))
k=m=0
for i in a:
    if i%2==0:
        k +=1
m=n-k

ans_x=ans_y=0

def cbn(b,c):
    z=1
    for i in range(2,b+1):
        z *= i
    for i in range(2,c+1):
        z //= i
    for i in range(2,b-c+1):
        z //= i
    return(z)


if p==0:

    for i in range(k+1):
        ans_x += cbn(k,i)
    for i in range(0,m+1,2):
        ans_y += cbn(m,i)

    print(ans_x * ans_y)

else:

    for i in range(k+1):
        ans_x += cbn(k,i)
    for i in range(1,m+1,2):
        ans_y += cbn(m,i)

    print(ans_x * ans_y)

Solution (Python):


def f():
 res=1
 for x in a:
  if x%2==0:
   res*=1
  else:
   res=0
   return res
 return res

n,p=map(int,raw_input().split())
a=map(int,raw_input().split())

if f()==1 and p==0:
 print 2**n
elif f()==1 and p==1:
 print 0
else:
 print 2**(n-1)

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

odd_flag = False
for a in A:
    if a % 2 == 1:
        odd_flag = True
        break
        
if odd_flag == True:
    print(2**(N-1))
elif((odd_flag == False) and (P == 0)):
    print(2**N)
else:
    print(0)

Solution (Python):
def comb(a,b):
    if b == 0:
        return 1
    elif a < b:
        return 0
    else:
        return comb(a-1,b-1) * a / b

n,p = map(int, raw_input().split())
l = map(int, raw_input().split())
en = len(filter(lambda x: x % 2 == 0, l))
on = n - en
if p == 1:
    ct = 0
    for i in range(1,on+1,2):
        ct += comb(on, i)
else:
    ct = 0
    for i in range(0,on+1,2):
        ct += comb(on,i)
print ct * (2**en)

Solution (Python):
import math

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

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

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

    print(ans)

main()

Solution (Python):
import math
 
 
def comb(n, r):
    return math.factorial(n) / math.factorial(r) / math.factorial(n - r)
 
 
def main():
    n, p = map(int, input().split())
    a = tuple(map(lambda x: int(x) % 2, input().split()))
 
    if n == 1 and a[0] % 2 != p:
        print(0)
        return 0
 
    t = len(tuple(filter(lambda x: x == 1, a)))
    f = n - t
 
    f_comb = 0
    for j in range(f + 1):
        f_comb += comb(f, j)
 
    t_comb = 0
    if p == 0:
        for i in range(t + 1):
            if i % 2 == 0:
                t_comb += comb(t, i)
    else:
        for i in range(t + 1):
            if i % 2 == 1:
                t_comb += comb(t, i)
 
    print(int(t_comb * f_comb))
 
    return 0
 
 
if __name__ == '__main__':
    main()

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

count = {0: 0, 1: 0}
for a in input().split():
    count[int(a) % 2] += 1

if count[1] == 0:
    if p == 0:
        print(pow(2, n))
    else:
        print(0)
else:
    print(pow(2, n - 1))

Solution (Python):
N,P = map(int,raw_input().split());
A = map(int,raw_input().split());
odd = sum(map(lambda x:x%2,A));
even = N - odd;
ans = 1 << even;

if P:
    if odd == 0: ans = 0;
    else:
        ans *= (1 << odd) >> 1;
else:
    if odd != 0: ans *= (1 << odd) >> 1;

print(ans);

Solution (Python):

import itertools, math
N, P = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
odd = [ tmp for tmp in a if tmp%2 != 0]
even = [ tmp for tmp in a if tmp%2 == 0]
d = math.factorial(len(odd))
e = math.factorial(len(even))
if P == 0:
    ans += 1
    b = sum([ (d//math.factorial(len(odd)-tmp))//math.factorial(tmp) for tmp in range(2, len(odd)+1, 2) ])
else:
    b = sum([ (d//math.factorial(len(odd)-tmp))//math.factorial(tmp) for tmp in range(1, len(odd)+1, 2) ])
c = [ (e//math.factorial(len(even)-tmp))//math.factorial(tmp) for tmp in range(1, len(even)+1) ]
for tmp in c:
    ans += tmp*b
else:
    if P == 0:
        ans += b+sum(c)
    else:
        ans += b
print(ans)

Solution (Python):
def makePascal(n):  
	res = [[1]]

	for m in range(1, n+1):
		l = []
		for k in range(m + 1):
			if k == 0 or k == m:
				l.append(1)
			else:
				tmp = res[m-1][k-1] + res[m-1][k]
				l.append(tmp)
		res.append(l)

	return res

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

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

ans = 0
comb = makePascal(N)
if P == 0:
	vol = 2 ** A.count(0)
	odds = A.count(1)
	i = 0
	while True:
		if i > odds:
			break
		else:
			ans += comb[odds][i] * vol
			i += 2
else:
	vol = 2 ** A.count(0)
	odds = A.count(1)
	i = 1
	while True:
		if i > odds:
			break
		else:
			ans += comb[odds][i] * vol
			i += 2
	
print(ans)

Solution (Python):
import math


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


def main():
    n, p = map(int, input().split())
    a = tuple(map(lambda x: int(x) % 2, input().split()))

    if n == 1 and a[0] % 2 != p:
        print(0)
        return 0

    t = len(tuple(filter(lambda x: x == 1, a)))
    f = n - t

    f_comb = 0
    for j in range(f + 1):
        f_comb += comb(f, j)

    t_comb = 0
    if p == 0:
        for i in range(t + 1):
            if i % 2 == 0:
                t_comb += comb(t, i)
    else:
        for i in range(t + 1):
            if i % 2 == 1:
                t_comb += comb(t, i)

    print(int(t_comb * f_comb))

    return 0


if __name__ == '__main__':
    main()

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

odd = len([a for a in A if a % 2 == 1])

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

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

evens = len(list(filter(lambda x: x == True, A)))
odds = len(A) - evens

evens_x = pow(2, evens)

if odds == 0 and P == 0:
    print(int(evens_x))
elif odds == 0 and P == 1:
    print(0)
else:
    odds_x = pow(2, odds - 1)
    print(int(evens_x * odds_x))

Solution (Python):


import sys

N,P = map(int, raw_input().split())
a = map(int, raw_input().split())

count_0 = 0
count_1 = 0
number = 0

def comb(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= numerator[k]
    return result

for i in range(N):
    if a[i] % 2 == 0:
        count_0 += 1
    else:
        count_1 += 1


if P == 0:
    if count_1 == 0:
        number = 1
    else:
        for j in range(count_1 /2 +1):
            number += comb(count_1,2*j)
else:
    if count_1 != 0:
        if count_1 % 2 == 0:
            for j in range(1,count_1 / 2 + 1):
                number += comb(count_1,2*j - 1)
        else:
            for j in range(1,count_1/2 + 2):
                number += comb(count_1, 2*j - 1)

if number != 0:
    print number * (2**count_0)
else:
    print number

Solution (Python):
import functools

import math

@functools.lru_cache()
def combinations(n, r):
    return math.factorial(n) / math.factorial(r) / math.factorial(n - r)


def main():
    n, p = map(int, input().split())
    a = tuple(map(lambda x: int(x) % 2, input().split()))

    if n == 1 and a[0] % 2 != p:
        print(0)
        return 0

    t = len(tuple(filter(lambda x: x == 1, a)))
    f = n - t

    count = 0

    if p == 0:
        for i in range(t + 1):
            if i % 2 == 0:
                c = 0
                for j in range(f + 1):
                    c += combinations(f, j)
                count += combinations(t, i) * c
    else:
        for i in range(t + 1):
            if i % 2 == 1:
                c = 0
                for j in range(f + 1):
                    c += combinations(f, j)
                count += combinations(t, i) * c

    print(int(count))

    return 0

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

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

a_list = input().split()
a_list = [int(x) for x in a_list]
a_array = np.array(a_list)

amari = a_array % 2

zero_count = np.sum(amari == 0)
one_count = np.sum(amari == 1)

zero_pattern = 2**zero_count
if p == 0:
    if one_count >= 2:
        one_pattern = 2**one_count/2
    else:
        one_pattern = 1
else:
    if one_count >= 1:
        one_pattern = 2**one_count/2
    if one_count < 1:
        one_pattern = 0
        
print(int(zero_pattern * one_pattern))

Solution (Python):
import math
import itertools

N,P = [int(i) for i in input().split(" ")]
A = [int(i) for i in input().split(" ")]
k = 0
for i in range(N):
    if int(A[i] % 2) == P:
        k += 1

if k == 0:
    if P == 0:
        tmp = 0
        i = 0
        while i <= N-k:
            tmp += int(math.factorial(N-k)/(math.factorial(N-k-i)*math.factorial(i)))
            i += 2
        print(tmp)
    elif P == 1:
        print(0)
else:
    tmp = 0
    i = 0
    while i <= N-k:
        tmp += int(math.factorial(N-k)/(math.factorial(N-k-i)*math.factorial(i)))
        i += 2
    print(pow(2,k)*tmp)

Solution (Python):
n,p=map(int,raw_input().split())
a=map(int,raw_input().split())
od=sum(k%2 for k in a)
ev=sum(1-k%2 for k in a)
if p==0:
	if od==0: print 2**n
	else: print 2**(n-1)
else:
	if od==0: print 0
	else: print 2**(n-1)

Solution (Python):
import sys

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

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

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

oddcnt = 0

for i in a:
    if i % 2 == 1:
        oddcnt += 1

evencnt = n - oddcnt

if oddcnt == 0 and p == 1:
    print(0)
    sys.exit()

evencomb = 0
for i in range(0, evencnt+1):
    evencomb += combi(evencnt, i)

oddcomb = 0
for i in range(p, oddcnt+1, 2):
    oddcomb += combi(oddcnt, i)

if evencomb != 0:
    if oddcomb != 0:
        print(evencomb * oddcomb)
    else:
        print(evencomb)
else:
    print(oddcomb)

Solution (Python):
def spaceinput():
    return list(map(int,input().split(" ")))

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

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

if a[0]%2==0:
    dp[0][0]=2
    dp[0][1]=0
else:
    dp[0][0]=1
    dp[0][1]=1


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


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

Solution (Python):
import sys

def biscuit(N, P, As):
    n_even = 0
    n_odd = 0
    for a in As:
      if int(a) % 2 == 0:
        n_even += 1
      else:
        n_odd +=1
    v = 2**n_even
    
    if n_odd == 0:
      v *= (0 if int(P) == 1 else 1)
    else:
      v *= 2**(n_odd -1)
    return v

N, P = sys.stdin.readline().strip().split()
As = sys.stdin.readline().strip().split()
print(biscuit(N, P, As))

Solution (Python):
import math

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

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

    if P:
        i = 1
    else:
        i = 0
    bisket1 = 0
    while i <= odd:
        bisket1 += (math.factorial(odd) // math.factorial(odd - i)) // math.factorial(i)
        i += 2

    bisket2 = 0
    i = 0
    while i <= even:
        bisket2 += (math.factorial(even) // math.factorial(even - i)) // math.factorial(i)
        i += 1

    print(bisket1 * bisket2)

main()

Solution (Python):
def make_comb_dp(n):
    dp = [[0] * (n + 1) for i in xrange(n + 1)]
    for i in xrange(n + 1):
        dp[i][0] = 1
        dp[i][i] = 1
    for i in xrange(2, n + 1):
        for j in xrange(1, i):
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]
    return dp



[N,P]=map(int,raw_input().split())
A= [int(x)%2 for x in raw_input().split()]
odd=A.count(1)
even=A.count(0)
dp=make_comb_dp(N)

ans=1
for n in range(1,N+1):
    for i in range(0,odd/2+1):
            ans+=dp[odd][i*2]*dp[even][n-i*2]
if P:
    ans=sum(dp[N]) -ans
print ans

Solution (Python):
import math
n, p = [int(i) for i in input().split()]
a = [int(i) % 2 for i in input().split()]
def nCr(n, r):
    f = math.factorial
    return f(n) // f(r) // f(n-r)
print(sum([nCr(a.count(1), i) for i in range(p, a.count(1) + 1, 2)]) * (2**a.count(0)))

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

even = odd = 0

def fact(n):
    if n == 0: return 1
    return n * fact(n-1)

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

odd_even = 0
for i in range(odd + 1):
    if i % 2 == 0:
        odd_even += fact(odd)/(fact(i)*fact(odd-i))

if P == 0:
    print(int(2**even * odd_even))
else:
    print(int(2**even * (2**odd - odd_even)))

Solution (Python):


import sys
import os
import math

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

A_temp = list(map(int, input().split()))
A = []

for a in A_temp:
    A.append(a % 2)

zero_num = A.count(0)
one_num = A.count(1)

def Combination(n, m):
    
    f = math.factorial
    return f(n) // f(m) // f(n - m)

combination_for_one = 0
if P == 0:
    for i in range(0, one_num + 1, 2):
        combination_for_one += Combination(one_num, i)
else:
    for i in range(1, one_num, 2):
        combination_for_one += Combination(one_num, i)

ans = combination_for_one * (2 ** zero_num)
print(ans)

Solution (Python):
def odd(n):
    return n % 2 == 1
    
def even(n):
    return n % 2 == 0

from math import factorial as fact
def c(n, r):
    if n < r:
        return 0
    if n == 0:
        return 0
    if r == 0:
        return 1
    return fact(n) // (fact(n-r) * fact(r))

n, p = map(int, input().split())
a = list(map(int, input().split()))
o = [i for i in a if odd(i)]
e = [i for i in a if even(i)]
x = len(o)
y = len(e)
yc = 0
for i in range(y):
    yc += c(y, i + 1)
ans = 0
if p == 0:
    ans += 1
i = 2 - p
while True:
    if i > x:
        break
    ans += c(x, i)
    ans += c(x, i) * yc
    i += 2
if p == 0:
    ans += yc
print(ans)

Solution (Python):
import numpy as np
import scipy.misc as scm

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

evens = A[A%2==0]
le = len(evens)
odds = A[A%2==1]
lo = len(odds)
ans = 0

for i in range(N+1) :
    for j in range(P,i+1,2) :
        ans += scm.comb(lo, j, 1)*scm.comb(le, i-j, 1)

print(ans)