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:
n, p = map(int, input().split())
a = list(map(int, input().split()))

odd = sum([item % 2 for item in a])
even = n - odd

ans = 0
if even == n and p == 1:
    print(0)
elif odd == n and p == 0:
    print(0)
else:
    # 偶数枚入った袋は選ぶor選ばない自由
    ans += 2 ** even

    # 奇数枚入った袋は2で割って余りがPになるよう選ぶ個数を決める
    ans *= 2 ** (odd - 1)
    print(ans)

Submission status: Wrong Answer

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

odd = sum([item % 2 for item in a])
even = n - odd

ans = 0
if even == n and p == 1:
    print(0)
else:
    # 偶数枚入った袋は選ぶor選ばない自由
    ans += 2 ** even

    # 奇数枚入った袋は2で割って余りがPになるよう選ぶ個数を決める
    ans *= 2 ** (odd - 1)
    print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce


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

LLeven = map(lambda x: x % 2, L)
LLodd = map(lambda x: x % 2, L)

even = list(LLeven).count(0)
odd = list(LLodd).count(1)

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


def pattern(x):
    (choose_even,choose_odd) = (0,0)
    for i in range(x):
        if i%2 == 0:
            choose_even += cmb(x,i)
        else:
            choose_odd += cmb(x,i)
    return(choose_even,choose_odd)

if p == 0:
    print(2**even * pattern(odd)[0])
else:
    print(2**even * pattern(odd)[1])

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

gu = 0
ki = 0
for a in al:
    if a % 2 == 0:
        gu += 1
    else:
        ki += 1
    
MOD = 10**9 + 7
N = 10**5

fact = [1]*(N+1)
rfact = [1]*(N+1)
r = 1
for i in range(1, N+1):
  fact[i] = r = r * i % MOD
rfact[N] = r = pow(fact[N], MOD-2, MOD)
for i in range(N, 0, -1):
  rfact[i-1] = r = r * i % MOD

# nPk (mod MOD) を求める
def perm(n, k):
  return fact[n] * rfact[n-k] % MOD

# nCk (mod MOD) を求める
def comb(n, k):
  return fact[n] * rfact[k] * rfact[n-k] % MOD

a = 0
b = 0
for i in range(gu+1):
    a += comb(gu, i)
for i in range(ki+1):
    if i % 2 == p:
        b += comb(ki, i)
print(a*b)

Submission status: Wrong Answer

Solution code:
N,P=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
for i in A:
    if i != 0:
        print(2**(N-1))
        exit()
if P ==0:
    print(2**N)
else:
    print(0)

Submission status: Wrong Answer

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

even_num=0
odd_num=0

for a in A:
    if a%2==0:
        even_num+=1
    else:
        odd_num+=1

ev_case = 2**even_num


from math import factorial

res=0
for i in range(P,odd_num+1,2):                                                                   res += factorial(odd_num) / factorial(i) / factorial(odd_num - i)

print(ev_case*res)

Submission status: Wrong Answer

Solution code:
import scipy.misc
N,P=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
odd = 0
even = 0
for i in A:
    if i%2 !=0:
        odd += 1
    else:
        even += 1

ans = 0
if P ==1:
    for i in range(1,odd+1,2):
        ans += scipy.misc.comb(odd,i)
else:
    for i in range(0,odd+1,2):
        ans += scipy.misc.comb(odd,i)
