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:
from scipy.misc import comb

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

for i in A:
    if i%2==0:
        e +=1
    else:
        o +=1
#print(e,o)
       
if P==0:
    e_x = 2**e
    o_x = 0
    for j in range(0,o+1,2):
        #print(j,comb(o,j,exact=True))
        o_x += comb(o,j,exact=True)
else:
    e_x = 2**e
    if o==0:
        o_x = 0
    else:
        o_x = 0
        for j in range(1,o+1,2):
            #print(j,comb(o,j,exact=True))
            o_x += comb(o,j,exact=True)

ans = e_x * o_x
print(e_x , o_x , ans)

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb

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

for i in A:
    if i%2==0:
        e +=1
    else:
        o +=1
#print(e,o)
       
if P==0:
    e_x = 2**e
    o_x = 0
    for j in range(0,o+1,2):
        #print(j,comb(o,j,exact=True))
        o_x += comb(o,j,exact=True)
else:
    e_x = 2**e
    if o==0:
        o_x = 0
    else:
        o_x = 0
        for j in range(0,o,2):
            #print(j,comb(o,j,exact=True))
            o_x += comb(o,j+1,exact=True)

ans = e_x * o_x
print(e_x , o_x , ans)

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb

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

for i in A:
    if i%2==0:
        e +=1
    else:
        o +=1
#print(e,o)
       
if P==0:
    e_x = 2**e
    o_x = 0
    for j in range(0,o+1,2):
        #print(j,comb(o,j,exact=True))
        o_x += comb(o,j,exact=True)
else:
    e_x = 2**e
    if o==0:
        o_x = 0
    else:
        o_x = 0
        for j in range(0,o+1,2):
            #print(j,comb(o,j,exact=True))
            o_x += comb(o,j,exact=True)

