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



Sample input:
2 0
1 3


Sample output:
2

Submission status: Accepted

Solution code:
class combination():
    #素数のmod取るときのみ　速い
    def __init__(self, n, mod):
        self.n = n
        self.fac = [1] * (n + 1)
        self.inv = [1] * (n + 1)
        for j in range(1, n + 1):
            self.fac[j] = self.fac[j - 1] * j % mod

        self.inv[n] = pow(self.fac[n], mod - 2, mod)
        for j in range(n - 1, -1, -1):
            self.inv[j] = self.inv[j + 1] * (j + 1) % mod

    def comb(self, n, r, mod):
        if r > n or n < 0 or r < 0:
            return 0
        return self.fac[n] * self.inv[n - r] * self.inv[r] % mod

def examA():
    N, P = LI()
    A = LI()
    odd = 0; even = 0
    for a in A:
        if a%2==1:
            odd +=1
        else:
            even +=1
    C = combination(N,mod)
    ans = 0
    if P==1:
        for i in range((odd+1)//2):
            ans += 2**even * C.comb(odd,i*2+1,mod)
    else:
        for i in range(odd//2+1):
            ans += 2**even * C.comb(odd,i*2,mod)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examA()

Submission status: Accepted

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

odd = False
for a in A:
    if a % 2 == 1:
        odd = True
        break

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

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

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


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


ans = 2**even
cnt = 0
if p == 0:
    for i in range(0, odd+1, 2):
        cnt += cmb(odd, i)
else:
    for i in range(1, odd+1, 2):
        cnt += cmb(odd, i)

print(ans*cnt)

Submission status: Accepted

Solution code:
N,P = map(int,input().split())
A = list(map(int,input().split()))
cnt = 0
for i in range(N):
    cnt += A[i]%2
if cnt>0:
    print(2**(N-1))
elif P==1:
    print(0)
else:
    print(2**N)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,P,*A = map(int,read().split())

od,ev = 0,1
for x in A:
    if x & 1:
        od,ev = od+ev,od+ev
    else:
        od,ev = od+od,ev+ev

answer = od if P else ev
print(answer)

Submission status: Accepted

Solution code:
import math
N,P = map(int,input().split())
A = [i%2 for i in list(map(int,input().split()))]
odd,even = A.count(1),A.count(0)
sumo = 0
for i in range(P,odd+1,2):
    sumo += int(math.factorial(odd)//(math.factorial(odd-i)*math.factorial(i)))
print(sumo*(2**even))

Submission status: Accepted

Solution code:
import math
N,P = map(int,input().split())
A = list(map(int,input().split()))
A = [i%2 for i in A]
odd = A.count(1)
even = A.count(0)
sumo = 0
for i in range(odd+1):
    if i%2 == P:
        sumo += int(math.factorial(odd)//(math.factorial(odd-i)*math.factorial(i)))
print(sumo*(2**even))

Submission status: Accepted

Solution code:
import math
N,P = map(int,input().split())
A = list(map(int,input().split()))
A = [i%2 for i in A]
odd = A.count(1)
even = A.count(0)
sumo = 0
for i in range(odd+1):
    if i%2 == P:
        sumo += int(math.factorial(odd)//(math.factorial(odd-i)*math.factorial(i)))
ans = sumo*(2**even)
print(ans)

Submission status: Accepted

Solution code:
import math
def comb(a,b):
    c = int(math.factorial(a)//(math.factorial(a-b)*math.factorial(b)))
    return c
N,P = map(int,input().split())
A = list(map(int,input().split()))
A = [i%2 for i in A]
odd = A.count(1)
even = A.count(0)
if P == 0:
    sumo = 0
    for i in range(odd+1):
        if i%2 == 0:
            sumo += comb(odd,i)
    ans = sumo*(2**even)
else:
    sumo = 0
    for i in range(odd+1):
        if i%2 == 1:
            sumo += comb(odd,i)
    ans = sumo*(2**even)
print(ans)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

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

Submission status: Accepted

Solution code:
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()))
o=0
e=0
for i in a:
    if i%2==0:
        e+=1
    else:
        o+=1
ans=2**e
cnt=0
if p==0:
    for i in range(0,o+1,2):
        cnt+=comb(o,i)
    print(ans*cnt)
else:
    for i in range(1,o+1,2):
        cnt+=comb(o,i)
    print(ans*cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, P = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

f0, f1 = 0, 0
for a in A:
    if a % 2 == 0:
        f0 += 1
    else:
        f1 += 1

ans = 0
n = 2 ** f0
for i in range(P, f1+1, 2):
    m = 1
    for j in range(i):
        m *= f1 - j
    for i in range(i):
        m /= i + 1

    ans += m * n

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
	#print(name)
	sys.stdin = open(name)

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

#print(a)

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

#print(gu,ki)

if ki==0:
	if p==1:
		print(0)
		exit()
	elif p==0:
		print(int(2**n))
		exit()

ans = 2**gu * (2**ki)/2
print(int(ans))

Submission status: Accepted

Solution code:
N, P = map(int,input().split())
A = list(map(int,input().split()))
odd = len(list(filter(lambda x:x%2==1 ,A)))
even = N-odd
if odd == 0:
    if P == 0:print(2**(N))
    else:print(0)
else:
    print(2**(N-1))

Submission status: Accepted

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

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

ret = pow(2, e) * max(1, pow(2, o - 1))

if P == 0 :
  print(ret)
else :
  print(pow(2, N) - ret)

Submission status: Accepted

Solution code:
n,p = map(int,input().split())
L = list(map(int,input().split()))
Le = [x for x in L if x%2 == 0]
Lo = [x for x in L if x%2 == 1]

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

Submission status: Accepted

Solution code:
n,p = map(int,input().split())
l = [0,0]
for i in map(int,input().split()):
  l[i%2] += 1
if p:
  if l[1] == 0:
    print(0)
  else:
    #l[1]C(range(1,l[1]+1,2))は2項定理より2**(l[1]-1)
    print(2**l[0]*2**(l[1]-1))
else:
  if l[1] == 0:
    print(2**l[0])
  else:
    #l[1]C(range(0,l[1]+1,2))は2項定理より2**(l[1]-1)
    print(2**l[0]*2**(l[1]-1))

Submission status: Accepted

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

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

Submission status: Accepted

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


ki=0

for i in a:
    if i%2 != 0:
        ki=1
        break

if ki==0:
    if p==0:
        ans=2**n
    else:
        ans=0
else:
    ans=2**(n-1)
print(ans)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, p = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    ls = [0] * 5001
    ls[0] += 1
    for v in a:
        for i in range(5000 - v, -1, -1):
            ls[i+v] += ls[i]
    t = 0
    for i in range(p, 5001, 2):
        t += ls[i]
    print(t)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
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:
        odd += 1
    else:
        even += 1
if odd == 0:
    if P:
        ans = 0
    else:
        ans = 2**N
else:
    ans = 2**(N-1)

print(int(ans))

Submission status: Accepted

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

ans = 0
for i in range(odd+1):
    if i%2 == P:
        ans += factorial(odd) / factorial(i) / factorial(odd-i)
ans *= 2**even

print(int(ans))

Submission status: Accepted

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

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

odd = []
even = []
for i in a:
    if i % 2 != 0:
        odd.append(i)
    else:
        even.append(i)
if len(odd) == 0:
    if p == 1:
        ans = 0
    else:
        ans = 2 ** len(even)
else:
    ans = 2 ** len(even) * 2 ** (len(odd) - 1)
print(ans)

Submission status: Accepted

Solution code:
n, p = map(int, input().split())
a = list(map(int, input().split()))
odd = []
even = []

for i in a:
    if i & 1:
        odd.append(i)
    else:
        even.append(i)
n_odd = len(odd)
n_even = len(even)


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


# P=0の場合、evenからは任意、oddからは2の倍数個取り出す
if p == 0:
    ans = 2 ** n_even
    tmp = 0
    for i in range(0, n_odd + 1, 2):
        tmp += nCr(n_odd, i)
    ans *= tmp
else:  # P=1の場合、evenは任意、oddからは奇数個取り出す
    ans = 2 ** n_even
    tmp = 0
    for i in range(1, n_odd + 1, 2):
        tmp += nCr(n_odd, i)
    ans *= tmp

print(ans)

Submission status: Accepted

Solution code:
m,p=map(int,input().split())
a=list(map(int,input().split()))

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

g=k=0
for i in a:
    if i % 2 == 0 : g+=1
    elif i % 2 == 1 : k+=1

all_g = all_k =0
for i in range(g+1):
    all_g += cmb(g,i)
        
if p == 0:
    for i in range(0,k+1,2):
        all_k += cmb(k,i)
elif p == 1:
    for i in range(1,k+1,2):
        all_k += cmb(k,i)
print(all_g * all_k)

Submission status: Accepted

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

x = 0
y = 0

for c in a:
    if c % 2 == 1:
        x += 1
    else:
        y += 1

if x == 0 and p == 1:
    print(0)
    exit()
elif x == 0:
    print(2 ** y)
    exit()
else:
    print(2 ** y * (2 ** (x-1)))

Submission status: Accepted

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

dp = [[-1]*2 for _ in range(n)]


def use(i, j):
    if i >= n:
        return 1 if j == p else 0
    if dp[i][j] != -1:
        return dp[i][j]
    dp[i][j] = use(i+1, j)+use(i+1, (j+a[i]) % 2)
    return dp[i][j]


print(use(0, 0))

Submission status: Accepted

Solution code:
from math import factorial

def c(n,k):
    return factorial(n)/(factorial(n-k) * factorial(k))

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

o = 0
e = 0

for i in A:
    if i % 2 == 0:
        e += 1
    else:
        o += 1
on = o // 2

a = []
b = []
ans = 0

if P == 0:
    for i in range(e+1):
        a.append(c(e,i))
    for i in range(on+1):
        b.append(c(o,i*2))        
    for i in a:
        for j in b:
            ans += i * j
else:
    for i in range(e+1):
        a.append(c(e,i))
    for i in range(1,o+1)[::2]:
        b.append(c(o,i))        
    for i in a:
        for j in b:
            ans += i * j

ans = int(ans)
print(ans)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,MOD = map(int,input().split())
A = list(map(int,input().split()))

ODD = 0
EVEN = 0

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

P = [1]

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

ans = 0

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

print(2**EVEN*ans)

Submission status: Accepted

Solution code:
# 2019-11-20 21:35:12(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
from scipy.misc import comb # (default: exact=False)
import numpy as np 


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

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





if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import factorial
N,P=map(int,input().split())
a=list(map(int,input().split()))
odd=0
even=0
for i in range(N):
  if a[i]%2==0:
    even+=1
  else:
    odd+=1
ans=2**even
k=0
if P==0:
  k=0
else:
  k=1
tmp=0
for i in range(k,odd+1,2):
  tmp+=factorial(odd)//factorial(odd-i)//factorial(i)

print(ans*tmp)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
# from collections import Counter
# from itertools import combinations as comb
# from itertools import permutations as perm
# from copy import copy
# 配列二分法アルゴリズム
# https://docs.python.jp/3/library/bisect.html
# import bisect
# 桁数指定
# print('{:.3f}'.format(X))
# from collections import defaultdict
# dic = defaultdict(lambda: ...)
# 値で辞書をソート
# sorted(dic.items(), key=lambda x:x[1])
# ヒープキュー
# https://docs.python.org/ja/3/library/heapq.html
# import heapq
# 正規表現(regular expression)のためのモジュール
# import re

import sys

sys.setrecursionlimit(2000)


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


# 重複組み合わせは nHr = (n + r - 1)Cn
def cmb(n, r):
    # combination
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def gcd(a, b):
    # greatest common divisor
    while b > 0:
        a, b = b, a % b

    return a


def lcm(a, b):
    # least common multiple
    return a * b // gcd(a, b)


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

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

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

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

Submission status: Accepted

Solution code:
from scipy.misc import comb

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

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

even = N - odd

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

def comb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

Submission status: Accepted

Solution code:

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import math

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

odd_n = 0
even_n = 0

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


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


if P == 0:
    odd_p = 1
    if odd_n > 0:
        # 偶数個選ぶ組み合わせ
        for i in range(2, odd_n + 1, 2):
            odd_p += C(odd_n, i)
    even_p = 2 ** even_n
    p = odd_p * even_p
else:
    odd_p = 0
    if odd_n > 0:
        # 奇数個選ぶ組み合わせ数
        for i in range(1, odd_n + 1, 2):
            odd_p += C(odd_n, i)

    even_p = 2 ** even_n
    p = odd_p * even_p

ans = p

print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

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

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


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

print(total)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
def nCr(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r) )
N,P = map(int,input().split())
A = list(map(int,input().split()))
E = 0
O = 0
for i in A:
    if i % 2 == 0:
        E += 1
    else:
        O += 1
ans = 1
ans *= 2**E
if P == 0:
    ans2 = 1
    for i in range(O // 2):
        i += 1
        i *= 2
        ans2 += nCr(O,i)
else:
    ans2 = 0
    for i in range((O+1) // 2):
        i *= 2
        i += 1
        ans2 += nCr(O,i)
print (ans * ans2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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


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

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

E = 0
O = 0

for i in A:

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

ans = 1

ans *= 2**E


if P == 0:

    ans2 = 1

    for i in range(O // 2):

        i += 1
        i *= 2

        ans2 += nCr(O,i)

else:

    ans2 = 0

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

        i *= 2
        i += 1

        ans2 += nCr(O,i)

print (ans * ans2)

Submission status: Accepted

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

Submission status: Accepted

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

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


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

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

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