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: Wrong Answer

Solution code:
def f(n, p, a):
    if n == 1:
        if p == 0 and a[0] % 2 == 0:
            print(2)
        elif p == 0 and a[0] % 2 == 1:
            print(1)
        elif p == 1 and a[0] % 2 == 0:
            print(0)
        elif p == 1 and a[0] % 2 == 1:
            print(1)
    else:
        print(2**(n-1))

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

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
	
#階乗#
lim = 50  #必要そうな階乗の限界を入力
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1] % mod

#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
	fact_inv[n-1] = n*fact_inv[n]%mod

def C(n, r):
	return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod


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

if any([x%2 for x in A]):
	print(pow(2, N-1))
else:
	print(pow(2, N))

Submission status: Wrong Answer

Solution code:
def comb(n,k):
    nCk = 1
    MOD = 10**9+7

    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk
n,p=map(int,input().split())
a=list(map(lambda x:int(x)%2,input().split()))
on=a.count(1)
ze=a.count(0)
print(on,ze)
ans=0
if on==0:
    if p==0:
        print(2**n)
        exit()
    if p==1:
        print(0)
        exit()
    
print(2**(n-1))

Submission status: Wrong Answer

Solution code:
import math

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

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

if odd == 0 and P == 1:
    res = 0
else:
    res = 2 ** (even+odd-1)

print(res)

Submission status: Wrong Answer

Solution code:
N,P = list(map(int, input().split()))
a = list(map(int, input().split()))
num_odd = sum([i%2== 1 for i in a])
num_even = N - num_odd

ce = 2 ** num_even
co = 2 ** (num_odd - 1)
if P==1:
    if num_odd == 0:
        co = 0

print(co * ce)

Submission status: Wrong Answer

Solution code:
N,P = list(map(int, input().split()))
a = list(map(int, input().split()))
num_odd = sum([i%2== 1 for i in a])
num_even = N - num_odd

ce = 2 ** num_even
co = 0
if num_odd > 0:
    co = 2 ** (num_odd - 1)
print(co * ce)

Submission status: Wrong Answer

Solution code:
from math import factorial
def ncr(n,r):
    a=factorial(n)
    b=factorial(n-r)*factorial(r)
    return a//b
N,P=list(map(int,input().split()))
A=list(map(int,input().split()))
A=[i%2 for i in A]
zero=[i for i in A if i==0]
one=[i for i in A if i==1]
lzero=len(zero)
lone=len(one)
if lzero==0:
    if P%2==0:
        a = 0
        for i in range(2, lone+1, 2):
            a += ncr(lone, i)
        print(a+1)
    else:
        a = 0
        for i in range(1, lone+1, 2):
            a += ncr(lone, i)
        print(a)
    exit()
if lone==0:
    if P%2==0:
        print(2**lzero)
    else:print(0)
    exit()
if P%2==1:
    guu=2**lzero
    a=0
    for i in range(1,lone+1,2):
        a+=ncr(lone,i)
    print(guu*a)
else:
    guu=2**lzero
    a=0
    for i in range(2,lone+1,2):
        a+=ncr(lone,i)
    print(guu*a)

Submission status: Wrong Answer

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

odd = 0
for v in A:
    if  v % 2:
        odd += 1 
even = N-odd

print((2**even)*int(2**(odd-1)))

Submission status: Wrong Answer

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

odd = 0
for v in A:
    if  v % 2:
        odd += 1 
even = N-odd

ans = (2**even)*(2**(odd-1) if 0 < odd else 0 )

print(ans)

Submission status: Wrong Answer

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

odd = 0
for v in A:
    if  v % 2:
        odd += 1 
even = N-odd

ans = (2**even)*(2**(odd-1))

print(ans)

Submission status: Wrong Answer

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

MOD = 2  # type: int


def solve(N: int, P: int, A: "List[int]"):
    if not sum([e%2 for e in A]):
        if P:
            print(0)
            return

    print(2**(N-1))
    return


# Generated by 1.1.7.1 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: Wrong Answer

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

OE = [0,0]

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

RemEven = 1

if OE[0]%2 - 1 !=0:
	RemEven = 0

import math

count = 0

for i in range (0, OE[0]+1):
	if i%2==0:
		count+=(2**OE[1])*math.factorial(OE[0])/(math.factorial(i)*math.factorial(OE[0]-i))