ans = ans*(2**even)
print(int(-(-1*ans//1)))

Submission status: Wrong Answer

Solution code:
import scipy.misc
N,P=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
odd = 0
even = 0
for i in A:
    if i%2 !=0:
        odd += 1
    else:
        even += 1

ans = 0
if P ==1:
    for i in range(1,odd+1,2):
        ans += scipy.misc.comb(odd,i)
else:
    for i in range(0,odd+1,2):
        ans += scipy.misc.comb(odd,i)
ans = ans*(2**even)
print(ans)

Submission status: Wrong Answer

Solution code:
import scipy.misc
N,P=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
odd = 0
even = 0
for i in A:
    if i%2 !=0:
        odd += 1
    else:
        even += 1

ans = 0
if P ==1:
    for i in range(1,odd+1,2):
        ans += scipy.misc.comb(odd,i)
else:
    for i in range(0,odd+1,2):
        ans += scipy.misc.comb(odd,i)
ans = ans*(2**even)
print(int(ans))

Submission status: Wrong Answer

Solution code:
def sq(a, b, mod):  # aのb乗を剰余,kは初期値#20191116-D-Knight
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod


def nCk(n, k, mod=10 ** 9 + 7):
    x = max(k, n - k)
    y = min(k, n - k)
    kkai = 1
    for i in range(2, y + 1):
        kkai = (kkai * i) % mod
    nkkai = 1
    for i in range(x + 1, n + 1):
        nkkai = (nkkai * i) % mod
    answer = sq(kkai, mod - 2, mod) * nkkai % mod
    return answer


from collections import Counter
N, P = map(int, input().split())
Ac = Counter([n % 2 for n in list(map(int, input().split()))])
ans = 0
if P == 0:  # ok
    for i in range(0, Ac[1] + 1, 2):
        ans += nCk(Ac[1], i)
else:
    for i in range(0, Ac[1] + 1, 2):
        ans += nCk(Ac[1], i)
    ans *= (2**Ac[0])
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from math import factorial

n,p = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

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

guusu = 0
kisuu = 0

for i in li:
    if i%2 == 0:
        guusu += 1
    else:
        kisuu += 1

point = 0

if p == 0:
    if guusu != 0:
        for i in range(guusu//2+1):
            point += combinations_count(guusu,i*2)
    if kisuu != 0:
        for j in range(kisuu//2+1):
            point += combinations_count(kisuu,j*2)
if p == 1:
    for i in range(guusu+1):
        for j in range(kisuu//2 if kisuu%2 == 0 else kisuu//2+1):
            point += combinations_count(guusu,i)*combinations_count(kisuu,j*2+1)

print(point)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from math import factorial

n,p = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

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

guusu = 0
kisuu = 0

for i in li:
    if i%2 == 0:
        guusu += 1
    else:
        kisuu += 1

point = 0

if p == 0:
    for i in range(guusu//2+1):
        point += combinations_count(guusu,i*2)
    for j in range(kisuu//2+1):
        point += combinations_count(kisuu,j*2)
if p == 1:
    for i in range(guusu+1):
        for j in range(kisuu//2 if kisuu%2 == 0 else kisuu//2+1):
            point += combinations_count(guusu,i)*combinations_count(kisuu,j*2+1)

print(point)

Submission status: Wrong Answer

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

print( (2**zero) * (2**(max(0, one-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()))
odd_num = 0
even_num = 0
for a in A:
    if a % 2 == 1:
        odd_num += 1
    else:
        even_num += 1
ans = 0

if P == 1:
    if odd_num == 0:
        ans = 0
    else:
        for i in range(1, N + 1, 2):
            ans += combinations_count(N, i)
else:
    # even_combinations = 2 ** even_num
    for i in range(0, N + 1, 2):
        ans += combinations_count(N, i)
    # ans *= even_combinations
print(ans)

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()))
odd_num = 0
even_num = 0
for a in A:
    if a % 2 == 1:
        odd_num += 1
    else:
        even_num += 1
ans = 0

if P == 1:
    if odd_num == 0:
        ans = 0
    else:
        for i in range(1, N + 1, 2):
            ans += combinations_count(N, i)
else:
    even_combinations = 2 ** even_num
    for i in range(0, N + 1, 2):
        ans += combinations_count(N, i)
    ans *= even_combinations
print(ans)

Submission status: Wrong Answer

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

jug = True
for i in range(n):
    a[i] % 2 == 1
    jug = False
    break

if jug:
    if p == 0:
        print(2 ** n)
    elif 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()))

jug = True
for i in range(n):
    a[i] % 2 == 1
    jug = False
    break

if jug:
    if p == 0:
        print(2 ** n)
    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()))

jug = True
for i in range(n):
    a[i] % 2 == 1
    jug = False
    break

if jug:
    if p == 0:
        print(2 ** n)
    else:
        print(0)

else:
    print(2 * (n - 1))

Submission status: Wrong Answer

Solution code:
# P=0 -> 奇数を偶数個といくつかの偶数個
# P=1 -> 奇数を奇数個といくつかの奇数個
n, p = map(int, input().split())
odds = n - len(list(filter(lambda x: int(x) % 2 == 0, input().split())))
evens = n - odds


def ncr(n, r):
    res = 1
    for i in range(1, r + 1):
        res = res * (n - i + 1) // i
    return res


ans = 0
if p == 0:
    for i in range(0, odds, 2):
        ans += ncr(odds, i)
    if evens > 0:
        ans *= max(1, 2 ** evens)
else:
    for i in range(1, odds, 2):
        ans += ncr(odds, i)
    if evens > 0:
        ans *= max(1, 2 ** evens)
print(ans)

Submission status: Wrong Answer

Solution code:
# P=0 -> 奇数を偶数個といくつかの偶数個
# P=1 -> 奇数を奇数個といくつかの奇数個
n, p = map(int, input().split())
odds = n - len(list(filter(lambda x: int(x) % 2 == 0, input().split())))
evens = n - odds

def ncr(n, r):
    res = 1
    for i in range(1, r + 1):
        res = res * (n - i + 1) // i
    return res


ans = 0
if p == 0:
    for i in range(0, odds, 2):
        ans += ncr(odds, i)
    ans *= max(1, 2 ** evens)
else:
    for i in range(1, odds, 2):
        ans += ncr(odds, i)
    ans *= max(1, 2 ** evens)
print(ans)

Submission status: Wrong Answer

Solution code:
# P=0 -> 奇数を偶数個といくつかの偶数個
# P=1 -> 奇数を奇数個といくつかの奇数個
n, p = map(int, input().split())
odds = n - len(list(filter(lambda x: int(x) % 2 == 0, input().split())))
evens = n - odds

print(evens, odds)


def ncr(n, r):
    res = 1
    for i in range(1, r + 1):
        res = res * (n - i + 1) // i
    return res


ans = 0
if p == 0:
    for i in range(0, odds, 2):
        ans += ncr(odds, i)
    ans *= max(1, 2 ** evens)
else:
    for i in range(1, odds, 2):
        ans += ncr(odds, i)
    ans *= max(1, 2 ** evens)
print(ans)

Submission status: Wrong Answer

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

odd = 0
even = 0

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

if p == 0:
    print((2 ** even) * max(2 ** (odd - 1), 1))
elif p == 1:
    print((2 ** even) * max(2 ** (odd - 1) - 1, 0))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools
from math import factorial
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, p = LI()
    a = LI()
    odd = sum(map(lambda x: x & 1, a))
    even = sum(map(lambda x: (x ^ 1) & 1, a))
    t0 = 0
    t1 = 0
    for i in range(0, odd + 1, 2):
        a = factorial(odd)
        b = factorial(i)
        c = factorial(odd - i)
        t1 += a // b // c
    for i in range(1, odd + 1, 2):
        a = factorial(odd)
        b = factorial(i)
        c = factorial(odd - i)
        t0 += a // b // c
    print(2 ** even * t1 if p else 2 ** even * t0)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

#print(a)

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


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

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

Submission status: Wrong Answer

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

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

#print(a)

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

#print(gu,ki)


if ki==0 and p==1:
	print(0)
	exit()

ans = 0
if p==0:
	ans = ans + 2**gu * (2**ki)/2
	print(int(ans))
else:
	ans = ans + 2**gu * (2**ki)/2
	print(int(ans))

Submission status: Wrong Answer

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

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

print(a)

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

print(gu,ki)


if ki==0 and p==1:
	print(0)
	exit()

ans = 0
if p==0:
	ans = ans + 2**gu * (2**ki)/2
	print(int(ans))
else:
	ans = ans + 2**gu * (2**ki)/2
	print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ret = pow(2, e + o - 1)
if o == 0 and P == 0 :
  ret += 1
if o == 0 and P == 1 :
  ret -= 1
  
print(ret)

Submission status: Wrong Answer

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

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

if o == 0 and P == 1 :
  print(0)
else :
  print(pow(2, e + o - 1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import factorial

def ncr(n,r):
  r = min(n-r,r)
  return int(factorial(n)/(factorial(n-r)*factorial(r)))

N, P = map(int,input().split())
A = list(map(int,input().split()))
odd_cnt = 0
eve_cnt = 0
for a in A:
  if a%2 == 0: eve_cnt += 1
  else: odd_cnt += 1
if P == 0:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(1,eve_cnt+1)]) if eve_cnt >= 1 else 0
  cases_odd = sum([ncr(odd_cnt,r) for r in range(2,odd_cnt+1,2)]) if odd_cnt >= 2 else 0
  if cases_eve == 0: print(cases_odd + 1)
  elif cases_odd == 0: print(cases_eve + 1)
  else: print(cases_eve*(cases_odd+1) + 1)
else:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(1,odd_cnt+1,2)]) if odd_cnt != 0 else 0
  print(cases_eve*cases_odd)

Submission status: Wrong Answer

Solution code:
from math import factorial

def ncr(n,r):
  r = min(n-r,r)
  return int(factorial(n)/(factorial(n-r)*factorial(r)))

N, P = map(int,input().split())
A = list(map(int,input().split()))
odd_cnt = 0
eve_cnt = 0
for a in A:
  if a%2 == 0: eve_cnt += 1
  else: odd_cnt += 1
if P == 0:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(1,eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(2,odd_cnt+1,2)]) if odd_cnt >= 2 else 0
  print(cases_eve*(cases_odd+1) + 1 if eve_cnt!=0 else cases_eve*(cases_odd+1))
else:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(1,odd_cnt+1,2)]) if odd_cnt != 0 else 0
  print(cases_eve*cases_odd)

