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

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)/(math.factorial(N-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)

Submission status: Wrong Answer

Solution code:
import sys

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

a = list(map(int, input().split(" ")))

def combi(n, k):
    # if k == 0 or n == k:
        # return 1
    # c = min(k, n - k)
    a = 1
    b = 1
    for i in range(k):
        a *= i+1
        b *= n-i
    return b // a

oddcnt = 0

for i in a:
    if i % 2 == 1:
        oddcnt += 1

evencnt = n - oddcnt

if evencnt == 1 and oddcnt == 0 and p == 1:
    print(0)
    sys.exit()

evencomb = 0
for i in range(0, evencnt+1):
    evencomb += combi(evencnt, i)

oddcomb = 0
for i in range(p, oddcnt+1, 2):
    oddcomb += combi(oddcnt, i)

if evencomb != 0:
    if oddcomb != 0:
        print(evencomb * oddcomb)
    else:
        print(evencomb)
else:
    print(oddcomb)

Submission status: Wrong Answer

Solution code:
import math
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)
if p == 0:
    ans += 1
    if len(even) != 0:
        for i in range(1, len(even)+1):
            ans += len(list(itertools.combinations(even, i)))
    if len(odd) > 1:
        for i in range(1, len(odd)+1):
            if i%2 == 0:
                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)))
                print(ans)
    if len(even) != 0:
        even_n = 0
        for i in range(1, len(even)+1):
            even_n += len(list(itertools.combinations(even, i)))
        ans += ans * even_n

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

a = list(map(int, input().split(" ")))

def combi(n, k):
    # if k == 0 or n == k:
        # return 1
    # c = min(k, n - k)
    a = 1
    b = 1
    for i in range(k):
        a *= i+1
        b *= n-i
    return b // a

oddcnt = 0

for i in a:
    if i % 2 == 1:
        oddcnt += 1

evencnt = n - oddcnt

if evencnt == 1 and p == 1:
    print(0)
    sys.exit()

evencomb = 0
for i in range(0, evencnt+1):
    evencomb += combi(evencnt, i)

oddcomb = 0
for i in range(p, oddcnt+1, 2):
    oddcomb += combi(oddcnt, i)

if evencomb != 0:
    if oddcomb != 0:
        print(evencomb * oddcomb)
    else:
        print(evencomb)
else:
    print(oddcomb)

Submission status: Wrong Answer

Solution code:
import sys

def biscuit(N, P, As):
    n_even = 0
    n_odd = 0
    for a in As:
      if int(a) % 2 == 0:
        n_even += 1
      else:
        n_odd +=1
    v = 2**n_even
    print(n_even, n_odd)
    if n_odd == 0:
      v *= (0 if int(P) == 1 else 1)
    else:
      v *= 2**(n_odd -1)
    return v

N, P = sys.stdin.readline().strip().split()
As = sys.stdin.readline().strip().split()
print(biscuit(N, P, As))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
N,P = map(int,input().split())
a = [int(i) for i in input().split()] 
cnt = 0
sum = 0
kisu = []
gusu = []

for i in a:
    if i %2 == 1:
        kisu.append(i)
    else:
        gusu.append(i)

if P==0:
    ki = 2
    while ki <= len(kisu):
        temp1 = 1
        temp2 = 1
        for i in range(1,ki+1):
            temp1 *= len(kisu)-i+1
            temp2 *= i
        sum += temp1/temp2
        ki += 2
    cnt = sum
    if sum == 0:
        cnt = 1
    cnt *= 2 ** int(len(gusu))
    if len(gusu) == 0:
        cnt += 1

if P==1:
    ki = 1
    while ki <= int(len(kisu)):
        temp1 = 1
        temp2 = 1
        for i in range(1,ki+1):
            temp1 *= len(kisu)-i+1
            temp2 *= i
        sum += temp1/temp2
        ki += 2

        
    cnt = sum
    if sum == 0:
        cnt = 0
    cnt *= 2 ** int(len(gusu))
print(int(cnt))

Submission status: Wrong Answer

Solution code:
import itertools

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

