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:
# -*- coding: utf-8 -*-


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

    for ai in a:
        if ai % 2 == 1:
            odd_count += 1

    j = 0

    if (p == 1) and (odd_count == 0):
        j = 0
    else:
        j = 2 ** (odd_count - 1)

    print(j * (2 ** (n - odd_count)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    from math import ceil

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

    for ai in a:
        if ai % 2 == 1:
            odd_count += 1

    j = 0

    if p == 0:
        j = 2 ** (ceil(odd_count / 2))
    else:
        if odd_count == 0:
            j = 0
        else:
            j = 2 ** (odd_count - 1)

    print(j * (2 ** (n - odd_count)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    from math import ceil

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

    for ai in a:
        if ai % 2 == 1:
            odd_count += 1

    j = 0

    if p == 0:
        j = 2 ** (ceil(odd_count / 2))
    else:
        if odd_count == 0:
            j = 0
        elif odd_count % 2 == 0:
            j = 2 ** (odd_count - 1)
        else:
            j = 2 ** odd_count

    print(j * (2 ** (n - odd_count)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# A - Biscuits
# https://beta.atcoder.jp/contests/agc017/tasks/agc017_a

# A_Biscuits.py

import math

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

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

even_combi = 2 ** even

odd_combi = 0
m = int(odd/2)
#print("m:", m)
for i in range(m+1):
    if P == 0:
        odd_combi += math.factorial(odd) / (math.factorial(i*2) * math.factorial(odd-i*2))
    else:
        if odd-(i*2+1) > 0:
            odd_combi += math.factorial(odd) / (math.factorial(i*2+1) * math.factorial(odd-(i*2+1)))

#print(even_combi, odd_combi)
print(even_combi*odd_combi)

Submission status: Wrong Answer

Solution code:
N,P = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
B = [1,0]
for _ in range(N):
    a = A.pop()%2
    p,q = B
    B = [p+q,q+p] 
print(B[P])

Submission status: Wrong Answer

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

P = [1]
for i in range(1, 51):
    P.append(P[-1] * i)

def C(n, m):
    return P[n] // P[n - m] // P[m]

odd = sum(x % 2 for x in A)
even = N - odd

r = 0
for i in range(0, odd + 1, 2):
    r += C(odd, i) * (2**even)

if P == 1:
    r = N - r

print(r)

Submission status: Wrong Answer

Solution code:
from math import factorial
N, P = map(int, input().split(' '))
biscuits = list(map(int, input().split(' ')))
bis_odd = len([i for i in biscuits if i % 2 != 0])
bis_even = len([i for i in biscuits if i % 2 == 0])
res = 0
if P == 0:
    res += bis_odd * (bis_odd - 1) // 2 + 1
    for i in range(1, bis_even + 1):
        res += factorial(bis_even) // (factorial(bis_even - i) * factorial(i))
else:
    sum_odd = 0
    odd_max = (bis_odd % 2 + bis_odd // 2) * 2 - 1
    for i in range(1, odd_max + 1, 2):
        sum_odd += factorial(bis_odd) // (factorial(bis_odd - i) * factorial(i))
    for i in range(1, bis_even + 1):
        res += sum_odd * factorial(bis_even) // (factorial(bis_even - i) * factorial(i))
    res += sum_odd
print(res)

Submission status: Wrong Answer

Solution code:
N,P=map(int,input().split())
N=list(input().split())
for i in range (len(N)):
    N[i]=int(N[i])%2
count1=N.count(1)
count0=N.count(0)
import math
count0_c=0
count1_c=0
if count0!=0:
    for k in range (0,count0+1):
        count0_c+=math.factorial(count0)/(math.factorial(k)*math.factorial(count0-k))
else:
    count0_c=1

if count1!=0:
    for j in range (0,count1//2+1-P):
        count1_c+=math.factorial(count1)/(math.factorial(2*j+P)*math.factorial(count1-2*j-P))
else:
    count1_c=1
print(int(count0_c*count1_c))

Submission status: Wrong Answer

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

    editorial(N, P, A)

def editorial(N, P, A):
    odds = [a for a in A if a % 2 == 1]
    odd = len(odds)
    even = N - odd

    if P == 1 and odd == 0:
        print(0)
        return
    
    # ある奇数袋を取り除いて、残りでの組み合わせ(選ぶ選ばないの2通りがN-1)
    ans = 2 ** (N - 1)
    # s = 組み合わせのビスケット枚数
    # P=0,s:奇数であるとき、加えるのは1通り
    # P=0,s:奇数でないとき、加えないのは1通り
    # P=1,s:奇数であるとき、加えないのは１通り
    # P=1,s:奇数でないとき、加えるのは1通り
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
lis = list(map(int,input().split()))
cou = 0
co = 0
for i in range(n):
    if lis[i] % 2 == 0:cou += 1
    else:co += 1
if ((2 ** cou)*(2 ** co))//2 == 1:
    print("0")
else:
    print(((2 ** cou)*(2 ** co))//2)

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
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
m = 0
if P == 0:
    for i in range(0,odd+1,2):
        m += int(comb(odd,i))
else:
    for i in range(1,odd+1,2):
        m += int(comb(odd,i))

print(m*(2**even))

Submission status: Wrong Answer

Solution code:
def cmb(n, k):
  s = 1
  for j in range(1, n - k + 1):
    s *= j
  for j in range(1, k+1):
    s //= j
  return s

n, p = map(int, input().split())
aa = list(map(lambda x: int(x) % 2, input().split()))
odd = sum(aa)
even = n - odd
if p == 0:
  c = 2**even * sum(cmb(odd, k) for k in range(0, odd+1, 2))
  print(c)
else:
  c = 2**even * sum(cmb(odd, k) for k in range(1, odd+1, 2))
  print(c)

Submission status: Wrong Answer

Solution code:
def cmb(n, k):
  s = 1
  for j in range(n - k):
    s *= j
  for j in range(1, k+1):
    s //= j
  return s

n, p = map(int, input().split())
aa = list(map(lambda x: int(x) % 2, input().split()))
odd = sum(aa)
even = n - odd
if p == 0:
  c = 2**even * sum(cmb(odd, k) for k in range(0, odd+1, 2))
  print(c)
else:
  c = 2**even * sum(cmb(odd, k) for k in range(1, odd+1, 2))
  print(c)

Submission status: Wrong Answer

Solution code:
n, p = map(int, input().split())
a = list(map(lambda x: x % 2, map(int, input().split())))
e=a.count(0)

ans=2**(n-1)
if p==1 and e==n:
    ans=0
if p==0 and e==0:
    ans=2**n
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

N, P = [int(i) for i in input().split()]
biscuits = [int(i) for i in input().split()]
even = 0
odd = 0
buffer_count = 1

for i in biscuits:
    if i % 2 == 0:
        even += 1
    elif i % 2 == 1:
        odd += 1

if P == 0:
    # even
    answer = 1
    if even >= odd:
        for i in range(1, even+1):
            answer += 2 ** (i-1)
            if i == odd:
                buffer_count = answer
    elif odd > even:
        for i in range(1, odd+1):
            buffer_count += 2 ** (i-1)
            if i == even:
                answer = buffer_count
    if buffer_count > 2:
        answer += (buffer_count / 2) - 1
    print(int(answer))
elif P == 1:
    # odd
    answer = 0
    even_c = 1
    odd_c = 0
    if even > odd:
        for i in range(1, even+1):
            even_c += 2 ** (i-1)
            if i == odd:
                buffer_count = even_c
    elif odd >= even:
        for i in range(1, odd+1):
            buffer_count += 2 ** (i-1)
            if i == even:
                even_c = buffer_count
    if buffer_count > 1:
        odd_c = (buffer_count / 2)
    print(int(even_c * odd_c))

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import math
import scipy.misc as scm

N, P = map(int, input().split())
A = map(int, input().split())
sum_A = 0
odd_count = 0
even_count = 0

for a in A:
    if a % 2 == 1:
        odd_count += 1
        sum_A += a
    else:
        even_count += 1
        sum_A += a

def getOddCombinationWithP(count, P):
    result = 0
    for i in range(0, count + 1):
        if i % 2 == 0 and P == 0:
            result += scm.comb(count, i)
        elif i % 2 == 1 and P == 1:
            result += scm.comb(count, i)

    return result


if odd_count == 0:
    if P == 1 and sum_A % 2 == 0:
        print(0)
        exit()
    elif P == 0 and sum_A % 2 == 1:
        print(0)
        exit()


print(int(math.pow(2, even_count) * getOddCombinationWithP(odd_count, P)))

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import math
import scipy.misc as scm

N, P = map(int, input().split())
A = map(int, input().split())
sum_A = 0
odd_count = 0
even_count = 0

for a in A:
    if a % 2 == 1:
        odd_count += 1
        sum_A += a
    elif a != 0:
        even_count += 1
        sum_A += a


def getOddCombinationWithP(count, P):
    result = 0
    for i in range(0, count + 1):
        if i % 2 == 0 and P == 0:
            result += scm.comb(count, i)
        elif i % 2 == 1 and P == 1:
            result += scm.comb(count, i)

    return result


if odd_count == 0:
    if P == 1 and sum_A % 2 == 0:
        print(0)
        exit()
    elif P == 0 and sum_A % 2 == 1:
        print(0)
        exit()


print(int(math.pow(2, even_count) * getOddCombinationWithP(odd_count, P)))

Submission status: Wrong Answer

Solution code:
import itertools

N, P = [int(i) for i in input().split()]
biscuits = [int(i) for i in input().split()]
even = []
odd = []

for i in biscuits:
    if i % 2 == 0:
        even.append(i)
    elif i % 2 == 1:
        odd.append(i)

if P == 0:
    # even
    answer = 1
    for i in range(1, len(even)+1):
        c = list(itertools.combinations(even,i))
        answer += len(c)
    for i in range(2, len(odd)+1, 2):
        c = list(itertools.combinations(odd,i))
        answer += len(c)
    print(answer)
elif P == 1:
    # odd
    answer = 0
    even_c = 1
    odd_c = 0
    for i in range(1, len(even)+1):
        c = list(itertools.combinations(even,i))
        even_c += len(c)
    for i in range(1, len(odd)+1, 2):
        c = list(itertools.combinations(odd,i))
        odd_c += len(c)
    if odd_c == 0:
        odd_c = 1
    print(even_c * odd_c)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import itertools
import math

n, p = map(int, input().split())
alist = map(int, input().split())

d = Counter()
for a in alist:
    d[a % 2] += 1

# print(d)

zeros = 2 ** d[0]


ones = 0
if p == 0:
    for i in range(d[1]):
        if i % 2 == 0:
            ones += math.factorial(d[1]) // (math.factorial(d[1] - i) * math.factorial(i))
        # print(i)
        # print(ones)
else:
    for i in range(d[1]):
        if i % 2 == 1:
            ones += math.factorial(d[1]) // (math.factorial(d[1] - i) * math.factorial(i))
        # print(i)
        # print(ones)

# print(zeros)
# print(ones)

print(zeros * ones)

Submission status: Wrong Answer

Solution code:
input1 = list(map(int,input("").split(" ")))
A = list(map(int,input("").split(" ")))
N = input1[0]
P = input1[1]

even = []
odd = []
for a in A:
	if a % 2 == 0:
		even.append(a)
	else:
		odd.append(a)

result = 2**len(even) * 2**(len(odd)-1)
print(result)

Submission status: Wrong Answer

Solution code:
input1s = input()
input2s = input()

input1 = [int(i) for i in input1s.split(' ')]
N = input1[0]
P = input1[1]
array = [int(i) for i in input2s.split(' ')]

count = 0
if(P == 0): count += 1 # P==0でそもそも一個も選ばない組合せ

for i in range(len(array)):
  for j in range(1,len(array)-i):
    # print (j)
    if((array[i]+array[i+j])%2 == P):
      count += 1
      # print ("count = "+str(count))

# print ("===========")
print (count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n_even = len(list(filter(lambda x: x % 2 == 0, A)))
n_odd = N - n_even
ans = 2 ** max(0, n_odd - 1) * 2 ** n_even
if P == 0 and n_odd == 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

if all(filter(lambda x: x % 2 == 0, A)):
    if P == 0:
        print(0)
    else:
        print(2 ** N)
else:
    n_even = sum(filter(lambda x: x % 2 == 0, A))
    n_odd = N - n_even
    print(2 ** max(0, n_odd - 1) * 2 ** n_even)

Submission status: Wrong Answer

Solution code:
import itertools

n, p = tuple(input().split(' '))
n = int(n)
p = int(p)

biscuits = [int(num) for num in input().split(' ')]
even = [num for num in biscuits if num % 2 == 0]
odd = [num for num in biscuits if num % 2 == 1]

comb_e = [len(list(itertools.combinations(even, i))) for i in range(0, len(even) + 1)]
comb_o = [len(list(itertools.combinations(odd, i))) for i in range(0, len(odd) + 1)]

sum = 0
if p == 0:
    for i in range(0, len(comb_e)):
        for j in range(0, len(comb_o), 2):
            sum += comb_e[i] * comb_o[j]
else:
    for i in range(0, len(comb_o)):
        for j in range(0, len(comb_e), 2):
            sum += comb_o[i] * comb_e[j]
print(sum)

Submission status: Wrong Answer

Solution code:
import math
def comb(n,r):
  return int(math.factorial(n)/(math.factorial(r)*math.factorial(n-r)))

N,P=map(int,input().split())
A=list(map(int,input().split()))
odd=0
even=0
total=0
for i in range(N):
  total+=A[i]
  if A[i]%2==0:
    even+=1
  else: 
    odd+=1
total=total%2
evens=2**even

ans=0
if total==even%2:
  for i in range(int((odd)/2+1)): 
    ans+=comb(odd,2*i)
else:
  for i in range(int((odd-1)/2)):
    ans+=comb(odd,2*i+1)
print(ans*evens)

Submission status: Wrong Answer

Solution code:
import math
def comb(n,r):
  return int(math.factorial(n)/(math.factorial(r)*math.factorial(n-r)))

N,P=map(int,input().split())
A=list(map(int,input().split()))
odd=0
even=0
total=0
for i in range(N):
  total+=A[i]
  if A[i]%2==0:
    even+=1
  else: 
    odd+=1
total=total%2
evens=2**even

ans=0
if total==even%2:
  for i in range(int((odd)/2+1)): 
    ans+=comb(odd,2*i)
else:
  for i in range(int((odd-1)/2+1)):
    ans+=comb(odd,2*i+1)
print(ans*evens)

Submission status: Wrong Answer

Solution code:
import math
def comb(n,r):
  return int(math.factorial(n)/(math.factorial(r)*math.factorial(n-r)))

N,P=map(int,input().split())
A=list(map(int,input().split()))
odd=0
even=0
total=0
for i in range(N):
  total+=A[i]
  if A[i]%2==0:
    even+=1
  else: 
    odd+=1
total=total%2
evens=2**even

ans=0
if total==even%2:
  for i in range(int((odd)/2+1)): 
    ans+=comb(odd,2*i)
else:
  for i in range(int((odd+1)/2)):
    ans+=comb(odd,2*i+1)
print(ans*evens)

Submission status: Wrong Answer

Solution code:
import math
def comb(n,r):
  return int(math.factorial(n)/(math.factorial(r)*math.factorial(n-r)))

N,P=map(int,input().split())
A=list(map(int,input().split()))
odd=0
even=0
total=0
for i in range(N):
  total+=A[i]
  if A[i]%2==0:
    even+=1
  else: 
    odd+=1
total=total%2
evens=2**even

ans=0
if total==even%2:
  for i in range(int((odd+1)/2)): 
    ans+=comb(odd,2*i)
else:
  for i in range(int((odd+1)/2)):
    ans+=comb(odd,2*i+1)
print(ans*evens)

Submission status: Wrong Answer

Solution code:
import math
def comb(n,r):
  return int(math.factorial(n)/(math.factorial(r)*math.factorial(n-r)))

N,P=map(int,input().split())
A=list(map(int,input().split()))
odd=0
even=0
total=0
for i in range(N):
  total+=A[i]
  if A[i]%2==0:
    even+=1
  else: 
    odd+=1
total=total%2
evens=2**even

ans=0
if total==even%2:
  for i in range(int((odd+1)/2)): 
    ans+=comb(odd,2*i)
    print(comb(odd,2*i))
else:
  for i in range(int((odd+1)/2)):
    ans+=comb(odd,2*i+1)
    print(comb(odd,2*i+1))
print(ans*evens)

Submission status: Wrong Answer

Solution code:
n, a = list(map(int, input().strip().split(' ')))
d = list(map(int, input().strip().split(' ')))

odd = sum([1 for i in d if i%2==0])
even  = sum([1 for i in d if i%2==1])
if even == 0 and a == 1:
    print(0)
else:
    print((2**odd) * (2**(even-1)))

Submission status: Wrong Answer

Solution code:
import math

def C(n, r):
    if (n == r or r == 0):
        return 1
    if (r > n):
        return 0

    ret = math.factorial(n) / math.factorial(r) / math.factorial(n - r)
    return int(ret)


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

odd = even = 0
ans = 0

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

for i in range(n + 1):
    for j in range(i + 1):
        if (p == 1 and j % 2 == 1) or(p == 0 and j % 2 == 0):
            ans += C(even, i - j) * C(odd, j)

print(ans)

Submission status: Wrong Answer

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

for a in A:
    if a%2==0:
        l0 +=1
    else:
        l1 +=1

if P==1 and l1==0:
    print(0)
elif P==0 and l1==0:
    print(2**l1)
else:
    print(2**(l1-1+l0))

Submission status: Wrong Answer

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

for a in A:
    if a%2==0:
        l0 +=1
    else:
        l1 +=1

if P==1 and l1==0:
    print(0)
else:
    print(2**(l1-1+l0))

Submission status: Wrong Answer

Solution code:
import math

def main():
    N, P = map(int, input().split())
    A = tuple(map(int, input().split()))

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

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

    print(ans)

main()

Submission status: Wrong Answer

Solution code:
n,p=map(int,raw_input().split())
N=map(int,raw_input().split())
e=o=0
for i in N:
	if i%2==0:
		e+=1
	else:
		o+=1
if p==1:
	if o==0:
		print 0
		exit(0)
if p==0:
	if e==0 and n==1:
		print 0
		exit(0)
print 2**(o+e-1)

Submission status: Wrong Answer

Solution code:
n,p=map(int,raw_input().split())
N=map(int,raw_input().split())
e=o=0
for i in N:
	if i%2==0:
		e+=1
	else:
		o+=1
if p==1:
	if o==0:
		print 0
		exit(0)
if p==0:
	if e==0:
		print 0
		exit(0)
print 2**(o+e-1)

Submission status: Wrong Answer

Solution code:
n,p=map(int,raw_input().split())
N=map(int,raw_input().split())
e=o=0
for i in N:
	if i%2==0:
		e+=1
	else:
		o+=1
if p==1:
	if o==0:
		print 0
		exit(0)
print 2**(o+e-1)

Submission status: Wrong Answer

Solution code:
import math
import scipy
from scipy.misc import comb
n, p = map(int, input().split())
a = list(map(int, input().split()))
 
def ncr(n, r):
    return math.factorial(n) / (math.factorial(r) * (math.factorial(n - r)))
 
kisuu = 0
guusuu = 0
for i in range(n):
    if a[i] % 2 == 1:
        kisuu += 1
    else:
        guusuu += 1
 
 
pkisuu = 0
pguusuu = 0
count = 0
 
if p == 1:
    for i in range(1, kisuu, 2):
        pkisuu += scipy.misc.comb(kisuu, i)
 
if p == 0:
    for i in range(0, kisuu, 2):
        pkisuu += scipy.misc.comb(kisuu, i)

    pguusuu = 2 ** guusuu
 
count += pkisuu * pguusuu
print(int(count))

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
import itertools, math
N, P = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
odd = [ tmp for tmp in a if tmp%2 != 0]
even = [ tmp for tmp in a if tmp%2 == 0]
d = math.factorial(len(odd))
e = math.factorial(len(even))
if P == 0:
    ans += 1
    b = int(sum([ (d/math.factorial(len(odd)-tmp))/math.factorial(tmp) for tmp in range(2, len(odd)+1, 2) ]))
    #b = sum([ len(list(itertools.combinations(odd,tmp))) for tmp in range(2, len(odd)+1, 2) ])
else:
    b = int(sum([ (d/math.factorial(len(odd)-tmp))/math.factorial(tmp) for tmp in range(1, len(odd)+1, 2) ]))
    #b = sum([ len(list(itertools.combinations(odd,tmp))) for tmp in range(1, len(odd)+1, 2) ])
c = [ int((e/math.factorial(len(even)-tmp))/math.factorial(tmp)) for tmp in range(1, len(even)+1) ]
#c = [ len(list(itertools.combinations(even, tmp))) for tmp in range(1, len(even)+1) ]
factor = 0
for tmp in c:
    ans += tmp*b
    factor += tmp
else:
    if P == 0:
        ans += b+factor
    else:
        ans += b
print(ans)

Submission status: Wrong Answer

Solution code:
import math


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


def main():
    n, p = map(int, input().split())
    a = tuple(map(lambda x: int(x) % 2 == 0, input().split()))

    if n == 1 and a[0] == bool(p):
        print(0)
        return 0

    t = len(tuple(filter(lambda x: x, a)))
    f = n - t

    f_comb = 0
    for j in range(f + 1):
        f_comb += comb(f, j)

    t_comb = 0
    if p != 0:
        for i in range(t + 1):
            if i % 2 == 0:
                t_comb += comb(t, i)
    else:
        for i in range(t + 1):
            if i % 2 == 1:
                t_comb += comb(t, i)

    print(int(t_comb * f_comb))

    return 0


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math


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


def main():
    n, p = map(int, input().split())
    a = tuple(map(lambda x: int(x) % 2 == 0, input().split()))

    if n == 1 and a[0] == bool(p):
        print(0)
        return 0

    t = len(tuple(filter(lambda x: x, a)))
    f = n - t

    f_comb = 0
    for j in range(f + 1):
        f_comb += comb(f, j)

    t_comb = 0
    if p == 0:
        for i in range(t + 1):
            if i % 2 == 0:
                t_comb += comb(t, i)
    else:
        for i in range(t + 1):
            if i % 2 == 1:
                t_comb += comb(t, i)

    print(int(t_comb * f_comb))

    return 0


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
n, p = map(int, input().split())
a = list((map(int, input().split())))
ax = []
for i in a:
    ax.append(i%2)
a1 = ax.count(1)
a0 = ax.count(0)

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

foo = 0
if p == 1:
    foo += 1

for i in range(a1):
    if i % 2 != p:
        foo += c(a1, i)
bar = 2**a0
if p == 1 and a1 == 0:
    foo, bar = 0, 0

print(foo * bar)

Submission status: Wrong Answer

Solution code:
import math
import itertools
n, p = map(int, input().split())
a = list((map(int, input().split())))
ax = []
for i in a:
    ax.append(i%2)
a1 = ax.count(1)
a0 = ax.count(0)

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

foo = 1
for i in range(a1):
    if i % 2 != p:
        foo += c(a1, i)
bar = 2**a0
if p == 1 and a1 == 0:
    foo, bar = 0, 0

print(foo * bar)

Submission status: Wrong Answer

Solution code:
import math
import scipy
from scipy.misc import comb
n, p = map(int, input().split())
a = list(map(int, input().split()))

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

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


pkisuu = 0
pguusuu = 0
count = 0

if p == 1:
    for i in range(1, kisuu, 2):
        pkisuu += scipy.misc.comb(kisuu, i)

if p == 0:
    for i in range(0, kisuu + 1, 2):
        pkisuu += scipy.misc.comb(kisuu, i)

for i in range(guusuu + 1):
    pguusuu += scipy.misc.comb(i, guusuu)

count += pkisuu * pguusuu
print(int(count))

Submission status: Wrong Answer

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

odd = len([a for a in A if a % 2 == 1])

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

Submission status: Wrong Answer

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

even = []
odd = []
ans = 0

for num in a:
    if num % 2 == 0:
        even.append(num)
    else:
        odd.append(num)

even_n = 0
if len(even) != 0:
    if (len(even)-1) % 2 == 0:
        for i in range(1, len(even)//2 + 1):
            even_n += len(list(itertools.combinations(even, i)))
        even_n = even_n * 2 + 1
    else:
        for i in range(1, len(even)//2):
            t = i
            even_n += len(list(itertools.combinations(even, i)))
        even_n = even_n * 2
        even_n += len(list(itertools.combinations(even, t+1))) + 1

if p == 0:
    ans += even_n + 1
    if len(odd) > 1:
        for i in range(1, len(odd)//2+1):
            ans += len(list(itertools.combinations(odd, i)))
else:
    if len(odd) != 0:
        for i in range(1, len(odd)+1):
            if i%2 == 1:
                ans += len(list(itertools.combinations(odd, i)))
    if len(even) != 0:
        ans += ans * even_n

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import scipy
from scipy.misc import comb
n, p = map(int, input().split())
a = list(map(int, input().split()))

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

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


pkisuu = 0
pguusuu = 0
count = 0

if p == 1:
    for i in range(1, kisuu, 2):
        pkisuu += scipy.misc.comb(kisuu, i)

if p == 0:
    for i in range(0, kisuu, 2):
        pkisuu += scipy.misc.comb(kisuu, i)

for i in range(guusuu + 1):
    pguusuu += scipy.misc.comb(i, guusuu)

#if pkisuu == 0:
#    pkisuu += 1
#if pguusuu == 0:
#    pguusuu += 1

count += pkisuu * pguusuu
print(int(count))

Submission status: Wrong Answer

Solution code:
import math
import scipy
from scipy.misc import comb
n, p = map(int, input().split())
a = list(map(int, input().split()))

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

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


pkisuu = 0
pguusuu = 0
count = 0

if p == 1:
    for i in range(1, kisuu + 1, 2):
        pkisuu += scipy.misc.comb(kisuu, i)

if p == 0:
    for i in range(0, kisuu + 1, 2):
        pkisuu += scipy.misc.comb(kisuu, i)

for i in range(guusuu + 1):
    pguusuu += scipy.misc.comb(i, guusuu)

#if pkisuu == 0:
#    pkisuu += 1
#if pguusuu == 0:
#    pguusuu += 1

count += pkisuu * pguusuu
print(int(count))

Submission status: Wrong Answer

Solution code:
import math
import scipy
from scipy.misc import comb
n, p = map(int, input().split())
a = list(map(int, input().split()))

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

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


pkisuu = 0
pguusuu = 0
count = 0

if p == 1:
    for i in range(1, kisuu, 2):
        pkisuu += scipy.misc.comb(kisuu, i)
    for j in range(guusuu):
        pguusuu += scipy.misc.comb(j, guusuu)

if p == 0:
    for i in range(0, kisuu, 2):
        pkisuu += scipy.misc.comb(kisuu, i)
    for j in range(guusuu):
        pguusuu += scipy.misc.comb(j, guusuu)

if pkisuu == 0 and pguusuu != 0:
    pkisuu += 1
if pkisuu != 0 and pguusuu == 0:
    pguusuu += 1

count += pkisuu * pguusuu
print(int(count))

Submission status: Wrong Answer

Solution code:
import functools

import math

@functools.lru_cache()
def combinations(n, r):
    return math.factorial(n) / math.factorial(r) / math.factorial(n - r)


def main():
    n, p = map(int, input().split())
    a = tuple(map(lambda x: int(x) % 2, input().split()))

    if n == 1 and a[0] % 2 != p:
        print(0)
        return 0

    t = len(tuple(filter(lambda x: x == 1, a)))
    f = n - t

    count = 0

    for i in range(t + 1):
        if i % 2 == 0:
            c = 0
            for j in range(f + 1):
                c += combinations(f, j)
            count += combinations(t, i) * c

    print(int(count))

    return 0

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import scipy
from scipy.misc import comb
n, p = map(int, input().split())
a = list(map(int, input().split()))

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

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


pkisuu = 0
pguusuu = 0
count = 0

if p == 1:
    for i in range(1, kisuu, 2):
        pkisuu += scipy.misc.comb(kisuu, i)
    for j in range(guusuu):
        pguusuu += scipy.misc.comb(j, guusuu)

if p == 0:
    for i in range(0, kisuu, 2):
        pkisuu += scipy.misc.comb(kisuu, i)
    for j in range(guusuu):
        pguusuu += scipy.misc.comb(j, guusuu)

if pkisuu == 0 and pguusuu != 0:
    pkisuu += 1
if pguusuu == 0 and pkisuu != 0:
    pguusuu += 1

count += pkisuu * pguusuu
print(int(count))

Submission status: Wrong Answer

Solution code:
import math
import itertools

N,P = [int(i) for i in input().split(" ")]
A = [int(i) for i in input().split(" ")]
k = 0
for i in range(N):
    if int(A[i] % 2) == P:
        k += 1

if k == 0:
    if P == 0:
        tmp = 0
        i = 0
        while i < N-k:
            tmp += int(math.factorial(N-k)/(math.factorial(N-k-i)*math.factorial(i)))
            i += 2
        print(tmp)
    elif P == 1:
        print(0)
else:
    tmp = 0
    i = 0
    while i <= N-k:
        tmp += int(math.factorial(N-k)/(math.factorial(N-k-i)*math.factorial(i)))
        i += 2
    print(pow(2,k)*tmp)