ans = e_x * o_x
print(e_x , o_x , ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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

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

a_0 = []
a_1 = []
for j in a_list:
    if j % 2 == 0:
        a_0.append(j)
    else:
        a_1.append(j)

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


if p == 0:
    ans = 1

    if len(a_0) >= 1:
        for i in range(1,len(a_0)+1):
            ans += combinations_count(len(a_0), i)
    
    if len(a_1) > 2:
        for i in range(2,len(a_1)+1, 2):
            #print(i)
            ans += combinations_count(len(a_1), i)
    elif len(a_1) == 2:
        ans += 1

elif p == 1:
    ans = 0

    tmp_2 = 1
    if len(a_0) >= 1:
        for i in range(1,len(a_0)+1):
            tmp_2 += combinations_count(len(a_0), i)
    #print(tmp_2)

    if len(a_1) >= 1:
        for i in range(1,len(a_1)+1, 2):
            #print(i)
            tmp = combinations_count(len(a_1), i)
            ans += tmp*tmp_2

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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

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

a_0 = []
a_1 = []
for j in a_list:
    if j % 2 == 0:
        a_0.append(j)
    else:
        a_1.append(j)

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


if p == 0:
    ans = 1

    if len(a_0) >= 1:
        for i in range(1,len(a_0)+1):
            ans += combinations_count(len(a_0), i)
    
    if len(a_1) > 2:
        for i in range(2,len(a_1)+1, 2):
            #print(i)
            ans += combinations_count(len(a_1), i)
    elif len(a_1) == 2:
        ans += 1

elif p == 1:
    ans = 0

    tmp_2 = 1
    if len(a_0) >= 1:
        for i in range(1,len(a_0)+1):
            tmp_2 += combinations_count(len(a_0), i)
    #print(tmp_2)

    if len(a_1) >= 1:
        for i in range(1,len(a_1), 2):
            #print(i)
            tmp = combinations_count(len(a_1), i)
            ans += tmp*tmp_2

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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

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

a_0 = []
a_1 = []
for j in a_list:
    if j % 2 == 0:
        a_0.append(j)
    else:
        a_1.append(j)

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


if p == 0:
    ans = 1

    if len(a_0) >= 1:
        for i in range(1,len(a_0)+1):
            ans += combinations_count(len(a_0), i)
    
    if len(a_1) > 2:
        for i in range(2,len(a_1), 2):
            #print(i)
            ans += combinations_count(len(a_1), i)
    elif len(a_1) == 2:
        ans += 1

elif p == 1:
    ans = 0

    tmp_2 = 1
    if len(a_0) >= 1:
        for i in range(1,len(a_0)+1):
            tmp_2 += combinations_count(len(a_0), i)
    #print(tmp_2)

    if len(a_1) >= 1:
        for i in range(1,len(a_1), 2):
            #print(i)
            tmp = combinations_count(len(a_1), i)
            ans += tmp*tmp_2

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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

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

a_0 = []
a_1 = []
for j in a_list:
    if j % 2 == 0:
        a_0.append(j)
    else:
        a_1.append(j)

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


if p == 0:
    ans = 1

    if len(a_0) >= 1:
        for i in range(1,len(a_0)+1):
            ans += combinations_count(len(a_0), i)
    
    if len(a_1) > 2:
        for i in range(2,len(a_1), 2):
            print(i)
            ans += combinations_count(len(a_1), i)
    elif len(a_1) == 2:
        ans += 1

elif p == 1:
    ans = 0

    tmp_2 = 1
    if len(a_0) >= 1:
        for i in range(1,len(a_0)+1):
            tmp_2 += combinations_count(len(a_0), i)
    #print(tmp_2)

    if len(a_1) >= 1:
        for i in range(1,len(a_1), 2):
            #print(i)
            tmp = combinations_count(len(a_1), i)
            ans += tmp*tmp_2

print(ans)

Submission status: Wrong Answer

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
#issueから始める
N,P = inputlist()
A = inputlist()
for i in range(N):
    A[i] = A[i] % 2
from collections import Counter
c = Counter(A)
n0 = c[0]
n1 = c[1]
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans = 0
for i in range(1,n1+1):
    if i % 2 == 0:
        continue
    ans += comb(n1,i)
if P == 1:
    print((2**n0)*ans)
if P == 0:
    d = 2**N - ((2**n0)*ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
N, P = map(int, input().split())
biscuits = list(map(int, input().split()))
gu = 0
ki = 0
for i in range(N):
    if biscuits[i] % 2 == 0:
        gu += 1
    else:
        ki += 1
if (P == 1 and ki == 0) or (P == 0 and gu == 0):
    print(0)
elif gu == N:
    print(pow(2,N))
else:
    print(pow(2,N-1))

Submission status: Wrong Answer

Solution code:
N, P = map(int, input().split())
biscuits = list(map(int, input().split()))
ki = 0
for i in range(N):
    if biscuits[i] % 2 != 0:
        ki += 1
if P == 1 and ki == 0:
    print(0)
else:
    print(pow(2,N)//2)

Submission status: Wrong Answer

Solution code:
N, P = map(int, input().split())
A = list(map(int, input().split()))
mod0, mod1 = 0, 0
for a in A:
  if a % 2 == 0: mod0 += 1
  else: mod1 += 1
#print(mod0, mod1)

from math import factorial
comb0 = 2 ** mod0
comb1 = 0
if mod1 > 0:
  for i in range(P, mod1+1, 2):
    comb1 += factorial(mod1) // (factorial(mod1 - i) * factorial(i))
ans = comb0 * comb1
#print(comb0, comb1)
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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

for a in A:
    if a % 2 == 0:
        cE += 1
    else:
        cO += 1


# 全て偶数
if cO == 0:
    ans = 2 ** (N - 1) if P == 0 else 0
    print(ans)
    exit()
else:
    print(2 ** (cO - 1) * 2 ** cE)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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

for a in A:
    if a % 2 == 0:
        cE += 1
    else:
        cO += 1


# 全て偶数
if cO == 0:
    ans = 2 ** (N - 1) if P == 0 else 0
    print(ans)
    exit()
else:
    print(2 ** (N - 1))

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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

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

for a in A:
    if a % 2 == 0:
        cE += 1
    else:
        cO += 1

count = 0
if P == 0:
    # 偶数にする
    count += 2 ** cE # 部分集合すべて (食べないを含む)
    # m=cO個の奇数袋を偶数個選ぶ
    # mC2 + mC4 + mC6 + ... mCm
    for n in range(2, cO + 1, 2):
        count += cmb(cO, n)
else:
    # 奇数にする
    count += (2 ** cE) * cO # 部分集合全て * 奇数を1つ選ぶ
    # 奇数を奇数個選ぶ
    for n in range(1, cO, 2):
        count += cmb(cO, n)
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import math
n,p = map(int,input().split())
a = list(map(int,input().split()))
dp = [[0,0] for _ in range(n)]
if a[0] & 1:
    dp[0][0] = 1
    dp[0][1] = 1
else:
    dp[0][0] = 1
    dp[0][1] = 0
for i in range(1,n):
    if a[i] & 1:
        dp[i][0] = dp[i-1][0]+dp[i-1][1]
        dp[i][1] = dp[i-1][0]+dp[i-1][1]
    else:
        dp[i][0] = dp[i-1][0]*2
        dp[i][1] = dp[i-1][1]*2
print(dp[n-1][p])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import math
n,p = map(int,input().split())
a = list(map(int,input().split()))
s = [1 for i in a if i%2 == 1]
num_odd = len(s)
def sum_comb_odd(n):
    ret = 0
    for i in range(n//2):
        ret += math.factorial(n)//(math.factorial(n-2*i-1)*math.factorial(2*i+1))
    return ret
if num_odd & 1: 
    print(pow(2,(n-num_odd))*pow(2,num_odd)//2)
else: 
    if n & 0: print(pow(2,(n-num_odd))*pow(2,num_odd)//2)
    else: print(pow(2,(n-num_odd))*sum_comb_odd(num_odd))

Submission status: Wrong Answer

Solution code:
def n_pow(a, n):
    if n <= 0:
        return 0
    return pow(a, n)


def main():
    bags, remainder = map(int, input().split())
    biscuits = list(map(int, input().split()))
    count = [0, 0]
    for b in biscuits:
        count[b % 2] += 1
    print(n_pow(2, count[0] + count[1] - 1))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
from math import factorial

sys.setrecursionlimit(4100000)
from functools import lru_cache

INF = 1 << 60
MOD = 10 ** 9 + 7

#Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ここから書き始める
n, p = map(int, input().split())
even = []
odd = []
a = list(map(int, input().split()))
for i in a:
    if i % 2 == 0:
        even.append(i)
    else:
        odd.append(i)
# print("even =", even)
# print("odd =", odd)
x = len(even)
y = len(odd)
ans = 0
if x == 0 and y == 1:
    ans = 1
elif x == 1 and y == 0:
    if p == 0:
       ans = 2
    else:
        ans = 0
elif x == y == 1:
    if p == 0:
        ans = 2
    else:
        ans = 2
else:
    ans = (2 ** x) * (2 ** (y - 1))
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
from math import factorial

sys.setrecursionlimit(4100000)
from functools import lru_cache

INF = 1 << 60
MOD = 10 ** 9 + 7

#Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ここから書き始める
n, p = map(int, input().split())
even = []
odd = []
a = list(map(int, input().split()))
for i in a:
    if i % 2 == 0:
        even.append(i)
    else:
        odd.append(i)
# print("even =", even)
# print("odd =", odd)
x = len(even)
y = len(odd)
ans = 0
if n == 1:
    if p == 0:
        if a[0] % 2 == 0:
            ans = 2
        else:
            ans = 1
    else:
        if a[0] % 2 == 0:
            ans = 0
        else:
            ans = 1
else:
    if p == 0:
        ans = (2 ** x) * (2 ** (y - 1))
    else:
        ans = 2 * (2 ** (x - 1)) * (2 ** (y - 1))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


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


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

odd = sum([a % 2 for a in A])
even = len(A) - odd

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys


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


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

odd = sum([a % 2 for a in A])
even = len(A) - odd

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

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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

N,P=map(int,input().split())
A=list(map(int,input().split()))
odd=len([i for i in A if i%2==1])
even=len([i for i in A if i%2==0])

if P==0:
    ans=2**even
    ans_odd=1
    if odd!=0:
        for i in range(odd//2+1):
            ans_odd+=cmb(odd,2*i)
else:
    ans=2**even
    ans_odd=0
    if odd!=0:
        for i in range(odd//2):
            ans_odd+=cmb(odd,2*i+1)
print(ans*ans_odd)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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

N,P=map(int,input().split())
A=list(map(int,input().split()))
odd=len([i for i in A if i%2==1])
even=len([i for i in A if i%2==0])

if P==0:
    ans=2**even
    ans_odd=0
    if odd!=0:
        for i in range(odd//2+1):
            ans_odd+=cmb(odd,2*i)
else:
    ans=2**even
    ans_odd=0
    if odd!=0:
        for i in range(odd//2):
            ans_odd+=cmb(odd,2*i+1)
print(ans*ans_odd)

Submission status: Wrong Answer

Solution code:
import math

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

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

for i in range(n):
  a[i] = a[i]%2

for i in range((a.count(1)+1)//2):
  res = res + comb(a.count(1), 2*i+1)
  
res = res * 2**a.count(0)
print(res)

Submission status: Wrong Answer

Solution code:
n, p = map(int, input().split())
a = list(map(int, input().split()))
a_even = 0
a_odd = 0
for i in a:
    if i % 2 == 0:
        a_even += 1
    else:
        a_odd += 1
        
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

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

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

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k]) 
    
    return result
        
if p == 0:
    odd = 0
    for i in range(a_odd//2 + 1):
        print(i)
        odd += cmb(a_odd, 2 * i)
    print((2 ** (a_even)) * odd)
else:
    odd = 0
    if a_odd % 2 == 0:
        for i in range(a_odd//2):
            odd += cmb(a_odd, 2 * i + 1)
    else:
        for i in range(a_odd//2 + 1):
            odd += cmb(a_odd, 2 * i + 1)
    print((2 ** (a_even)) * odd)

Submission status: Wrong Answer

Solution code:
import math
N,P=map(int,input().split())
A=list(map(int,input().split()))
l=[]
c=0
cnt=0
even=0
odd=0
for i in range(0,N):
    if A[i]%2==0:
        even=even+1
    else:
        odd=odd+1
if P==0:
    print(pow(2,even)*int(pow(2,odd-1)))
else:
    print(pow(2,even)*math.floor(pow(2,odd-1)))

Submission status: Wrong Answer

Solution code:

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

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

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

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

if n == 1:
    if p == 0:
        if a[0] % 2 == 0:
            print(1)
        else:
            print(0)
    else:
        if a[0] % 2 == 1:
            print(0)
        else:
            print(1)
else:
    if odd == 0:
        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 = [i for i in a if i%2==1]
eve = [i for i in a if i%2==0]
odd_len = len(odd)
eve_len = len(eve)
if p==0:
    ans = 2**eve_len
else:
    ans = 0
count = 0
if p==0:
    ans *= 2**odd_len//2
else:
    ans +=   (2**eve_len)*(2**odd_len//2)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import math

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

N, p = map(int,input().split())
A = list(map(int,input().split()))
even = 0
odd = 0

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

ans = 0

if p % 2 == 0:
    for i in range(even+1):
        ans += combinations_count(even,i)
    for i in range(odd+1):
        if i % 2 == 0:
            ans += combinations_count(odd,i)
    ans -= 1
else:
    for i in range(odd+1):
        if i % 2 == 1:
            ans += combinations_count(odd,i)
#print(ans)

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

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import math

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

N, p = map(int,input().split())
A = list(map(int,input().split()))
even = 0
odd = 0

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

ans = 0

if p % 2 == 0:
    for i in range(even+1):
        ans += combinations_count(even,i)
    for i in range(odd+1):
        if i % 2 == 0:
            ans += combinations_count(odd,i)
    ans -= 1
else:
    for i in range(odd+1):
        if i % 2 == 1:
            ans += combinations_count(odd,i)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  n, p = input_list()
  a = list(input_list())
  b = "1"*n
  bi = int(b, 2)
  r = 0
  if p == 0:
    # 偶数の場合：
    for i in range(n):
      if i % 2 == 0:
        r += combinations_count(n, i)
    if r % 2 != 0:
      r += 1
  else:
    # 奇数の場合：奇数を奇数個かける
    for i in range(n):
      if i % 2 != 0:
        r += combinations_count(n, i)
    if r > 0:
      r += 1
  print(r)  
  exit()
  for i in range(bi+1):
    fi = format(i, '0'+str(n)+'b')
    ans = 0
    for index, v in enumerate(fi):
      if v == '1':
        ans += a[index]
    if ans % 2 == p:
      r += 1
  print(r)
  
def input_list():
  return map(int, input().split())

def input_list():
  return map(int, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

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

import math
import fractions

from functools import reduce
main()

Submission status: Wrong Answer

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

odd = 0
even = 0

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


ans = (2 ** even) * ((2 ** odd) // 2)
print(ans)

Submission status: Wrong Answer

Solution code:
n, p = map(int, input().split())
a = [1 if i%2==0 else 0 for i in map(int,input().split())]
sum_a = sum(a)

if p==0:
    print(n*(n-1)//2-sum_a*(n-sum_a)+1)
else:
    print(sum_a*(n-sum_a))

Submission status: Wrong Answer

Solution code:
n, p = map(int, input().split())
a = [1 if i%2==0 else 0 for i in map(int,input().split())]
sum_a = sum(a)

if p==0:
    print(n*(n-1)-sum_a*(n-sum_a))
else:
    print(sum_a*(n-sum_a))

Submission status: Wrong Answer

Solution code:
n, p = map(int, input().split())
a = list(map(int, input().split()))
flag = True
for i in a:
    if i % 2 == 0:
        continue
    else:
        flag = False
        break

# if n == 1 and a[0] % 2 == 0:
#     if p == 0:
#         print(2)
#     else:
#         print(0)
# elif n == 1 and a[0] % 2 == 1:
#     print(1)
# 
# else:
if flag:
    print(2 ** n)
else:
    print(2 ** n // 2)

Submission status: Wrong Answer

Solution code:
n, p = map(int, input().split())
a = list(map(int, input().split()))
flag = True
for i in a:
    if i % 2 == 0:
        continue
    else:
        flag = False
        break

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

else:
    if flag:
        print(2 ** n)
    else:
        print(2 ** n // 2)

Submission status: Wrong Answer

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

if n == 1 and a[0] % 2 == 0:
    if p == 0:
        print(2)
    else:
        print(0)
elif n == 1 and a[0] % 2 == 1:
    print(1)
else:
    print(2 ** n // 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, p = map(int, input().split())
A = list(map(int, input().split()))
if n>=2:
    print(pow(2, n)//2)
else:
    print(1 if A[0]%2==p else 0)

Submission status: Wrong Answer

Solution code:
from math import factorial
def f(a, b):
    if a == 0 or b == 0:
        return 1
    else:
        return factorial(a) // (factorial(a - b) * factorial(b))
n, p = (int(x) for x in input().split())
a = [int(x) % 2 for x in input().split()]
o = sum(a)
e = n - o
ans = 0
if p == 0:
    ans += 1
    if e == 0:
        for i in range(2, o+1, 2):
            ans += f(o, i)
    elif o <= 1:
        for i in range(1, e+1):
            ans += f(e, i)
    else:
        for i in range(e+1):
            for j in range(2, o+1, 2):
                ans += f(e, i) * f(o, j)
else:
    if e == 0: e = 1
    for i in range(e+1):
        for j in range(1, o+1, 2):
            ans += f(e, i) * f(o, j)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
def f(a, b):
    if a == 0 or b == 0:
        return 1
    else:
        return factorial(a) // (factorial(a - b) * factorial(b))
n, p = (int(x) for x in input().split())
a = [int(x) % 2 for x in input().split()]
o = sum(a)
e = n - o
ans = 0
if p == 0:
    ans += 1
    if e == 0:
        for i in range(2, o+1, 2):
            ans += f(o, i)
    elif o <= 1:
        for i in range(1, e+1):
            ans += f(e, i)
    else:
        for i in range(1, e+1):
            for j in range(2, o+1, 2):
                ans += f(e, i) * f(o, j)
else:
    if e == 0: e = 1
    for i in range(1, e+1):
        for j in range(1, o+1, 2):
            ans += f(e, i) * f(o, j)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
def f(a, b):
    if a == 0 or b == 0:
        return 1
    else:
        return factorial(a) // (factorial(a - b) * factorial(b))
n, p = (int(x) for x in input().split())
a = [int(x) % 2 for x in input().split()]
o = sum(a)
e = n - o
ans = 0
if p == 0:
    ans += 1
    if e == 0:
        for i in range(2, o+1, 2):
            ans += f(o, i)
    elif o <= 1:
        for i in range(1, e+1):
            ans += f(e, i)
    else:
        for i in range(1, e+1):
            for j in range(2, o+1, 2):
                ans += f(e, i) * f(o, j)
else:
    if e == 0:
        for i in range(1, o+1, 2):
            ans += f(o, i)
    elif o == 0:
        for i in range(1, e+1):
            ans += f(e, i)
    else:
        for i in range(1, e+1):
            for j in range(1, o+1, 2):
                ans += f(e, i) * f(o, j)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
def f(a, b):
    if a == 0 or b == 0:
        return 1
    else:
        return factorial(a) // (factorial(a - b) * factorial(b))
n, p = (int(x) for x in input().split())
a = [int(x) % 2 for x in input().split()]
o, e = sum(a), n - sum(a)
ans = 0
if e == 0: e = 1
if p == 1:
    for i in range(1, e+1):
        for j in range(1, o+1, 2):
            ans += f(e, i) * f(o, j)
else:
    ans += 1
    for i in range(1, e+1):
        for j in range(2, o+1, 2):
            ans += f(e, i) * f(o, j)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
def f(a, b):
    if b == 0:
        return 1
    else:
        return factorial(a) // (factorial(a - b) * factorial(b))
n, p = (int(x) for x in input().split())
a = [int(x) % 2 for x in input().split()]
o, e = sum(a), n - sum(a)
ans = 0
if p == 1:
    for i in range(e+1):
        for j in range(1, o+1, 2):
            ans += f(e, i) * f(o, j)
else:
    ans += 1
    if e == 0: e = 1
    for i in range(e):
        for j in range(2, o+1, 2):
            ans += f(e, i) * f(o, j)
print(ans)

Submission status: Wrong Answer

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

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
if (P == 0):
  l_odd = len(odd)
  num = 0
  while l_odd >= num:
    ans += combinations_count(l_odd, num)
    num += 2
  if (len(even)!=0):
    ans *= 2**len(even)
else:
  if (len(odd)!=0):
    ans *= 2**len(odd)*2**len(even)
print(ans)

Submission status: Wrong Answer

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

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
if (P == 0):
  l_odd = len(odd)
  ans += 1
  num = 2
  while l_odd >= num:
    ans += combinations_count(l_odd, num)
    num += 2
  if (len(even)!=0):
    ans *= 2**len(even)
else:
  l_even = len(even)
  ans += 1
  num = 2
  while l_even >= num:
    ans += combinations_count(l_even, num)
    num += 2
  if (len(odd)!=0):
    ans *= 2**len(odd)
print(ans)

Submission status: Wrong Answer

Solution code:
import math,itertools

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

def main():
    N,P = map(int,input().split())
    A = list(map(int,input().split()))
    odd_A = [A[i] for i in range(N) if A[i]%2 != 0]
    even_A = [A[i] for i in range(N) if A[i]%2 == 0]
    allpat = 2**N
    comb = 0
    for i in range(0,len(odd_A)+1,2):
        comb += combinations_count(len(odd_A),i)
    evenpat = (2**len(even_A))*comb
    oddpat = allpat - evenpat
    ans = evenpat if P == 1 else oddpat
    print(ans)


if __name__ == '__main__':
    main()