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:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n,p = I()
A = [2 if i%2==0 else 1 for i in I()]
a = set(A)

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

Submission status: Wrong Answer

Solution code:
n,p=map(int,input().split())
a=[i%2 for i in list(map(int,input().split()))]
e=a.count(0)
o=a.count(1)
if n==1 and sum(a)%2!=p:
	print(0)
else:
	print((2**e)*(2**o)//2)

Submission status: Wrong Answer

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

print(2**(n-1))

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
from operator import mul
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def cmb(n: int, r: int):
    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 main():
    n, p = input_int_list()
    A = input_int_list()
    even = 0
    odd = 0
    for a in A:
        if a % 2 == 1:
            odd += 1
        else:
            even += 1

    if p == 1:
        ans = 2**even
        tmp = 0
        for i in range(1, odd, 2):
            tmp += cmb(odd, i)
        print(ans * tmp)
    elif p == 0:
        ans = 2**even
        tmp = 0
        for i in range(0, odd, 2):
            tmp += cmb(odd, i)
        print(ans * tmp)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import math
from math import factorial

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

#奇数の袋、偶数の袋の個数を求める。
odd = 0
even = 0

for A in As:
    if(A % 2 == 0):
        even += 1
    else:
        odd += 1

#偶数の組み合わせを求める。
#偶数の組み合わせは0~N個のすべての組み合わせである。
even_combi = 0

for i in range(even+1):
    even_combi += math.factorial(even) // math.factorial(i) // math.factorial(even-i)

print(even_combi)

#奇数の組み合わせを求める。
#奇数の組み合わせは、Pの値によって変わる。

#Pが0の時
odd_combi = 0

if(P == 0):
    for i in range(0,odd + 1,2):
        odd_combi += math.factorial(odd) // math.factorial(i) // math.factorial(odd-i)

else:
    for i in range(1, odd + 1 , 2):
        odd_combi += math.factorial(odd) // math.factorial(i) // math.factorial(odd-(i))

print(odd_combi*even_combi)

Submission status: Wrong Answer

Solution code:
import math

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

if __name__ == '__main__':  
    N, P = map(int, input().split())
    A = list(map(int, input().split()))

    odd = 0
    for a in A:
        if a%2==1:
            odd += 1
    ans = 0
    if P == 0:
        for i in range(0, odd+1, 2):
            ans += comb(N, i)
    else:
        for i in range(1, N+1, 2):
            ans += comb(N, i)
    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))

if __name__ == '__main__':  
    N, P = map(int, input().split())
    A = list(map(int, input().split()))

    odd = 0
    for a in A:
        if a%2==1:
            odd += 1
    ans = 0
    if P == 0:
        for i in range(0, odd+1, 2):
            ans += comb(N, i)
    else:
        for i in range(1, odd+1, 2):
            ans += comb(N, i)
    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))

if __name__ == '__main__':  
    N, P = map(int, input().split())
    A = list(map(int, input().split()))

    ans = 0
    if P == 0:
        for i in range(0, N+1, 2):
            ans += comb(N, i)
    else:
        for i in range(1, N+1, 2):
            print(i)
            ans += comb(N, i)
    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))

if __name__ == '__main__':  
    N, P = map(int, input().split())
    A = list(map(int, input().split()))

    ans = 0
    if P == 0:
        if N==1:
            print(0)
            quit()
        for i in range(0, N+1, 2):
            ans += comb(N, i)
    else:
        for i in range(1, N+1, 2):
            print(i)
            ans += comb(N, i)
    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))

if __name__ == '__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
    ans = 0
    if P == 0:
        for i in range(0, N+1, 2):
            ans += comb(N, i)
    else:
        for i in range(1, N+1, 2):
            ans += comb(N, i)
    print(ans)

Submission status: Wrong Answer

Solution code:
n,p = map(int,input().split())
a = list(map(int,input().split()))
odd = 0
even = 0
for ai in a:
    if(ai%2==0):
        even += 1
    else:
        odd += 1

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
def main():
    n,p=map(int,input().split())
    a=Counter(map(lambda x: int(x)%2, input().split()))
    ans=0
    for i in range(p, n+1, 2):
        ans += combinations_count(n, i)
    print(ans)