if RemEven == 1:
	print(int(count))
else:
	print(int(2**N-count))

Submission status: Wrong Answer

Solution code:
def main():
    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 = list(map(int, input().split()))
    A = list(map(int, input().split()))
    odd = sum([a % 2 == 1 for a in A])
    even = n - odd
    if p == 0:
        odd_sum = 0
        for i in range(0, odd + 1, 2):
            odd_sum += combinations_count(odd, i)
    else:
        if odd == 0:
            print(0)
            exit()
        else:
            odd_sum = 0
            for i in range(1, odd + 1, 2):
                odd_sum += combinations_count(odd, i)
    if even == 0:
        even_sum = 0
    else:
        even_sum = pow(2, even)
    print(even_sum * odd_sum)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

length = len(a)
even = len([i for i in a if i % 2 == 0])
odd = len([i for i in a if i % 2 == 1])

if length == even and p == 1 or length == odd and p == 0 and odd % 2 == 1:
    print(0)
elif length == even:
    print(2 ** n)
else:
    print(2 ** n // 2)

Submission status: Wrong Answer

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

length = len(a)
even = len([i for i in a if i % 2 == 0])
odd = len([i for i in a if i % 2 == 1])

if length == even and p == 1 or length == odd and p == 0 and odd % 2 == 1:
    print(0)
else:
    print(2 ** n // 2)

Submission status: Wrong Answer

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

if N==1:
    if P==0:
        print(1+1*(A[0]%2==0))
    else:
        print(1*(A[0]%2==1))
else:
    print(2**(N-1))

Submission status: Wrong Answer

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

if N==1:
    print(2*(P==A[0]%2))
else:
    print(2**(N-1))

Submission status: Wrong Answer

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

if N==1:
    print(1*(P==A[0]%2))
else:
    print(2**(N-1))

Submission status: Wrong Answer

Solution code:
n, p = map(int, input().split())
a = [int(i)&1 for i in input().split()]
odd = sum(a)
ans = 0
if odd:
    ans = 2**(n-1)
else:
    ans = 2**n

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

def nCk(n, k):
    k = min(k, n-k)
    numer = 1
    for i in range(n, n-k, -1):
        numer *= i
    denom = 1
    for i in range(k, 1, -1):
        denom *= i
    return numer // denom

def main():
    N, P = map(int, input().split())
    A = list(map(int, input().split()))
    B = [x%2 for x in A]
    Bcount = collections.Counter(B)
    tmp = pow(2, Bcount[P])
    ans = 0
    if N == 1:
        print(((P == 1) ^ (B[0] == 1))^1)
        return
        
    for i in range(0, Bcount[(P+1)%2]+1, 2):
        ans += tmp * nCk(Bcount[(P+1)%2], i)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# 二項係数を"やるだけ"にしてくれるライブラリ
from collections import Counter
MAX = 1000005
MOD = 10**9+7
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()


N, P = map(int, input().split())  # 袋がN個, mod2をPにしたい
A = list(map(lambda x: int(x)%2, input().split()))
# print(A)

kisuu = sum(A)  # 奇数個の袋の数
guusuu = N-kisuu  # 偶数個の袋の数

# Pが1のとき，偶数側の袋を任意の数と，奇数側の数を奇数個選ぶ
if P == 1:
    exit()
    tmp_guusuu = 0
    tmp_kisuu = 0
    # 偶数側を任意の個数選ぶ
    for i in range(guusuu+1):
        tmp_guusuu += COM(guusuu, i)
    for i in range(kisuu+1):
        if i % 2 == 0:
            continue
        tmp_kisuu += COM(kisuu, i)
    print(tmp_guusuu*tmp_kisuu)

# Pが0のとき，偶数側の袋を任意の数と，奇数側の数を偶数個選ぶ
elif P == 0:
    tmp_guusuu = 0
    tmp_kisuu = 0
    # 偶数側を任意の個数選ぶ
    for i in range(guusuu+1):
        tmp_guusuu += COM(guusuu, i)
    # 奇数側を0個数以上の偶数個選ぶ
    for i in range(kisuu+1):
        if i % 2 == 1:
            continue
        tmp_kisuu += COM(kisuu, i)
    print(tmp_guusuu*tmp_kisuu)

Submission status: Wrong Answer

Solution code:
# 二項係数を"やるだけ"にしてくれるライブラリ
from collections import Counter
MAX = 1000005
MOD = 10**9+7
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()


N, P = map(int, input().split())  # 袋がN個, mod2をPにしたい
A = list(map(lambda x: int(x)%2, input().split()))
# print(A)

kisuu = sum(A)  # 奇数個の袋の数
guusuu = N-kisuu  # 偶数個の袋の数

# Pが1のとき，偶数側の袋を任意の数と，奇数側の数を奇数個選ぶ
if P == 1:
    tmp_guusuu = 0
    tmp_kisuu = 0
    # 偶数側を任意の個数選ぶ
    for i in range(guusuu+1):
        tmp_guusuu += COM(guusuu, i)
    for i in range(kisuu+1):
        if i % 2 == 0:
            continue
        tmp_kisuu += COM(kisuu, i)
    print(tmp_guusuu*tmp_kisuu)

# Pが0のとき，偶数側の袋を任意の数と，奇数側の数を偶数個選ぶ
elif P == 0:
    tmp_guusuu = 0
    tmp_kisuu = 0
    # 偶数側を任意の個数選ぶ
    for i in range(guusuu+1):
        tmp_guusuu += COM(guusuu, i)
    # 奇数側を0個数以上の偶数個選ぶ
    for i in range(kisuu+1):
        if i % 2 == 1:
            continue
        tmp_kisuu += COM(kisuu, i)
    print(tmp_guusuu*tmp_kisuu)

Submission status: Wrong Answer

Solution code:
# 二項係数を"やるだけ"にしてくれるライブラリ
from collections import Counter
MAX = 1000005
MOD = 10**9+7
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()


N, P = map(int, input().split())  # 袋がN個, mod2をPにしたい
A = list(map(lambda x: int(x)%2, input().split()))
# print(A)

kisuu = sum(A)
guusuu = N-kisuu
# print(kisuu, guusuu)
# Pが1のとき，偶数側の袋を任意の数と，奇数側の数を奇数個選ぶ
if P == 1:
    tmp_guusuu = 0
    tmp_kisuu = 0
    # 偶数側を任意の個数選ぶ
    for i in range(guusuu+1):
        tmp_guusuu += COM(guusuu, i)
    for i in range(kisuu+1):
        if i % 2 == 0:
            continue
        tmp_kisuu += COM(kisuu, i)
    print(tmp_guusuu*tmp_kisuu)

# Pが0のとき，偶数側の袋を任意の数と，奇数側の数を偶数個選ぶ
elif P == 0:
    tmp_guusuu = 0
    tmp_kisuu = 0
    # 偶数側を任意の個数選ぶ
    for i in range(guusuu+1):
        tmp_guusuu += COM(guusuu, i)
    # 奇数側を0個数以上の偶数個選ぶ
    for i in range(kisuu+1):
        if i % 2 == 0:
            continue
        tmp_kisuu += COM(kisuu, i)
    print(tmp_guusuu*tmp_kisuu)

Submission status: Wrong Answer

Solution code:
n, p, *a = map(int, open(0).read().split())
if n == 1:
    if a[0] % 2 == 1 and p == 1:
        print(1)
    elif a[0] % 2 == 0 and p == 0:
        print(2)
    else:
        print(0)
else:
    print(2**(n -1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,p = map(int,input().split())
a = list(map(lambda x:int(x)%2,input().split()))
cnt0 = a.count(0)
cnt1 = n-cnt0
if cnt0==n and p==0:
    print(2**n)
elif cnt0==0 and p==1:
    print(0)
else:
    print(2**(n-1))

Submission status: Wrong Answer

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())
a = list(map(lambda x:int(x)%2,input().split()))
cnt0 = a.count(0)
cnt1 = n-cnt0
ans = 2**cnt0
temp=0
for i in range(p,cnt1+1,2):
    temp += cmb(n,i)
print(ans*temp)

Submission status: Wrong Answer

Solution code:
n,p=map(int,input().split())
A=[i%2 for i in map(int,input().split())]
A0=A.count(0)
A1=A.count(1)
if p==1 and A1==0:
    print(0)
elif p==1 and A1==0:
    print(2**A0)
else:
    print((2**A0)*(2**A1)//2)

Submission status: Wrong Answer

Solution code:
n,p=map(int,input().split())
A=[i%2 for i in map(int,input().split())]
A0=A.count(0)
A1=A.count(1)
if p==1 and A1==0:
    print(0)
else:
    print((2**A0)*(2**A1)//2)

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
# @lru_cache(None)

n,p=l()
A=l()
o=e=0
for i in range(n):
    if(A[i]%2):
        o+=1
    else:
        e+=1
if(o):
    print(2**(n-1))
else:
    print(2**n)

Submission status: Wrong Answer

Solution code:
# from scipy.special import comb
from scipy.misc import comb

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

num_evens = len([a for a in as_ if a % 2 == 0])
num_odds = len([a for a in as_ if a % 2 == 1])

counts = 0
if p == 0:
    # 全部で偶数枚食べる = 偶数枚の袋 a 個 + 奇数枚の袋 b = 2k 個
    # 0袋食べる場合も OK.
    counts += 1
    # 1袋以上食べる場合
    for i in range(1, n + 1):
        # 全部で i 袋食べるとする i = 1 〜 n
        for a in range(i + 1):
            # そのうち偶数枚の袋を a 個食べる方法
            even_ways = comb(num_evens, a, exact=True)
            # 奇数枚の袋は (i - a) 個食べるが、それは偶数でなければならない
            b = (i - a)
            if b % 2 == 1 or b < 0:
                continue
            else:
                odd_ways = comb(num_odds, b, exact=True)

            counts += even_ways * odd_ways

else:
    # 全部で奇数枚食べる = 偶数枚の袋 a 個 + 奇数枚の袋 b = 2k + 1個 (k > 0)
    # 奇数の袋は0ではいけない (k > 0)
    # 0袋食べるのはダメ
    # 1袋以上食べる場合
    for i in range(1, n + 1):
        # 全部で i 袋食べるとする
        for b in range(1, i + 1):
            # 奇数枚の袋を b = 2k + 1 個食べる
            if b % 2 == 0:
                continue
            # すると偶数枚の袋は a = i - b 個食べる
            a = i - b
            if a < 0:
                continue

            odd_ways = comb(num_odds, b, exact=True)
            even_ways = comb(num_evens, a, exact=True)
            counts += even_ways * num_odds

print(counts)

Submission status: Wrong Answer

Solution code:
N,P = map(int, input().split())
A = list(map(int, input().split()))
in_odd = False
for i in range(N):
    if A[i]%2:
        in_odd = True
        break
if (not in_odd and P == 1):
    print(0)
else:
    print(2**(N-1))

Submission status: Wrong Answer

Solution code:
N,P = map(int, input().split())
A = list(map(int, input().split()))
in_odd = False
for i in range(N):
    if A[i]%2:
        in_odd = True
        break
if not in_odd:
    if P == 0:
        print(0)
else:
    print(2**(N-1))

Submission status: Wrong Answer

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

odds, evens = 0, 0

for i in A:
    if i & 1:
        odds += 1
        
    else:
        evens += 1

from math import factorial

if P == 0:
    ans = 0
    fo = factorial(odds)
    for r in range(2, odds + 1, 2):
        # ncr
        ans += fo // (factorial(odds - r) * factorial(r))
    ans *= 2**evens

else:
    ans = 0
    fo = factorial(odds)
    for r in range(1, odds + 1, 2):
        # ncr
        ans += fo // (factorial(odds - r) * factorial(r))

    ans *= 2**evens
print(ans)

Submission status: Wrong Answer

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

odds, evens = 0, 0

for i in A:
    if i & 1:
        odds += 1
        
    else:
        evens += 1

from math import factorial

if P == 0:
    ans = 2**evens
    fo = factorial(odds)
    for r in range(2, odds + 1, 2):
        # ncr
        ans += fo // (factorial(odds - r) * factorial(r))

else:
    ans = 0
    fo = factorial(odds)
    for r in range(1, odds + 1, 2):
        # ncr
        ans += fo // (factorial(odds - r) * factorial(r))

    ans *= 2**evens
print(ans)

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
import math

n,p = iim()
A = iil()

if n > 1:
    even = 0
    odd = 0
    for i in A:
        if i%2 == 0:
            even += 1
        else:
            odd += 1

    p0 = 2**(odd-1)
    print(2**even*p0)
else:
    if p == 0:
        print(2 if A[0]%2 == p else 0)
    else:
        print(1 if A[0]%2 == p else 0)

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
import math

n,p = iim()
A = iil()

if n > 1:
    even = 0
    odd = 0
    for i in A:
        if i%2 == 0:
            even += 1
        else:
            odd += 1

    p0 = 2**(odd-1)
    print(2**even*p0)
else:
    print(2 if A[0]%2 == p else 0)

Submission status: Wrong Answer

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

A = [a % 2 for a in A]

acc = [1] * 60
for i in range(60):
  if i == 0:
    continue
  acc[i] = acc[i-1] * i

odd = sum(A)
even = N - odd

ans = 0
if P == 0:
  # 奇数から偶数個
  j = 0
  for i in range(0,odd+1,2):
    j += acc[odd] // (acc[odd-i] * acc[i])
  
else:
  # 奇数から奇数個
  j = 0
  for i in range(1,odd+1,2):
    j += acc[odd] // (acc[odd-i] * acc[i])
  
ans = 0
for i in range(even):
  k = acc[even] // (acc[even-i] * acc[i])
  ans += k * j
  
print(ans)

Submission status: Wrong Answer

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

A = [a % 2 for a in A]

acc = [1] * 60
for i in range(60):
  if i == 0:
    continue
  acc[i] = acc[i-1] * i

odd = sum(A)
even = N - odd

ans = 0
if P == 0:
  # 奇数から偶数個
  j = 0
  for i in range(0,odd,2):
    j += acc[odd] // (acc[odd-i] * acc[i])
  
else:
  # 奇数から奇数個
  j = 0
  for i in range(1,odd,2):
    j += acc[odd] // (acc[odd-i] * acc[i])
  
ans = 0
for i in range(even):
  k = acc[even] // (acc[even-i] * acc[i])
  ans += k * j
  
print(ans)

Submission status: Wrong Answer

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

s = [0]*n
for i in range(n):
    if a[i]%2 == 0:
        s[i] = 0
    else:
        s[i] = 1
import collections
c = collections.Counter(s)
odd  = c[1]
even = c[0]
x = 0
i = 0
while  2*i+p <= even:
    x += comb(even, i)
    i += 1
ans = 0
i = 0
while  2*i+p <= odd:
    ans += comb(odd, 2*i+p)*x
    i += 1
if p == 0:
    print(ans)
else:
    print(ans*2)

Submission status: Wrong Answer

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

for i in A:
    if i % 2 == 0:
        even += 1
    else:
        odd += 1
#print(even,odd)

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

#print("0,0 = ", comb(0,0))
if P == 0:
    ans = 0
    for x in range(odd+1):
        if x % 2 == 0:
            ans += comb(odd,x)
    ans *= 2**even
    print(ans)
else:
    ans = 0
    for x in range(odd+1):
        if x % 2 == 1:
            if odd != 0:
                ans += comb(odd,x)
    ans *= 2**even
    print(ans)

Submission status: Wrong Answer

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

for i in A:
    if i % 2 == 0:
        even += 1
    else:
        odd += 1
#print(even,odd)

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

#print("0,0 = ", comb(0,0))
if P == 0:
    ans = 0
    for x in range(odd+1):
        if x % 2 == 0:
            if odd != 0:
                ans += comb(odd,x)
    ans *= 2**even
    print(ans)
else:
    ans = 0
    for x in range(odd+1):
        if x % 2 == 1:
            if odd != 0:
                ans += comb(odd,x)
    ans *= 2**even
    print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial

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

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

eve = 0
odd = 0

for i in range(n):
	if a[i]%2==0:
		eve += 1
	else:
		odd += 1
		
eve_cb = 2**eve
odd_cb = 0

for i in range(1,odd+1)[::2]:
	odd_cb += combinations_count(odd,i)

print(eve_cb*odd_cb)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
n-=1
if n == 0:
    print(0)
else:
    print(pow(2,n))

Submission status: Wrong Answer

Solution code:
from functools import lru_cache

@lru_cache(maxsize=None)

def kaijou(n):
    if n <= 1:
        return 1
    return kaijou(n-1)*n

n,p = map(int,input().split())
even = 0
odd = 0
ans = 0
for i in map(int,input().split()):
    if i % 2 == 0:
        even += 1
    else:
        odd += 1
if p == 0:
    eveng = 0
    for j in range(0,odd+1,2):
        if j > odd:
            break
        eveng += kaijou(odd)/kaijou(odd-j)/kaijou(j)
    ans = int((2**even)*eveng)
else:
    oddg = 0
    print(odd)
    for j in range(1,odd+1,2):
        if j > odd:
            break
        oddg += kaijou(odd)/kaijou(odd-j)/kaijou(j)
    ans = int((2**even)*oddg)
print(ans)

Submission status: Wrong Answer

Solution code:
n , p = map(int, input().split())
a = list(map(int,input().split()))
ans=2**(n-1)
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    odd = 0
    even = 0
    for a in A:
        if a&1:
            odd += 1
        else:
            even += 1
    if odd == 0:
        print(0)
    else:
        print(2**(N - 1))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

odd = [i for i in a if i % 2 == 1]
even = [i for i in a if i % 2 == 0]
ecnt = pow(2, len(even))
ocnt = pow(2, len(odd)-1)
print(0 if (len(odd) == 0 and p == 1) else ecnt * ocnt)

Submission status: Wrong Answer

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

if n == 1:
    print(1 if a[0] % 2 == p else 0)
else:
    odd = [i for i in a if i % 2 == 1]
    even = [i for i in a if i % 2 == 0]
    ecnt = pow(2, len(even))
    ocnt = pow(2, max(len(odd)-1,0))
    print(ecnt * ocnt)

Submission status: Wrong Answer

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

c = [0,0]
for a in A:
    c[a%2] += 1
print(2**(c[0]+c[1]-1))

Submission status: Wrong Answer

Solution code:
from math import factorial

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

#p==0:奇数が偶数個になるまで食べる
#p==1:奇数が奇数個になるまで食べる
def calc_comb(n,r):
    return factorial(n) / factorial(r) / factorial(n - r)

odd_len = 0
even_len = 0
for i in range(n):
    if a_input[i]%2==0:
        even_len+=1
    else:
        odd_len+=1

ans=0
even_comb = 2**even_len
if p==0:
    if odd_len%2==0:
        for i in range(0,odd_len+1,2):
            ans+=calc_comb(odd_len,i)*even_comb
            print(i)
    if odd_len%2==1:
        for i in range(1,odd_len+1,2):
            ans+=calc_comb(odd_len,i)*even_comb
else:
    if odd_len%2==0:
        for i in range(1,odd_len+1,2):
            ans+=calc_comb(odd_len,i)*even_comb
    if odd_len%2==1:
        for i in range(0,odd_len+1,2):
            ans+=calc_comb(odd_len,i)*even_comb
print(int(ans))

Submission status: Wrong Answer

Solution code:
# A - Biscuits
import numpy as np

N, P = map(int, input().split())
A = list(map(int, input().split()))
odd = len([i for i in A if i%2!=0])
if odd==0:
    ans = 0
else:
    ans = np.uint64(2**(N-1))
print(ans)

Submission status: Wrong Answer

Solution code:
# A - Biscuits

N, P = map(int, input().split())
print(2**N)

Submission status: Wrong Answer

Solution code:
from collections import Counter, defaultdict
from math import factorial
import numpy as np

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

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

d = defaultdict(int)
d.update(Counter(A).items())

if P == 0:
    ans = 1
    for i in range(1, d[0]+1):
        ans += nCr(d[0], i)
    for i in range(2, d[1]+1, 2):
        ans += nCr(d[1], i)
    print(ans)
else:
    if d[0] >= 1:
        e = []
        for i in range(0, d[0]+1):
            e.append(nCr(d[0], i))
        e = np.array(e)
    else:
        e = np.ones(1).astype(int)
    
    ans = 0
    for i in range(1, d[1]+1, 2):
        ans += sum(e * nCr(d[1], i))
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter, defaultdict
from math import factorial
import numpy as np

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

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

d = defaultdict(int)
d.update(Counter(A).items())

if P == 0:
    ans = 1
    for i in range(1, d[0]+1):
        ans += nCr(d[0], i)
    for i in range(2, d[1]+1, 2):
        ans += nCr(d[1], i)
    print(ans)
else:
    if d[0] >= 1:
        e = []
        for i in range(0, d[0]+1):
            e.append(nCr(d[0], i))
        e = np.array(e)
    else:
        e = 1
    
    ans = 0
    for i in range(1, d[1]+1, 2):
        ans += sum(e * nCr(d[1], i))
    print(ans)