Submission status: Wrong Answer

Solution code:
from math import factorial

def ncr(n,r):
  r = min(n-r,r)
  return int(factorial(n)/(factorial(n-r)*factorial(r)))

N, P = map(int,input().split())
A = list(map(int,input().split()))
odd_cnt = 0
eve_cnt = 0
for a in A:
  if a%2 == 0: eve_cnt += 1
  else: odd_cnt += 1
if P == 0:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(1,eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(2,odd_cnt+1,2)]) if odd_cnt >= 2 else 0
  print(cases_eve*(cases_odd+1) + 1)
else:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(1,odd_cnt+1,2)]) if odd_cnt != 0 else 0
  print(cases_eve*cases_odd)

Submission status: Wrong Answer

Solution code:
from math import factorial

def ncr(n,r):
  r = min(n-r,r)
  return int(factorial(n)/(factorial(n-r)*factorial(r)))

N, P = map(int,input().split())
A = list(map(int,input().split()))
odd_cnt = 0
eve_cnt = 0
for a in A:
  if a%2 == 0: eve_cnt += 1
  else: odd_cnt += 1
if P == 0:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(1,eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(2,odd_cnt+1,2)]) if odd_cnt >= 2 else 0
  print(cases_eve*(cases_odd) + 1)
else:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(1,odd_cnt+1,2)]) if odd_cnt != 0 else 0
  print(cases_eve*cases_odd)