from operator import mul
from functools import reduce

def combinations_count(n:int, r:int) -> int:
    '''nCrの総数を返す。'''
    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
                       
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#47 A - Biscuits
N,P = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A,reverse = False)

m = sum(A) +1
dp = [0]*(m)

dp[0] = 2

# ビスケットの総数
v = 0

odd = 0
even = 1

# dp[v] が偶数なら 2, 奇数なら 1
# 選択する袋 a
for a in range(N):
    # a を選ぶか選ばないか
    for j in range(2):
        n = A[a]*j
        v += n       
        # 和が奇数なら 1 (odd + even)
        if dp[v-n]%2 != n%2:
            dp[v] = 1
            odd += 1
        # 和が偶数なら 2
        else:
            dp[v] = 2
            even += 1
if P == 0:
    print(even)
else:
    print(odd)

Submission status: Wrong Answer

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,P = MI()
A = LI()

x = sum(A[i] & 0 for i in range(N))  # Aiの中で、偶数であるものの個数
y = N-x  # Aiの中で、奇数であるものの個数

if y == 0:
    print(0 if P == 1 else 2**x)
else:
    print(2**(x+y-1))

Submission status: Wrong Answer

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,P = MI()
A = LI()

x = sum(A[i] & 1 for i in range(N))  # Aiの中で、偶数であるものの個数
y = N-x  # Aiの中で、奇数であるものの個数

if y == 0:
    print(0 if P == 1 else 2**x)
else:
    print(2**(x+y-1))

Submission status: Wrong Answer

Solution code:
import math
n, p, *a = map(int, open(0).read().split())


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


memo = [0, 0]
for i in range(n):
    memo[a[i] % 2] += 1
# p == 0


ans = 0
if p == 0:
    for i in range(0, memo[1], 2):
        ans += c(memo[1], i) * pow(2, memo[0])
else:
    for i in range(1, memo[1], 2):
        ans += c(memo[1], i) * pow(2, memo[0])
# p == 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,p=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=a[i]%2
one=sum(a)
zero=n-one
if p==1 and one==0:
    print(0)
    exit()
print(2**(n-1))

Submission status: Wrong Answer

Solution code:
n,p=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=a[i]%2
a.sort()
one=sum(a)
zero=n-one
if p==1 and one==0:
    print(0)
    exit()
print(2**(zero)*2**(one-1))

Submission status: Wrong Answer

Solution code:
Limit = 100
CMB = [[0]*(Limit+1) for _ in range(Limit+1)]
def cmb_table(Limit):
  for i in range(Limit+1):
    for j in range(Limit+1):
      if j == 0 or j == i: #端っこの場合
        CMB[i][j] = 1
      else:
        CMB[i][j] = CMB[i-1][j-1] + CMB[i-1][j]

cmb_table(Limit)
#print(CMB[0][3])
N,P = map(int,input().split())
A = list(map(int,input().split()))
odd = 0; even = 1
for x in A:
  if x%2 == 0:
    even +=1
  else:
    odd +=1
