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:
N,P=map(int,input().split())
A=list(map(int,input().split()))
odd=len([x for x in A if x%2==1])
if odd==0:
    if P==0:
        ans=2**N
    else:
        ans=0
else:
    ans=2**(N-1)
print(ans)

Submission status: Accepted

Solution code:
def f(n):
    N=1
    for i in range(n):
        N=N*(i+1)
    return N

def C(n,x):
    return f(n)//(f(x)*f(n-x))
    
n,p = map(int,input().split())
a   = list(map(int,input().split()))
odd=0
even=0
for i in range(n):
    if a[i]%2==0:
        even+=1
    else:
        odd+=1
if p % 2 == 0:
    x=0
    for i in range(odd//2+1):
        x+=C(odd,i*2)
    print((2**even) * x)
else:
    x=0
    for i in range(odd//2):
        x+=C(odd,i*2+1)
    print((2**even) * x)

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
a=list(map(int,input().split()))
e=o=0
def c(a,b):
	w=1
	for i in range(a-b+1,a+1):
		w*=i
	for i in range(b):
		w//=(i+1)
	return w
for i in range(n):
	if a[i]%2==0:
		e+=1
	else:
		o+=1
if p==0:
	ans=2**e
	q=0
	for i in range(o//2+1):
		q+=c(o,2*i)
	print(ans*q)
else:
	ans=2**e
	q=0
	for i in range((o+1)//2):
		q+=c(o,2*i+1)
	print(ans*q)

Submission status: Accepted

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

even, odd = 0, 0

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

if n == even:
    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()))

class Combination:
    def __init__(self, size):
        self.size = size
        self.fact = [1] * size
        for i in range(1, size):
            self.fact[i] = i * self.fact[i - 1]

    def ncr(self, n, r):
        if r > n or n < 0 or r < 0:
            return 0
        return self.fact[n] // self.fact[r] // self.fact[n - r]

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

ans = 0
comb = Combination(N + 100)
if P == 0:  # oddを偶数個
    for o in range(0, odd + 1, 2):
        for e in range(even + 1):
            ans += comb.ncr(odd, o) * comb.ncr(even, e)
else:
    for o in range(1, odd + 1, 2):
        for e in range(even + 1):
            ans += comb.ncr(odd, o) * comb.ncr(even, e)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,P=map(int,input().split())
A=list(map(int,input().split()))
if all(a%2==0 for a in A):
  if P==0:
    ans=2**N
  else:
    ans=0
else:
  ans=2**(N-1)   
print(ans)

Submission status: Accepted

Solution code:
N, P = map(int,input().split())
A = list(map(int,input().split()))
dp = [[[0 for k in range(2)] for j in range(N+1)] for i in range(N+1)] #dp[i][j][k]は1-iまででj個選んだ時にmod2がkとなる選び方
dp[1][0][0] = 1
if(A[0] % 2 == 0):
    dp[1][1][0] = 1
else:
    dp[1][1][1] = 1
for i in range(2, N+1):
    for j in range(i+1):
        if(j == 0):
            dp[i][j][0] = 1
        else:
            if(A[i-1] % 2 == 0):
                dp[i][j][0] = dp[i-1][j-1][0] + dp[i-1][j][0]
                dp[i][j][1] = dp[i-1][j-1][1] + dp[i-1][j][1]
            else:
                dp[i][j][0] = dp[i-1][j-1][1] + dp[i-1][j][0]
                dp[i][j][1] = dp[i-1][j-1][0] + dp[i-1][j][1]
ans = 0
if(P == 0):
    for i in range(N+1):
        ans += dp[N][i][0]
else:
    for i in range(N+1):
        ans += dp[N][i][1]
print(str(ans))

Submission status: Accepted

Solution code:
import math
def combi(n, r):
  if n >= r:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  elif r == 0:
    return 1
  else:
    return 0

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

eo = ["e" if i % 2 == 0 else "o" for i in A]
e_num = eo.count("e")
o_num = eo.count("o")

o = [i for i in range(o_num + 1) if i % 2 == 0]
e = [i for i in range(o_num + 1) if i % 2 == 1]


if P == 0:
  oo = 0
  for i in o:
    oo += combi(o_num, i)
  ans = 2**e_num * oo
else:
  ee = 0
  for i in e:
    ee += combi(o_num, i)
  ans = 2**e_num * ee

print(ans)

Submission status: Accepted

Solution code:
N, P = map(int, input().split())
As = list(map(int, input().split()))
nE = 0
nO = 0
for A in As:
  if A%2 == 0:
    nE += 1
  else:
    nO += 1
#print(P, nE, nO)
r = 0
# \sum_{2k<=nO}C_nO_2k
for k in range(0 if P == 0 else 1, nO+1, 2):
  c = 1
  for i in range(1, k+1):
    c = c*(nO+1-i)//i
  r += c
r = r*2**nE
print(r)

Submission status: Accepted

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

Submission status: Accepted

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

    dp = [[0, 0] for i in range(n + 1)]
    dp[0][0] = 1  # 何も選ばない時あまりは０なので
    for i in range(n):
        if a[i] % 2 == 0:
            dp[i + 1][0] = dp[i][0]*2
            dp[i+1][1] = dp[i][1]*2
        else:
            dp[i + 1][0] = dp[i][0] + dp[i][1]
            dp[i + 1][1] = dp[i][0] + dp[i][1]

    print(dp[n][p])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

    print(dp[n][p])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, p = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    has_odd = False
    for v in a:
        if v % 2 != 0:
            has_odd = True
            break
    if p == 0:
        if has_odd:
            print(2 ** (n - 1))
        else:
            print(2 ** n)
    else:
        if has_odd:
            print(2 ** (n - 1))
        else:
            print(0)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
from scipy.misc import*
N,P,*A=map(int,open(0).read().split());O=sum(a%2for a in A)
print(2**(N-O)*sum(comb(O,2*i+P,exact=1)for i in range(O//2+1)))

Submission status: Accepted

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

for a in A:
    if a % 2 == 0:
        n += 1

if n == N:
    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()))
n = 0

for a in A:
    if a % 2 == 0:
        n += 1

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



def comb(n, r):
    if r > n: return 0
    fact = 1
    for i in range(n-r+1, n+1):
        fact *= i


    divisor = 1
    for j in range(1, r+1):
        divisor *= j


    return fact // divisor




n, p = LI()
L = [i%2 for i in LI()]
ans = 0
odd_cnt = L.count(1)
even_cnt = L.count(0)
for k in range(p, odd_cnt+1, 2):
    ans += comb(odd_cnt, k) * 2 ** even_cnt



print(ans)

Submission status: Accepted

Solution code:
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=list(map(lambda x: int(x)%2,input().split()))
B=[len(A)-sum(A),sum(A)]

ans=0
for i in range(P,B[1]+1,2):
  ans+=combinations_count(B[1],i)
ans*=2**B[0]
print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
import fractions

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

def main():
    _,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
    x = 0
    if P==0:
        for i in range(0,odd+1,2):
            x += combinations_count(odd, i)
        print(2**even*x)
    else:
        for i in range(1,odd+1,2):
            x += combinations_count(odd, i)
        if x == 0:
            print(0)
        else:
            print(2**even*x)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
def combination(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()))
odd = list(filter(lambda n:n%2==1, A))
even = list(filter(lambda n:n%2==0, A))
O = len(odd)
E = len(even)
O_a = 0
E_a = 0

for i in range(O+1):
    if i % 2 == 0:
        E_a += combination(O,i)
    else:
        O_a += combination(O,i)

if P == 0:
    print(int(2**E * E_a))
else:
    print(int(2**E * O_a))

Submission status: Accepted

Solution code:
def resolve():
    n, p = map(int, input().split())
    a = list(map(int, input().split()))
    if len([ai for ai in a if ai % 2 == 0]) == n:
        print(2 ** n if p == 0 else 0)
        return 2 ** n if p == 0 else 0
    else:
        print(2 ** (n - 1))
        return 2 ** (n - 1)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import math

def main():
    N,P = map(int,input().split())
    A = list(map(int,input().split()))
    odd = []
    even = []
    for i in A:
        if i%2 == 0:
            even.append(i)
        else:
            odd.append(i)

    num_even = 2**len(even)
    def combination(n,r):
        return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

    count = 0
    lo = len(odd)
    if P == 0:
        for i in range(lo//2+1):
            count += combination(lo,2*i)
        print(num_even*count)
    else:
        for i in range(-(-lo)//2):
            count += combination(lo,2*i+1)
        print(num_even*count)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

n0 = A.count(0)
n1 = A.count(1)
ans0 = 2 ** n0
ans1 = 0
for i in range(P, n1 + 1, 2):
    ans1 += factorial(n1) // (factorial(i) * factorial(n1 - i))
print(ans0 * ans1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import math
n, p = map(int, input().split())
a = np.array([int(i) for i in input().split()])
even = len(a[a%2 == 0])
odd = len(a[a%2 == 1])
def combinations(n,c):
    return math.factorial(n)//(math.factorial(n-c)*math.factorial(c))
if p == 0:
    x = 1
    for i in range(2,odd+1,2):
        x += combinations(odd,i)
    print(x*2**even)
else:
    if odd == 0:
        print(0)
    else:
        x = 0
        for i in range(1,odd+1,2):
            x += combinations(odd,i)
        print(x*2**even)

Submission status: Accepted

Solution code:
n,p=map(int, input().split())
a=list(map(int, input().split()))
total=sum( i%2 for i in a )

if total==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()))
dp=[[0]*2 for i in range(n+1)]
dp[0][0]=1
dp[0][1]=0
for i in range(1,n+1):
	if a[i-1]%2==1:
		dp[i][1]=dp[i-1][0]+dp[i-1][1]
		dp[i][0]=dp[i-1][1]+dp[i-1][0]
	else:
		dp[i][1]=dp[i-1][1]*2
		dp[i][0]=dp[i-1][0]*2
print(dp[n][p])

Submission status: Accepted

Solution code:
# AGC017A - Biscuits
def main():
    N, P, *A = map(int, open(0).read().split())
    total = sum(i % 2 for i in A)
    if total == 0:  # all numbers are even
        flg = P == 0
        print(2 ** N if flg else 0)
    else:
        print(2 ** (N - 1))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,p = LI()
    a = LI()
    o = 0
    for i in a:
        o += i%2
    e = n-o
    ans = (1<<e)*((1<<o)>>((o!=0)|(p!=0)))
    print(ans)
    return
#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# nCr
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)

  # lbから偶数個選ぶ方法は何通り？
  bc=0
  for i in range(len(lb)+1):
    bc+=nCr(len(lb),i)
    # print(bc)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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:#p==1のとき
  if odd:
    for i in range(tmp):
      ans_tmp += cmb(odd,i*2+1)
else:#p==0のとき
  if odd:
    tmp += 1
    for i in range(tmp):
      ans_tmp += cmb(odd,(i*2))
  else:
    ans_tmp = 1

ans *= ans_tmp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq

MOD = 2  # type: int

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


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, P, A)

if __name__ == '__main__':
    main()

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
A_1 = A.count(1)
A_0 = A.count(0)

import math
def conbination(n, r): #nCrを求める
    # nCr = n! //(r! * (n-r)!)
    return math.factorial(n) //(math.factorial(r) * math.factorial(n-r))


# print ('A_0, A_1 = ', A_0, A_1)
if P == 0: #2の倍数
    ans = 2 ** A_0 #偶数のものの選び方
    if A_1 >= 1:
        tmp = 0
        # A_1個の奇数から偶数個を選ぶ
        for i in range(0, A_1 + 1, 2):
            tmp += conbination(A_1, i)
        ans *= tmp
else:
    ans = 2 ** A_0 #偶数のものの選び方
    tmp = 0
    # A_1個の奇数から偶数個を選ぶ
    for i in range(1, A_1 + 1, 2):
        # print (i, end = ' ')
        tmp += conbination(A_1, i)
    ans *= tmp

print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#AGC17 A

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)

Submission status: Accepted

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

Submission status: Accepted

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

#print(count0, count1, P)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AGC017A - Biscuits
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:  # all numbers are even
        print(2 ** n if p == 0 else 0)
    else:
        print(2 ** (n - 1))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# AGC017A - Biscuits
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)  # even
    if e == n:
        print(2 ** n if p == 0 else 0)
    else:
        print(2 ** (n - 1))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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):  # n C 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)