Submission status: Wrong Answer

Solution code:
from math import factorial

def ncr(n,r):
  r = min(n-r,r)
  return int(factorial(n)/(factorial(n-r)*factorial(r)))

N, P = map(int,input().split())
A = list(map(int,input().split()))
odd_cnt = 0
eve_cnt = 0
for a in A:
  if a%2 == 0: eve_cnt += 1
  else: odd_cnt += 1
if P == 0:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(2,odd_cnt+1,2)]) if odd_cnt >= 2 else 0
  print(cases_eve*(cases_odd) + 1)
else:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(1,odd_cnt+1,2)]) if odd_cnt != 0 else 0
  print(cases_eve*cases_odd)

Submission status: Wrong Answer

Solution code:
from math import factorial

def ncr(n,r):
  r = min(n-r,r)
  return int(factorial(n)/(factorial(n-r)*factorial(r)))

N, P = map(int,input().split())
A = list(map(int,input().split()))
odd_cnt = 0
eve_cnt = 0
for a in A:
  if a%2 == 0: eve_cnt += 1
  else: odd_cnt += 1
if P == 0:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(0,odd_cnt+1,2)]) if odd_cnt != 0 else 0
  print(cases_eve*(cases_odd-1) + 1)
else:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(1,odd_cnt+1,2)]) if odd_cnt != 0 else 0
  print(cases_eve*cases_odd)