ans = 0
if P%2 == 0: #偶数の場合
  for x in range(N//2+1):
    E = x*2
    if E == 0:
      face = 1
    else:
      face = CMB[even][E]
    O = 0
    while E+O <= N:
      if O == 0:
        faco = 1
      else:
        faco += CMB[odd][O]
      O += 2
    #print(E,face,faco)
    ans += face*faco #どっちも選ばなくてOK
else:
  for x in range(N//2+1):
    E = x*2
    #print(E)
    if E == 0:
      face = 1
    else:
      face = CMB[even][E]
    O = 1
    while E+O <= N:
      if O == 1:
        faco = CMB[odd][O]
      else:
        faco += CMB[odd][O]
      O += 2
    #print(face,faco)
    ans += face*faco #どっちも選ばなくてOK
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
Limit = 100
CMB = [[0]*(Limit+1) for _ in range(Limit+1)]
def cmb_table(Limit):
  for i in range(Limit+1):
    for j in range(Limit+1):
      if j == 0 or j == i: #端っこの場合
        CMB[i][j] = 1
      else:
        CMB[i][j] = CMB[i-1][j-1] + CMB[i-1][j]

cmb_table(Limit)
#print(CMB[0][3])
N,P = map(int,input().split())
A = list(map(int,input().split()))
odd = 0; even = 1
for x in A:
  if x%2 == 0:
    even +=1
  else:
    odd +=1
ans = 0
if P%2 == 0: #偶数の場合
  for x in range(N//2+1):
    E = x*2
    if E == 0:
      face = 1
    else:
      face = CMB[even][E]
    O = 0
    while E+O <= N:
      if O == 0:
        faco = 1
      else:
        faco += CMB[odd][O]
      O += 2
    print(face,faco)
    ans += face*faco #どっちも選ばなくてOK
else:
  for x in range(N//2+1):
    E = x*2
    #print(E)
    if E == 0:
      face = 1
    else:
      face = CMB[even][E]
    O = 1
    while E+O <= N:
      if O == 1:
        faco = CMB[odd][O]
      else:
        faco += CMB[odd][O]
      O += 2
    #print(face,faco)
    ans += face*faco #どっちも選ばなくてOK
    
print(ans)

Submission status: Wrong Answer

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

MOD = 2 ** 61 - 1
table_len = 100

fac = [1, 1]
for i in range(2, table_len):
    fac.append(fac[-1] * i % MOD)

finv = [0] * table_len
finv[-1] = pow(fac[-1], MOD - 2, MOD)
for i in range(table_len-1, 0, -1):
    finv[i-1] = finv[i] * i % MOD

C = 0
D = 0
for A in As:
    if A % 2:
        D += 1
    else:
        C += 1

ans = pow(2, C)
ans *= sum( ((fac[D] * finv[i] * finv[D-i])%MOD for i in range(1, D+1, 2)) )
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,P = MI()
A = LI()

x,y = 0,0
for a in A:
    if a % 2 == 0:
        x += 1
    else:
        y += 1

if y == 0 and P == 1:
    print(0)
else:
    print(2**(x+y-1))

Submission status: Wrong Answer

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(int,input().split()))
even=0
odd=0
for a in A:
    if a%2==0:
        even+=1
    else:
        odd+=1
if N==1 and P==0 and odd==1:
    print(1)
elif N==1 and P==1 and odd==1:
    print(1)
elif P==1:
    if odd==0:
        print(0)
    else:
        answer=2**even
        suuji=0
        for n in range(1,odd+1,2):
            suuji+=combinations_count(odd,n)
        if suuji!=0 and answer>=2:
            answer*=suuji
        else:
            answer+=suuji
        print(answer)
else:
    if even==0 and odd==1:
        print(0)
    else:
        answer=2**even
        suuji=0
        for n in range(2,odd+1,2):
            suuji+=combinations_count(odd,n)
        if suuji != 0 and answer >= 2:
            answer *= suuji
        else:
            answer += suuji
        print(answer)

Submission status: Wrong Answer

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(int,input().split()))
even=0
odd=0
for a in A:
    if a%2==0:
        even+=1
    else:
        odd+=1
if P==1:
    if odd==0:
        print(0)
    else:
        answer=2**even
        suuji=0
        for n in range(1,odd+1,2):
            suuji+=combinations_count(odd,n)
        if suuji!=0 and answer>=2:
            answer*=suuji
        else:
            answer+=suuji
        print(answer)
else:
    if even==0 and odd==1:
        print(0)
    else:
        answer=2**even
        suuji=0
        for n in range(2,odd+1,2):
            suuji+=combinations_count(odd,n)
        if suuji != 0 and answer >= 2:
            answer *= suuji
        else:
            answer += suuji
        print(answer)

Submission status: Wrong Answer

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(int,input().split()))
even=0
odd=0
for a in A:
    if a%2==0:
        even+=1
    else:
        odd+=1
if P==1:
    if odd==0:
        print(0)
    else:
        answer=2**even
        suuji=0
        for n in range(1,odd+1,2):
            suuji+=combinations_count(odd,n)
        if suuji!=0:
            answer*=suuji
        print(answer)
else:
    if even==0 and odd==1:
        print(0)
    else:
        answer=2**even
        suuji=0
        for n in range(2,odd+1,2):
            suuji+=combinations_count(odd,n)
        if suuji!=0:
            answer*=suuji
        print(answer)

Submission status: Wrong Answer

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

anseven = 1
ansodd = 0

dic = {0:1}
for i in range(1, 51):
    dic[i] = dic[i - 1] * i

#  偶数i個選ぶ
for i in range(1, even + 1):
    anseven += dic[even] // dic[even - i] // dic[i]

if P == 0:
    #  奇数i個選ぶ
    for i in range(2, odd + 1, 2):
        ansodd += dic[odd] // dic[odd - i] // dic[i]

else:
    if odd == 0:
        print(0)
        exit()
    #  奇数i個選ぶ
    for i in range(1, odd + 1, 2):
        ansodd += dic[odd] // dic[odd - i] // dic[i]

print(anseven * ansodd)

Submission status: Wrong Answer

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

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

ans = 0

for i in range(0,odd+2,2):
    if i+p > odd:
        break
    for j in range(0,even+1,2):
        if j > even:
            break
        
        a = 1
        for k in range(i+p):
            a *= (odd-k)
            a /= k+1
    
        b = 1
        for k in range(j):
            b *= (even-k)
            b /= k+1
       
        
        ans += a*b
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, P = mapint()
As = list(mapint())
bit = [a%2 for a in As]

pos = {}
pos[0] = 1
for i in range(1, N+1):
    pos[i] = pos[i-1]*i
dic = {}
dic[0] = 0
dic[1] = 0
for i in bit:
    dic[i] += 1

ans = 2**dic[0]
if P<1:
    if dic[1]<1:
        print(0)
        exit(0)
    else:
        ans*=dic[1]
        dic[1] -= 1
val = 0
for i in range(dic[1]//2+1):
    val += pos[dic[1]]//pos[i*2]//pos[dic[1]-i*2]
print(val*ans)

Submission status: Wrong Answer

Solution code:
from scipy.special import comb
n, p, *A = map(int, open(0).read().split())
odd = sum(a%2 for a in A)
even = n - odd

if p:
  s = 0
  for i in range(1, odd, 2):
    s += comb(odd, i, exact=True)
  s *= pow(2, even)
  print(s)
else:
  s = 0
  for i in range(0, odd, 2):
    s += comb(odd, i, exact=True)
  s *= pow(2, even)
  print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def solve():
  N, P = map(int, input().split())
  A = list(map(int, input().split()))
  zero,one = 0,0
  for i in range(N):
    if A[i]%2==0:
      zero += 1
    else:
      one += 1
  if P==1:
    ans = pow(2,N-1)
  else:
    ans = pow(2,N-1)
  return ans
print(solve())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,P = list(map(int,input().split()))
A = list(map(int,input().split()))
o = 0
class Com:
    def __init__(self, MAX = 510000, MOD = 10000000000007):
        self.MAX = MAX
        self.MOD = MOD
        self._fac = [0]*MAX
        self._finv = [0]*MAX
        self._inv = [0]*MAX
        self._fac[0], self._fac[1] = 1, 1
        self._finv[0], self._finv[1] = 1, 1
        self._inv[1] = 1
        for i in range(2,self.MAX):
            self._fac[i] = self._fac[i - 1] * i % self.MOD
            self._inv[i] = self.MOD - self._inv[self.MOD%i] * (self.MOD // i) % self.MOD
            self._finv[i] = self._finv[i - 1] * self._inv[i] % self.MOD
    
    def com(self, n, k):
        if (n < k):
            return 0
        if (n < 0 or k < 0):
            return 0
        return self._fac[n] * (self._finv[k] * self._finv[n - k] % self.MOD) % self.MOD

for a in A:
    if a%2 == 1:
        o += 1
com = Com()
L1 = []
for i in range(0,N-o+1):
    L1.append(com.com(N-o, i))
L2 = []
for i in range(1,o+1,2):
    L2.append(com.com(o, i))
ans = 0
for l1 in L1:
    for l2 in L2:
        ans += l1*l2
print(ans)

Submission status: Wrong Answer

Solution code:
N,P = list(map(int,input().split()))
A = list(map(int,input().split()))
o = 0
class Com:
    def __init__(self, MAX = 510000, MOD = 100000000007):
        self.MAX = MAX
        self.MOD = MOD
        self._fac = [0]*MAX
        self._finv = [0]*MAX
        self._inv = [0]*MAX
        self._fac[0], self._fac[1] = 1, 1
        self._finv[0], self._finv[1] = 1, 1
        self._inv[1] = 1
        for i in range(2,self.MAX):
            self._fac[i] = self._fac[i - 1] * i % self.MOD
            self._inv[i] = self.MOD - self._inv[self.MOD%i] * (self.MOD // i) % self.MOD
            self._finv[i] = self._finv[i - 1] * self._inv[i] % self.MOD
    
    def com(self, n, k):
        if (n < k):
            return 0
        if (n < 0 or k < 0):
            return 0
        return self._fac[n] * (self._finv[k] * self._finv[n - k] % self.MOD) % self.MOD

for a in A:
    if a%2 == 1:
        o += 1
com = Com()
L1 = []
for i in range(0,N-o+1):
    L1.append(com.com(N-o, i))
L2 = []
if P == 1:
    for i in range(1,o+1,2):
        L2.append(com.com(o, i))
else:
    for i in range(0,o+1,2):
        L2.append(com.com(o, i))
ans = 0
for l1 in L1:
    for l2 in L2:
        ans += l1*l2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

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

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

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

N,P = I()
A = l()
odd = 0
even = 0
for i in range(N):
    if A[i]%2 == 0:
        even += 1
    else:
        odd += 1
ans = 0
if P == 0:
    for i in range(0,odd,2):
        ans += cmb(odd,i)
    print(ans*(2**even))
else:
    for i in range(1,odd,2):
        ans += cmb(odd,i)
    print(ans*(2**even))

Submission status: Wrong Answer

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

N, P = map(int, input().split())
a_li = list(map(int, input().split()))
ans = 0
"""
Pは0か1。
トータルで偶数になるか奇数になるかを考えればいい。
ビスケットが偶数個入っている袋の個数をe個、奇数個入っている袋の個数をo個とする。
偶数個入っている袋に関しては選んでも選ばなくても結果に影響しないので
2 ** e通りある。
奇数個入っている袋については、トータルで偶数個になるように選ぶなら、奇数個選ぶ。
トータルで奇数個になるように選ぶなら、偶数個選ぶ。
"""
e = 0
o = 0
for a in a_li:
    if a % 2 == 0:
        e += 1
    else:
        o += 1
# 奇数個入っている袋を選ぶ個数の初期値。
initial = 1 if P == 0 else 0
comb = 0
for i in range(initial, o + 1, 2):
    comb += cmb(o, i)
if P == 1 and o == 0:
    # 最終的に奇数個にしたいが奇数個入った袋がない場合
    comb = 0
if P == 0:
    # 「選ばない」という選択肢がある
    print(max(2 ** e * comb, 1))
else:
    print(2 ** e * comb)

Submission status: Wrong Answer

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

N, P = map(int, input().split())
a_li = list(map(int, input().split()))
ans = 0
"""
Pは0か1。
トータルで偶数になるか奇数になるかを考えればいい。
ビスケットが偶数個入っている袋の個数をe個、奇数個入っている袋の個数をo個とする。
偶数個入っている袋に関しては選んでも選ばなくても結果に影響しないので
2 ** e通りある。
奇数個入っている袋については、トータルで偶数個になるように選ぶなら、奇数個選ぶ。
トータルで奇数個になるように選ぶなら、偶数個選ぶ。
"""
e = 0
o = 0
for a in a_li:
    if a % 2 == 0:
        e += 1
    else:
        o += 1
initial = 1 if P == 0 else 0
comb = 0
for i in range(initial, o + 1, 2):
    if o > 0:
        comb += cmb(o, i)
if P == 0:
    # 「選ばない」という選択肢がある
    print(max(2 ** e * comb, 1))
else:
    print(2 ** e * comb)

Submission status: Wrong Answer

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

N, P = map(int, input().split())
a_li = list(map(int, input().split()))
ans = 0
"""
Pは0か1。
トータルで偶数になるか奇数になるかを考えればいい。
ビスケットが偶数個入っている袋の個数をe個、奇数個入っている袋の個数をo個とする。
偶数個入っている袋に関しては選んでも選ばなくても結果に影響しないので
2 ** e通りある。
奇数個入っている袋については、トータルで偶数個になるように選ぶなら、奇数個選ぶ。
トータルで奇数個になるように選ぶなら、偶数個選ぶ。
"""
e = 0
o = 0
for a in a_li:
    if a % 2 == 0:
        e += 1
    else:
        o += 1
initial = 1 if P == 0 else 0
comb = 0
for i in range(initial, o + 1, 2):
    comb += cmb(o, i)
print(2 ** e * comb)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

from itertools import product

N, P = map(int, input().split())
a_li = list(map(int, input().split()))
ans = 0
"""
Pは0か1。
トータルで偶数になるか奇数になるかを考えればいい。
ビスケットが偶数個入っている袋の個数をe個、奇数個入っている袋の個数をo個とする。
偶数個入っている袋に関しては選んでも選ばなくても結果に影響しないので
2 ** e通りある。
奇数個入っている袋については、トータルで偶数個になるように選ぶなら、奇数個選ぶ。
トータルで奇数個になるように選ぶなら、偶数個選ぶ。
"""
e = 0
o = 0
for a in a_li:
    if a % 2 == 0:
        e += 1
    else:
        o += 1
initial = 1 if P == 0 else 0
comb = 0
if o > 0:
    for i in range(initial, o + 1, 2):
        comb += len(list(combinations(range(o), i)))
print(2 ** e * comb)

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    N, P = [int(item) for item in input().split()]
    As = [int(item)%2 for item in input().split()]

    is_all_even = True
    for item in As:
        if item == 1:
            is_all_even = False
    res = 0
    if is_all_even:
        if P == 0:
            res = 2 ** N
        else:
            res = 0
    else:
        print(2**(N-1))

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
from scipy.special import comb
import numpy as np

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

A = A % 2 != 0
odd = np.sum(A)
even = N - odd
print(A, odd, even)

ans = 0
odd_num = 0
even_num = 0
if P == 1:
    for i in range(1, odd + 1, 2):
        odd_num += comb(odd, i, exact=True)
    even_num = pow(2, even)
    ans = odd_num * even_num
else:
    for i in range(0, odd + 1, 2):
        odd_num += comb(odd, i, exact=True)
    even_num = pow(2, even)
    ans = odd_num * even_num
    # print(odd_num, even_num)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math
import itertools
N, P = map(int,input().split())
A = list(map(int,input().split()))
cnt0 = 0
cnt1 = 0
for i in range(N):
    if A[i]%2 == 0:
        A[i] = 0
        cnt0 += 1
    else:
        A[i] = 1
        cnt1 += 1

#0はいくらでも選べる
#1をいくつ選ぶか
def modcomb(n,r):
    X, Y =  1, 1
    r = min(r, n-r)
    for i in range(1,r+1):
        X = X * (n-i+1)
        Y = Y * i
    
    return X // Y
ans = 0
if P == 0:#1を奇数個選ぶ
    for i in range(math.ceil(cnt1/2)):
        ans += modcomb(cnt1, 2*i+1)
else:#1を偶数個選ぶ
    for i in range(cnt1//2+1):
        ans += modcomb(cnt1, 2*i)

if (cnt1 == 0 and P == 1):
    ans = 0
else:
    ans *= 2**cnt0
print(ans)

Submission status: Wrong Answer

Solution code:
#AGC017-A
from math import factorial
def nCr(n,r):
    return factorial(n) / factorial(r) / factorial(n - r)
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

#偶数
if p == 0:
    temp = 0
    for i in range(0,odd+1,2):
        print(i)
        temp += nCr(odd,i)
    print(int(2**even * temp))
#奇数
else:
    temp = 0
    for i in range(1,odd+1,2):
        temp += nCr(odd,i)
    print(int(2**even * temp))