a = list(map(int, input().split(" ")))

def combi(n, k):
    # if k == 0 or n == k:
        # return 1
    # c = min(k, n - k)
    a = 1
    b = 1
    for i in range(k):
        a *= i+1
        b *= n-i
    return b // a

oddcnt = 0

for i in a:
    if i % 2 == 1:
        oddcnt += 1

evencnt = n - oddcnt

evencomb = 0
for i in range(0, evencnt+1):
    evencomb += combi(evencnt, i)

oddcomb = 0
for i in range(p, oddcnt+1, 2):
    oddcomb += combi(oddcnt, i)

if evencomb != 0:
    if oddcomb != 0:
        print(evencomb * oddcomb)
    else:
        print(evencomb)
else:
    print(oddcomb)

Submission status: Wrong Answer

Solution code:
import math

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

n, p = map(int, input().split())
a_list = list(map(int, input().split()))
surplus0 = 0
surplus1 = 0
for i in a_list:
    if i % 2 == 0:
        surplus0 += 1
    else:
        surplus1 += 1

if p == 0:
    #剰余0となる袋の選び方全て
    s0 = 0
    for i in range(surplus0+1):
        s0 = math.factorial(surplus0)
    #剰余1となる袋の選び方全て
    s1 = 0
    if surplus1 == 0:
        s1 = 1
    elif surplus1 % 2 == 1:
        for i in range(surplus1//2 + 1):
            s1 += combination(surplus1, i*2)
    else:
        for i in range(surplus1//2):
            s1 += combination(surplus1, i*2)
    ans = s0 * s1
else:
    #剰余0となる袋の選び方全て
    s0 = 0
    for i in range(surplus0+1):
        s0 += combination(surplus0, i)
    #剰余1となる袋の選び方全て
    s1 = 0
    if surplus1 == 0:
        s1 = 0
    elif surplus1 % 2 == 1:
        for i in range(surplus1//2 + 1):
            s1 += combination(surplus1, i*2+1)
    else:
        for i in range(surplus1//2):
            s1 += combination(surplus1, i*2+1)
    ans = s0 * s1

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

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

n, p = map(int, input().split())
a_list = list(map(int, input().split()))
surplus0 = 0
surplus1 = 0
for i in a_list:
    if i % 2 == 0:
        surplus0 += 1
    else:
        surplus1 += 1

if p == 0:
    #剰余0となる袋の選び方全て
    s0 = 0
    for i in range(surplus0+1):
        s0 = math.factorial(surplus0)
    #剰余1となる袋の選び方全て
    s1 = 0
    if surplus1 % 2 == 1:
        for i in range(surplus1//2 + 1):
            s1 += combination(surplus1, i*2)
    else:
        for i in range(surplus1//2):
            s1 += combination(surplus1, i*2)
    ans = s0 * s1
else:
    #剰余0となる袋の選び方全て
    s0 = 0
    for i in range(surplus0+1):
        s0 += combination(surplus0, i)
    #剰余1となる袋の選び方全て
    s1 = 0
    if surplus1 == 0:
        s1 = 0
    elif surplus1 % 2 == 1:
        for i in range(surplus1//2 + 1):
            s1 += combination(surplus1, i*2+1)
    else:
        for i in range(surplus1//2):
            s1 += combination(surplus1, i*2+1)
    ans = s0 * s1

print(int(ans))

Submission status: Wrong Answer

Solution code:
n, p = (int(i) for i in input().split())
A=[int(i) for i in input().split()]
an=0

for i in range(0,n):
    A[i]=A[i]%2
one=A.count(1)
zero=A.count(0)

f=[1]
t=1
for i in range(1,max(one,zero)+3):
    t=t*i
    f.append(t)
#0
if p==0:
    if zero!=0:
        for i in range(0,zero+1):
            an+=round(f[zero]/(f[zero-i]*f[i]))

    j=0
    if one!=0:
        while j<=one:
            an+=round(f[one]/round(f[one-j]*f[j]))
            j+=2
    if one!=0 and zero!=0:
        an-=1
#1
if p==1:
    oo=0
    for i in range(0,zero+1):
        oo+=round(f[zero]/round(f[zero-i]*f[i]))
    j=1
    ll=0
    if one!=0:
        while j<=one:
            ll+=round(f[one]/round(f[one-j]*f[j]))
            j+=2
    an=oo*ll

print(an)

Submission status: Wrong Answer

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

import sys
import os
import math

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

A_temp = list(map(int, input().split()))
A = []

for a in A_temp:
    A.append(a % 2)

zero_num = A.count(0)
one_num = A.count(1)

def Combination(n, m):
    #print(str(n) + "C" + str(m))
    f = math.factorial
    return f(n) // f(m) // f(n - m)

combination_for_one = 0
if P == 0:
    for i in range(0, one_num + 1, 2):
        combination_for_one += Combination(one_num, i)
else:
    for i in range(0, one_num, 2):
        combination_for_one += Combination(one_num, i)

ans = combination_for_one * (2 ** zero_num)
print(ans)

Submission status: Wrong Answer

Solution code:
#Biscuits

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

#奇数の数
k = 0
for a in A:
    k += a%2
if ( k ==0 ):
    ans = (3-P)%2 * 2**(N-1)
else:
    ans = 2**(N-1)
print(ans)

Submission status: Wrong Answer

Solution code:
def odd(n):
    return n % 2 == 1
    
def even(n):
    return n % 2 == 0

from math import factorial as fact
def c(n, r):
    if n < r:
        return 0
    if n == 0:
        return 0
    if r == 0:
        return 1
    return fact(n) // (fact(n-r) * fact(r))

n, p = map(int, input().split())
a = list(map(int, input().split()))
o = [i for i in a if odd(i)]
e = [i for i in a if even(i)]
x = len(o)
y = len(e)
yc = 0
for i in range(y):
    yc += c(y, i + 1)
ans = 0
if p == 0:
    ans += yc
i = 2 - p
while True:
    if i > x:
        break
    ans += c(x, i)
    ans += c(x, i) * yc
    i += 2
print(ans)

Submission status: Wrong Answer

Solution code:
#Biscuits

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

#奇数の数
k = 0
for a in A:
    k += a%2
if ( k ==0 ):
    ans = (3-P)%2
else:
    ans = 2**(N-1)
print(ans)

Submission status: Wrong Answer

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

import sys
import os

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

A_temp = list(map(int, input().split()))
A = []

for a in A_temp:
    A.append(a % 2)

zero_num = A.count(0)
one_num = A.count(1)

def Permutation(n, m):
    ret = 1
    for i in range(m):
        ret *= (n - i)
    return ret

def Combination(n, m):
    #import itertools
    #lst = [1] * n
    #c = list(itertools.combinations(lst, m))
    #return len(c)
    return Permutation(n, m) // Permutation(m, m)

combination_for_one = 0
if P == 0:
    for i in range(2, one_num + 1, 2):
        combination_for_one += Combination(one_num, i)
    combination_for_one += 1
else:
    for i in range(0, one_num, 2):
        combination_for_one += Combination(one_num, i)

ans = combination_for_one * (2 ** zero_num)

print(ans)

Submission status: Wrong Answer

Solution code:
#Biscuits

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

#奇数の数
k = 0
for a in A:
    if a%2 ==1:
        k+=1

if ( k ==0 ):
    ans = (3-P)%2
else:
    ans = 2**(N-1)
print(ans)

Submission status: Wrong Answer

Solution code:
def odd(n):
    return n % 2 == 1
    
def even(n):
    return n % 2 == 0

from math import factorial as fact
def c(n, r):
    if n < r:
        return 0
    if n == 0:
        return 0
    if r == 0:
        return 1
    return fact(n) // (fact(n-r) * fact(r))

n, p = map(int, input().split())
a = list(map(int, input().split()))
o = [i for i in a if odd(i)]
e = [i for i in a if even(i)]
x = len(o)
y = len(e)
yc = 0
for i in range(y):
    yc += c(y, i + 1)
ans = 0
if p == 0:
    ans += 1
i = 2 - p
while True:
    ans += c(x, i)
    ans += c(x, i) * yc
    i += 2
    if i > x:
        break
if x == 0:
    ans += yc
print(ans)

Submission status: Wrong Answer

Solution code:
def spaceinput():
    return list(map(int,input().split(" ")))

N,P=list(map(int,input().split(" ")))
a=spaceinput()

dp=[[0,0] for i in range(N)]

if a[0]%2==0:
    dp[0][0]=1
    dp[0][1]=0
else:
    dp[0][0]=1
    dp[0][1]=1


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


print(dp[N-1][P])

Submission status: Wrong Answer

Solution code:
import math

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

n, p = map(int, input().split())
a_list = list(map(int, input().split()))
surplus0 = 0
surplus1 = 0
for i in a_list:
    if i % 2 == 0:
        surplus0 += 1
    else:
        surplus1 += 1

if p == 0:
    #剰余0となる袋の選び方全て
    s0 = 0
    for i in range(surplus0+1):
        s0 = math.factorial(surplus0)
    #剰余1となる袋の選び方全て
    s1 = 0
    for i in range(surplus1//2 + 1):
        s1 += combination(surplus1, i*2)
    ans = s0 * s1
else:
    #剰余0となる袋の選び方全て
    s0 = 0
    for i in range(surplus0+1):
        s0 += combination(surplus0, i)
    #剰余1となる袋の選び方全て
    s1 = 0
    if surplus1 == 0:
        s1 = 0
    elif surplus1 % 2 == 1:
        for i in range(surplus1//2 + 1):
            s1 += combination(surplus1, i*2+1)
    else:
        for i in range(surplus1//2):
            s1 += combination(surplus1, i*2+1)
    ans = s0 * s1

print(int(ans))

Submission status: Wrong Answer

Solution code:
n, p = (int(i) for i in input().split())
A=[int(i) for i in input().split()]
an=0

for i in range(0,n):
    A[i]=A[i]%2
one=A.count(1)
zero=A.count(0)

f=[1]
t=1
for i in range(1,max(one,zero)+1):
    t=t*i
    f.append(t)
#0
if p==0:
    if zero!=0:
        for i in range(0,zero+1):
            an+=round(f[zero]/(f[zero-i]*f[i]))

    j=0
    if one!=0:
        while j<=one:
            an+=round(f[one]/(f[one-j]*f[j]))
            j+=2
    if one!=0 and zero!=0:
        an-=1
#1
if p==1:
    oo=0
    if zero!=0:
        for i in range(0,zero+1):
            oo+=round(f[zero]/(f[zero-i]*f[i]))
    else:
        oo=1
    j=1
    ll=0
    if one!=0:
        while j<=one:
            ll+=round(f[one]/(f[one-j]*f[j]))
            j+=2
    an=oo*ll

print(an)

Submission status: Wrong Answer

Solution code:
import scipy.misc as scm


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

evens = len(list(filter(lambda x: x == True, A)))
odds = len(A) - evens

if P == 0:
    evens_x = pow(2, evens)
    odds_x = 0
 
    for i in range(0, odds + 1, 2):
        odds_x += scm.comb(odds, i)
    
else:
    evens_x = pow(2, evens)
    odds_x = 0

    for i in range(1, odds + 1, 2):
        odds_x += scm.comb(odds, i)
    
print(int(evens_x * odds_x))

Submission status: Wrong Answer

Solution code:
def odd(n):
    return n % 2 == 1
    
def even(n):
    return n % 2 == 0

from math import factorial as fact
def c(n, r):
    if n < r:
        return 0
    if n == 0:
        return 0
    if r == 0:
        return 1
    return fact(n) // (fact(n-r) * fact(r))

n, p = map(int, input().split())
a = list(map(int, input().split()))
o = [i for i in a if odd(i)]
e = [i for i in a if even(i)]
x = len(o)
y = len(e)
yc = 0
for i in range(y):
    yc += c(y, i + 1)
ans = 0
if p == 0:
    ans += 1
i = 2 - p
while True:
    ans += c(x, i)
    ans += c(x, i) * yc
    i += 2
    if i > x:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
# your code goes here
N,P=(int(i) for i in input (). split ())
A=[int (i) for i in input(). split ()]
od=0
ev=0
for i in range (N):
    if A[i]%2==1:
        od+=1
    else:
        ev+=1
if P==0:
    r=1
    for i in range (N-1):
        r*=2
else:
    if od==0:
        r=0
    else:
        r=1
        for i in range (od-1):
            r*=2
print (r)

Submission status: Wrong Answer

Solution code:
#Biscuits

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


#偶数と奇数の数
gusu = 0
for a in A:
    if a%2 ==0:
        gusu += 1

ans = int((2**gusu) * ( 2**(N-gusu-1) ))
print(ans)

Submission status: Wrong Answer

Solution code:
def odd(n):
    return n % 2 == 1
    
def even(n):
    return n % 2 == 0

from math import factorial as fact
def c(n, r):
    if n == 0:
        return 0
    return fact(n) // (fact(n-r) * fact(r))

n, p = map(int, input().split())
a = list(map(int, input().split()))
o = [i for i in a if odd(i)]
e = [i for i in a if even(i)]
x = len(o)
y = len(e)
yc = 0
for i in range(y):
    yc += c(y, i + 1)
ans = 0
if p == 0:
    ans += 1
i = 2 - p
while True:
    ans += c(x, i)
    ans += c(x, i) * yc
    i += 2
    if i > x:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import scipy.misc as scm
import sys

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

evens = len(list(filter(lambda x: x == True, A)))
odds = len(A) - evens

if P == 0:
    evens_x = int(pow(2, evens))
    odds_x = 0
    
    for i in range(0, odds + 1, 2):
        odds_x += int(scm.comb(odds, i))

    print(evens_x * odds_x)
    
else:
    evens_x = int(pow(2, evens))
    odds_x = 0

    for i in range(1, odds + 1, 2):
        odds_x += int(scm.comb(odds, i))

    print(evens_x * odds_x)

Submission status: Wrong Answer

Solution code:
def main():
  N,P = map(int,input().split())
  n0 = 0
  n1 = 0
  for a in map(int,input().split()):
    if a%2 == 0:
      n0 += 1
    else:
      n1 += 1
  if P == 1 and n1 == 0:
    print(0)
    return
  print(2**(n0+n1-1))

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, p = (int(i) for i in input().split())
A=[int(i) for i in input().split()]
an=0

for i in range(0,n):
    A[i]=A[i]%2
one=A.count(1)
zero=A.count(0)

f=[1]
t=1
for i in range(1,max(one,zero)+1):
    t=t*i
    f.append(t)
#0
if p==0:
    if zero!=0:
        for i in range(0,zero+1):
            an+=round(f[zero]/(f[zero-i]*f[i]))
    j=0
    if one!=0:
        while j<=one:
            an+=round(f[one]/(f[one-j]*f[j]))
            j+=2
#1
if p==1:
    oo=0
    if zero!=0:
        for i in range(0,zero+1):
            oo+=round(f[zero]/(f[zero-i]*f[i]))
    else:
        oo=1
    j=1
    ll=0
    if one!=0:
        while j<=one:
            ll+=round(f[one]/(f[one-j]*f[j]))
            j+=2
    an=oo*ll

print(an)

Submission status: Wrong Answer

Solution code:
def spaceinput():
    return list(map(int,input().split(" ")))

N,P=list(map(int,input().split(" ")))
a=spaceinput()

dp=[[0,0] for i in range(N)]

if a[0]%2==0:
    dp[0][0]=1
    dp[0][1]=0
else:
    dp[0][0]=1
    dp[0][1]=1


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


print(dp[-1][P])

Submission status: Wrong Answer

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

import sys
import os

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

A_temp = list(map(int, input().split()))
A = []

for a in A_temp:
    A.append(a % 2)

zero_num = A.count(0)
one_num = A.count(1)

def P(n, m):
    ret = 1
    for i in range(m):
        ret *= (n - i)
    return ret

def C(n, m):
    #import itertools
    #lst = [1] * n
    #c = list(itertools.combinations(lst, m))
    #return len(c)
    return P(n, m) // P(m, m)

combination_for_one = 0
for i in range(1, one_num, 2):
    combination_for_one += C(one_num, i)

ans = combination_for_one * (2 ** zero_num)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

even = list(filter(lambda x: x%2 == 0, a))
odd = list(filter(lambda x: x%2, a))

fact = [0]
r = 1
for i in range(1, 100):
    r *= i
    fact.append(r)

def c(a, b):
    if a == b: return 1
    return fact[a] / (fact[a - b] * fact[b])
if p == 0:
    e = 2**len(even)
    r = 0
    for i in range(2, len(odd) + 1, 2):
        r += c(len(odd), i)
    print(int(r * e + 1))

if p == 1:
    e = 2**len(even)
    r = 0
    for i in range(1, len(odd) + 1, 2):
        r += c(len(odd), i)
    print(int(r * e))

Submission status: Wrong Answer

Solution code:
N,mod=map(int,raw_input().split())
packs=map(int,raw_input().split())
odd=0
even=0

def nCk(n,k):
    result=1
    for i in range(n-k+1,n+1):
        result*=i
    for i in range(1,k+1):
        result/=i
    return result

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

base=(2**even)
result=0
if N%2==1:
    for i in range(1,odd+1,2):
        result+=base*nCk(odd,i)
elif N%2==0:
    for i in range(0,odd+1,2):
        result+=base*nCk(odd,i)
print result

Submission status: Wrong Answer

Solution code:
def spaceinput():
    return list(map(int,input().split(" ")))

N,P=list(map(int,input().split(" ")))
a=spaceinput()

dp=[[0,0] for i in range(N)]

if a[0]%2==0:
    dp[0][0]=1
    dp[0][1]=0
else:
    dp[0][0]=1
    dp[0][1]=1


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


print(dp[-1][P])

Submission status: Wrong Answer

Solution code:
n, p = (int(i) for i in input().split())
A=[int(i) for i in input().split()]
an=0

for i in range(0,n):
    A[i]=A[i]%2
one=A.count(1)
zero=A.count(0)

f=[1]
t=1
for i in range(1,max(one,zero)+1):
    t=t*i
    f.append(t)
#0
if p==0:
    if zero!=0:
        for i in range(0,zero+1):
            an+=round(f[zero]/(f[zero-i]*f[i]))
    j=0
    if one!=0:
        while j<=one:
            an+=round(f[one]/(f[one-j]*f[j]))
            j+=2
#1
if p==1:
    oo=0
    if zero!=0:
        for i in range(0,zero+1):
            oo+=round(f[zero]/(f[zero-i]*f[i]))
    j=1
    ll=0
    if one!=0:
        while j<=one:
            ll+=round(f[one]/(f[one-j]*f[j]))
            j+=2
    an=oo*ll

print(an)

Submission status: Wrong Answer

Solution code:
n,p = map(int,input().split())
a=[]
a=map(int,input().split())
c=[([0]*(n+2)) for i in range(n+2)]
for i in range(1,n+1):
	c[i][0]=c[i][i]=1
	for j in range(1,i):
		c[i][j]=c[i-1][j-1]+c[i-1][j]

s0=0;s1=0
for x in a:
	if (x%2==1):
		s1+=1
	else:
		s0+=1
ans=0

for i in range(p,s1+1,2):
	ans+=c[s1][i]*(2**s0)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def biscuit(N, P, As):
    n_even = 0
    n_odd = 0
    for a in As:
      if int(a)/2 == 0:
        n_even += 1
      else:
        n_odd +=1
    v = 2**n_even
    if n_odd == 0:
      v *= (0 if int(P) == 1 else 1)
    else:
      v *= 2**(n_odd -1)
    return v

N, P = sys.stdin.readline().strip().split()
As = sys.stdin.readline().strip().split()
print(biscuit(N, P, As))

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.misc as scm
hoge = input()
hoge = list(map(int,hoge.split(" ")))
N = hoge[0]
P = hoge[1]
A = input()
A = list(map(int,A.split(" ")))
A = np.array(A)
odd = len(A[A %2 == 1])
even = N -odd
perm = 0
if P == 0:
    for i in range(0,odd,2):
        perm +=scm.comb(odd,i,1)
else:
    for i in range(1,odd,2):
            perm +=scm.comb(odd,i,1)
ans = 2**even * perm
print(ans)

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)
else:
    print(2 ** (N- 1))

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.misc as scm
hoge = input()
hoge = list(map(int,hoge.split(" ")))
N = hoge[0]
P = hoge[1]
A = input()
A = list(map(int,A.split(" ")))
A = np.array(A)
odd = len(A[A %2 == 1])
even = N -odd
perm = 0
if P == 0:
    for i in range(0,odd,2):
        perm +=scm.comb(odd,i,1)
else:
    for i in range(1,odd,2):
            print(i)
            perm +=scm.comb(odd,i,1)
ans = 2**even * perm
print(ans)

Submission status: Wrong Answer

Solution code:
n,p = map(int,input().split())
a=[]
a=map(int,input().split())
c=[([0]*(n+1)) for i in range(n+1)]
for i in range(1,n+1):
	c[i][0]=c[i][i]=1
	for j in range(1,i):
		c[i][j]=c[i-1][j-1]+c[i-1][j]

s0=0;s1=0
for x in a:
	if (x%2==1):
		s1+=1
	else:
		s0+=1
ans=0

for i in range(p,s1+1,2):
	ans+=c[s1][i]*(2**s0)
print(ans)

Submission status: Wrong Answer

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

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

def f(n,r):
    res= 1
    for i in range(n-r+1 ,n+1):
        res *=  i
    for i in range(1,r+1):
        res //=i
    #print(n,r,res)
    return int(res)



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

even = N-odd

if P==1:
    if odd==0:
        print(0)
        exit()
    ans = 2**even
    tmp = 0
    for i in range(1, odd + 1, 2):
        tmp += f(odd, i)
        print(tmp)
    print(ans * tmp)
else:
    ans = 2 ** even
    tmp=0
    for i in range(0, odd+1, 2):
        tmp += f(odd, i)
        #print(tmp)
    print(ans*tmp)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3
import itertools
import math
N, P = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
for i in A:
    if i % 2 : cnt += 1
_cnt = len(A) - cnt
if P == 0:
    print(2 ** _cnt + 2 ** (cnt - 1) - 1)
else:
    a = 0
    for i in range(1, cnt + 1, 2):
        a += (math.factorial(cnt) // math.factorial(cnt-i)) // math.factorial(i)
    print(2 ** _cnt * a)

Submission status: Wrong Answer

Solution code:
n,p = map(int,input().split())
a=[]
a=map(int,input().split())
c=[([0]*(n+1)) for i in range(n+1)]
for i in range(1,n+1):
	c[i][0]=c[i][i]=1
	for j in range(1,i):
		c[i][j]=c[i-1][j-1]+c[i-1][j]

s0=0;s1=0
for x in a:
	if (x%2==1):
		s1+=1
	else:
		s0+=1
ans=0

for i in range(p,s1,2):
	ans+=c[s1][i]*(2**s0)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
N, P = input().split()
A = list(map(int, input().split()))
if int(P) == 0:
    ans = 1
else:
    ans = 0
for i in itertools.combinations(A, 2):
    if sum(i)%2 == int(P):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N, P = sys.stdin.readline().strip().split()
As = sys.stdin.readline().strip().split()
n_even = 0
n_odd = 0
for a in As:
  if int(a)/2 == 0:
    n_even += 1
  else:
    n_odd +=1
v = 2**n_even
if n_odd == 0:
  v *= (0 if P == 1 else 1)
else:
  v *= 2**(n_odd -1)
print(v)

Submission status: Wrong Answer

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

for i in itertools.combinations(A, 2):
    if sum(i)%2 == int(P):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,p = map(int,input().split())
a=[]
a=map(int,input().split())
c=[([0]*(n+1)) for i in range(n+1)]
for i in range(1,n):
	c[i][0]=c[i][i]=1
	for j in range(1,i):
		c[i][j]=c[i-1][j-1]+c[i-1][j]

s0=0;s1=0
for x in a:
	if (x%2==1):
		s1+=1
	else:
		s0+=1
ans=0
for i in range(p,s1,2):
	ans+=c[s1][i]*(2**s0)
print(ans)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import math

def main():
	N, P = list(map(int, input().split()))
	biscuits = list(map(int, input().split()))

	n_odd = sum([x % 2 for x in biscuits])
	n_even = N - n_odd

	out = calcNPtrn_odd(n_odd, P) * calcNPtrn_even(n_even)
	print(out)
	
def calcComb(n, m):
	return(math.factorial(n)/math.factorial(m)/math.factorial(n-m))

def calcNPtrn_odd(n, is_odd):
	if n == 0:
		if is_odd == 1:
			return(0)
		else:
			return(1)

	count = 0
	if is_odd == 1:
		for i in range(1, n + 1, 2):
			count += calcComb(n, i)
			print(count)
	else:
		count = 0
		for i in range(0, n + 1, 2):
			count += calcComb(n, i)

	return(int(count))

def calcNPtrn_even(n):
	if n == 0:
		return(1)

	count = 0
	for i in range(0, n + 1):
		count += calcComb(n, i)
	return(int(count))

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import math

def main():
	N, P = list(map(int, input().split()))
	biscuits = list(map(int, input().split()))

	n_odd = sum([x % 2 for x in biscuits])
	n_even = N - n_odd

	print(n_odd)
	print(calcNPtrn_odd(n_odd, P))
	print(calcNPtrn_even(n_even))

	out = calcNPtrn_odd(n_odd, P) * calcNPtrn_even(n_even)
	print(out)
	
def calcComb(n, m):
	return(math.factorial(n)/math.factorial(m)/math.factorial(n-m))

def calcNPtrn_odd(n, is_odd):
	if n == 0:
		if is_odd == 1:
			return(0)
		else:
			return(1)

	count = 0
	if is_odd == 1:
		for i in range(1, n + 1, 2):
			count += calcComb(n, i)
			print(count)
	else:
		count = 0
		for i in range(0, n + 1, 2):
			count += calcComb(n, i)

	return(int(count))

def calcNPtrn_even(n):
	if n == 0:
		return(1)

	count = 0
	for i in range(0, n + 1):
		count += calcComb(n, i)
	return(int(count))

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys
N, P = sys.stdin.readline().strip().split()
As = sys.stdin.readline().strip().split()
n_even = 0
n_odd = 0
for a in As:
  if int(a)/2 == 0:
    n_even += 1
  else:
    n_odd +=1
v = 2**n_even
if n_odd <= 1:
  v *= (1 if n_odd == P else 0)
else:
  v *= 2**(n_odd -1)
print(v)

Submission status: Wrong Answer

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


for i in range(len(A)):
	A[i] = A[i] % 2

num1 = A.count(1)
num0 = A.count(0)

if P == 0:
		print(2 ** (num0 + num1 - 1))
else:
	if num1 == 0:
		print(0)
	else:
		print(2 ** (num0 + num1 - 1))

Submission status: Wrong Answer

Solution code:
(N,P) = map(int, raw_input().split())
A = map(int, raw_input().split())
n_even = 0
m_odd = 0
for i in range(N):
	if A[i] % 2==0:
		n_even += 1
	else:
		m_odd += 1
N = 2**n_even
def calC(a,b):
	l1 = 1
	l2 = 1
	l3 = 1
	for i in range(a):
		l1 *= (i+1)
	for i in range(b):
		l2 *= (i+1)
	for i in range(a-b):
		l3 *= (i+1)
	return l1/l2/l3
M = 0	
for i in range((m_odd+1)//2):
	M += calC(m_odd, i*2+P)

print N*M