Submission status: Wrong Answer

Solution code:
from math import factorial

def ncr(n,r):
  r = min(n-r,r)
  return int(factorial(n)/(factorial(n-r)*factorial(r)))

N, P = map(int,input().split())
A = list(map(int,input().split()))
odd_cnt = 0
eve_cnt = 0
for a in A:
  if a%2 == 0: eve_cnt += 1
  else: odd_cnt += 1
if P == 0:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(0,odd_cnt+1,2)]) if odd_cnt != 0 else 0
else:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(1,odd_cnt+1,2)]) if odd_cnt != 0 else 0
print(cases_eve*cases_odd)

Submission status: Wrong Answer

Solution code:
from math import factorial

def ncr(n,r):
  r = min(n-r,r)
  return int(factorial(n)/(factorial(n-r)*factorial(r)))

N, P = map(int,input().split())
A = list(map(int,input().split()))
odd_cnt = 0
eve_cnt = 0
for a in A:
  if a%2 == 0: eve_cnt += 1
  else: odd_cnt += 1
if P == 0:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 0
  cases_odd = sum([ncr(odd_cnt,r) for r in range(0,odd_cnt+1,2)]) if odd_cnt != 0 else 0
  print(cases_eve + cases_eve*cases_odd + cases_odd)
else:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 1
  cases_odd = sum([ncr(odd_cnt,r) for r in range(1,odd_cnt+1,2)]) if odd_cnt != 0 else 0
  print(cases_eve*cases_odd)

Submission status: Wrong Answer

Solution code:
from math import factorial

def ncr(n,r):
  r = min(n-r,r)
  return int(factorial(n)/(factorial(n-r)*factorial(r)))

N, P = map(int,input().split())
A = list(map(int,input().split()))
odd_cnt = 0
eve_cnt = 0
for a in A:
  if a%2 == 0: eve_cnt += 1
  else: odd_cnt += 1
if P == 0:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 0
  cases_odd = sum([ncr(odd_cnt,r) for r in range(0,odd_cnt+1,2)]) if odd_cnt != 0 else 0
  print(cases_eve + cases_eve*cases_odd + cases_odd)
else:
  cases_eve = sum([ncr(eve_cnt,r) for r in range(eve_cnt+1)]) if eve_cnt != 0 else 0
  cases_odd = sum([ncr(odd_cnt,r) for r in range(1,odd_cnt+1,2)]) if odd_cnt != 0 else 0
  print(cases_eve*cases_odd + cases_odd)

Submission status: Wrong Answer

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

x = 0
y = 0

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

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

Submission status: Wrong Answer

Solution code:
from math import factorial

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

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

o = 0
e = 0

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

a = []
b = []
ans = 0

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

Submission status: Wrong Answer

Solution code:
import math
n, p = map(int, input().split())
a = list(map(int, input().split()))
def combi(x, y):
    if y == 0:
        return 1
    if x == 0:
        return 0

    return math.factorial(x) / (math.factorial(x - y) * math.factorial(y))
odd_count = 0
even_count = 0
for i in range(n):
    if a[i] % 2 == 0:
        even_count += 1
    else:
        odd_count += 1
ans = 0
if p % 2 == 0:
    ans += 2 ** even_count
    ans += combi(odd_count, 2)
else:
    ans += combi(odd_count,2)
print(int(ans))

Submission status: Wrong Answer

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

print(ans*tmp)

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(len(a)):
         if a[i] % 2 == 0:
                  even += 1
         else:
                  odd += 1
if p == 1 and odd == 0:
         print(0)
else:
         print((2**(odd-1))*(2**even))

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb

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

odd = []
even = []

#偶奇わけ
for _a in a:
        if _a%2 == 0:
                even.append(_a)
        else:
                odd.append(_a)

lenE = len(even)
lenO = len(odd)

totalE = 0
totalO = 0
for i in range(1, lenE+1):
        totalE += comb(lenE, i)

if p == 0:
        #偶数
        ans += 1
        for i in range(1, lenO+1):
                if i%2 == 0:
                        totalO += comb(lenO, i)
        ans += totalO + totalE + totalE*totalO
        print(int(ans))
elif p == 1:
        #奇数
        for i in range(1, lenO+1):
                if i%2 != 0:
                        totalO += comb(lenO, i)

        ans += totalO + totalO*totalE
        print(int(ans))

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb

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

odd = []
even = []

#偶奇わけ
for _a in a:
        if _a%2 == 0:
                even.append(_a)
        else:
                odd.append(_a)

lenE = len(even)
lenO = len(odd)

totalE = 0
totalO = 0
for i in range(1, lenE+1):
        totalE += comb(lenE, i)


if p == 0:
        #偶数
        ans += 1
        for i in range(1, lenO+1):
                if i%2 == 0:
                        totalO += comb(lenO, i)
        ans += totalO + totalE + totalE*totalO
        print(int(ans))
elif p == 1:
        #奇数
        for i in range(1, lenO+1):
                if i%2 != 0:
                        totalO += comb(lenO, i)

        ans += totalO + totalO*totalE
        print(int(ans))

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb

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

odd = []
even = []

#偶奇わけ
for _a in a:
        if _a%2 == 0:
                even.append(_a)
        else:
                odd.append(_a)

lenE = len(even)
lenO = len(odd)

totalE = 0
totalO = 0
for i in range(1, lenE+1):
        totalE += comb(lenE, i)


if p == 0:
        #偶数
        ans += 1
        for i in range(1, lenO+1):
                if i%2 == 0:
                        totalO += comb(lenO, i)
        ans += totalO + totalE + totalE*totalO
        print(int(ans))
elif p == 1:
        #奇数
        for i in range(1, lenO+1):
                if i%2 != 0:
                        totalO += comb(lenO, i)

        ans += totalO*totalE
        print(int(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:
from operator import mul
from functools import reduce

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

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

Submission status: Wrong Answer

Solution code:
n,p=map(int,input().split())
l=list(map(int,input().split()))
def comb(n,r):
    if n==r or r==0:
        return 1
    t=1
    for i in range(n-r,n+1):
        t*=i
    for i in range(1,r+1):
        t=t//i
    return t
g=0
k=0
for i in l:
    if i%2==0:
        g+=1
    else:
        k+=1
if p==0:
    h=k//2
    ans=0
    for i in range(0,h+1):
        ans+=comb(k,2*i)
    print(ans*(2**g))
else:
    h=(k+1)//2
    ans=0
    for i in range(h):
        ans+=comb(k,2*i+1)
    print(ans*(2**g))