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: Accepted

Solution code:
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 = 2 ** (even + odd - 1)
if odd == 0:
    if P == 1: ans = 0
    else: ans = 2 ** even
    
print(ans)

Submission status: Accepted

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

odd = 0
even = 0
for i in range(n):
    if A[i] % 2 == 0:
        even += 1
    else:
        odd += 1
        
if odd == 0:
    if p == 0:
        print(2 ** n)
    else:
        print(0)
else:
    print(2 **(n - 1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, P = map(int, input().split())
A = list(map(int, input().split()))
if all(a % 2 == 0 for a in A):
    if P:
        print(0)
    else:
        print(2 ** N)
else:
    print(2 ** (N - 1))

Submission status: Accepted

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

cnt = 0
for x in a:
    if x % 2 == 0:
        cnt += 1
        
if cnt == n:
    if p == 0:
        print(2**n)
    else:
        print(0)
else:
    print(2**n//2)

Submission status: Accepted

Solution code:
n, p = map(int, input().split())
a = list(map(int, input().split()))
odd = 0
for i in a:
    if i % 2:
        print(2 ** (n - 1))
        exit()
if p:
    print(0)
else:
    print(2 ** n)

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
flag=0;a=list(map(int,input().split()))
ans=0
for i in range(n):
  if a[i]%2!=0:
    flag=1

if flag==0 and p==0:
  ans=2**n
elif flag==0 and p==1:
  ans=0

if flag==1:
  ans=2**(n-1)
print(ans)

Submission status: Accepted

Solution code:
import math
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
T = 2**Even
S = 0
if P == 0:
  for i in range(Odd//2+1):
    S += math.factorial(Odd)//((math.factorial(Odd-2*i))*math.factorial(2*i))
  print(S*T)
else:
  for j in range(Odd//2):
    S += math.factorial(Odd)//((math.factorial(Odd-2*j-1))*math.factorial(2*j+1))
  print(S*T)

Submission status: Accepted

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

k = A.count(1)
l = A.count(0)

if P == 0:
    if k == 0:
        print(2**l)
        exit()
    ans = 1
    ans = 2**(k-1+l)
else:
    if k == 0:
        print(0)
        exit()
    else:
        ans = 1
        ans = 2**(k-1+l)

print(ans)

Submission status: Accepted

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

aa = list(map(lambda x:x%2, aa))
odd = aa.count(1)
even = aa.count(0)
ans = 2**even
# if p==1:
#     ans*=odd
#     odd-=1
# 偶数個の選び方
pattern = 0
for i in range(p, odd+1, 2):
    # print(even, odd, i, math.factorial(odd) // (math.factorial(i)*math.factorial(odd-i)))
    pattern += math.factorial(odd) // (math.factorial(i)*math.factorial(odd-i))
print(ans*pattern)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
from math import factorial

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,*a=map(int,open(0).read().split())
b=[i for i in a if i%2==0]
c=[i for i in a if i%2==1]
ans=0
x=0
for s in range(len(b)+1):
  x+=cmb(len(b),s)
if p==0:
  for s in range(0,len(c)+1,2):
    ans+=x*cmb(len(c),s)
  print(ans)
else:
  for s in range(1,len(c)+1,2):
    ans+=x*cmb(len(c),s)
  print(ans)

Submission status: Accepted

Solution code:
n,p = map(int,input().split())
A = list(map(int,input().split()))
A = [_ % 2 for _ in A ]
k = A.count(1)
if k == 0:
    if p == 0:
        print(2**n)
    else:
        print(0)
else:
    print(2**(n-1))

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
a=list(map(int, input().split()))
for i in range(n):
  a[i]%=2
if sum(a)>0:print(2**(n-1))
else:
    if m==0:print(2**n)
    else:print(0)

Submission status: Accepted

Solution code:
from math import factorial
def comb(n,r):
    return factorial(n)//(factorial(n-r)*factorial(r))
n,p=map(int,input().split())
A=list(map(int,input().split()))
cnt_odd=0
cnt_even=0
for i in range(n):
    if A[i]%2:
        cnt_odd+=1
    else:
        cnt_even+=1
ans=0
for i in range(p%2,cnt_odd+1,2):
    ans+=2**cnt_even*comb(cnt_odd,i)
print(ans)

Submission status: Accepted

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 = [int(m) for m in input().split()]
k = 0
for i in range(n):
    if a[i] % 2 == 0:
        k += 1

if p == 1:
    tmp = 0
    for i in range(1, n - k + 1, 2):
        tmp += comb(n - k, i)
    print((2 ** k) * tmp)
else:
    tmp = 0
    for i in range(0, n - k + 1, 2):
        tmp += comb(n - k, i)
    print((2 ** k) * tmp)

Submission status: Accepted

Solution code:
from math import factorial

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

l = [0, 0]
for a in A:
    l[a%2] += 1

even = (2**l[0])*sum(factorial(l[1])//factorial(l[1]-i)//factorial(i) for i in range(0, l[1]+1, 2))
# print(even, 2**N)
if P:
    print(2**N-even)
else:
    print(even)

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, P = map(int, input().split())
f = [1]*(N+1)
for i in range(1, N):
    f[i+1] = f[i]*(i+1)

A = list(map(lambda x: int(x) % 2, input().split()))

odd = A.count(1)
even = N-odd

ans = 0

even_sum = 2**even
odd_sum_even = sum([f[odd]//(f[v]*f[odd-v]) for v in range(0, odd+1, 2)])
odd_sum_odd = sum([f[odd]//(f[v]*f[odd-v]) for v in range(1, odd+1, 2)])
if P == 0:
    ans = even_sum*odd_sum_even if even_sum * \
        odd_sum_even != 0 else max(even_sum, odd_sum_even)
else:
    if odd_sum_odd == 0:
        ans = 0
    else:
        ans = even_sum*odd_sum_odd if even_sum * \
            odd_sum_odd != 0 else max(even_sum, odd_sum_odd)

print(ans)

Submission status: Accepted

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


n,p = (int(i) for i in input().split())
a = list(int(i) for i in input().split())
odd = 0
even = 0
ans = 0
for i in range(n):
  if a[i]%2 == 0: even+=1
  else:odd += 1
if even == n:
  if p == 0: print(2**n)
  else:print(0)
else:
  print(2**(n-1))

Submission status: Accepted

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

"""
参考：https://img.atcoder.jp/agc017/editorial.pdf
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, P = MAP()
aN = LIST()

has_odd = False
for i in range(N):
    if aN[i] % 2 == 1:
        has_odd = True
        break
if not has_odd:
    if P == 0:
        print(2 ** N)
    else:
        print(0)
else:
    print(2 ** (N-1))

Submission status: Accepted

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def nCr(n, r):
    # 10C7 = 10C3
    r = min(r, n-r)
    return factorial(n) // (factorial(r) * factorial(n-r))

N, P = MAP()
aN = LIST()

# この問題では偶奇しか関係しないのでmod 2する
for i in range(N):
    aN[i] %= 2
c = Counter(aN)

ans = 0
# 最終的に偶奇どっちにするかによって、奇数を取る数を変える
if P == 0:
    # 奇数を偶数個取る組み合わせ
    for i in range(0, c[1]+1, 2):
        ans += nCr(c[1], i)
else:
    # 同じように奇数個取る組み合わせ
    for i in range(1, c[1]+1, 2):
        ans += nCr(c[1], i)
# 偶数の数は偶奇の変化に影響を与えないので、取るor取らないの全組み合わせ(2**偶数の数)をかける
print(ans * 2**c[0])

Submission status: Accepted

Solution code:
import collections, scipy.misc, numpy
n, p = map(int, input().split())
a = numpy.array(list(map(int, input().split())))
a %= 2
c = collections.Counter(a)
ans = 0
for i in range(p, c[1] + 1, 2):
    ans += 2 ** c[0] * scipy.misc.comb(c[1], i, exact=True)
print(ans)

Submission status: Accepted

Solution code:
import collections, scipy.misc, numpy
n, p = map(int, input().split())
a = numpy.array(list(map(int, input().split())))
a %= 2
c = collections.Counter(a)
ans = 0
for i in range(p, c[1] + 1, 2):
    ans += 2 ** c[0] * scipy.misc.comb(c[1], i, exact=True)
print(ans)

Submission status: Accepted

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

for i in range(n):
    a[i] %= 2
c = collections.Counter(a)
zero = c[0]
one = c[1]
ans = 0
if p == 0:
    s = 0
else:
    s = 1
for i in range(s, one + 1, 2):
    ans += 2 ** zero * scipy.misc.comb(one, i, exact=True)

print(ans)

Submission status: Accepted

Solution code:
n,r=map(int,input().split())
c=[i%2for i in list(map(int,input().split()))]
p=sum(c)
print(0if p==0 and r!=0else(2**n if p==0 and r!=1else (2**(n-1))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

b = 0
c = 0

for i in range(N):
    if A[i]%2==1:
        b = b+1
    else:
        c = c+1

if P==1:
    k=1
else:
    k=0
  
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)   
 
def C(n, r):
    return P(n, r)//math.factorial(r)
    
ans = 0
tmp = 2**c

while k<=b:
    ans = ans + tmp*C(b, k)
    k = k+2

print(ans)

Submission status: Accepted

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()))
b = [i%2 for i in a]
n1 = b.count(1)
zero = 2 ** (n-n1)
r = 1
one = 0
while r <= n1:
  one += cmb(n1,r)
  r += 2
if p == 0:
  print(2**n - zero*one )
else:
  print(zero * one)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
a = list(map(int,input().split()))
a = [i%2 for i in a]
if sum(a)>0:print(2**(n-1))
else:
    if m == 0:print(2**n)
    else:print(0)

Submission status: Accepted

Solution code:
from collections import Counter
def combination(n, r): # nCrを求める
    r = min(n-r, r)
    result = 1
    for i in range(n, n-r, -1):
        result *= i
    for i in range(1, r+1):
        result //= i
    return result
n,p = map(int,input().split())
a =list(map(int,input().split()))
for i in range(n):
    a[i] = a[i]%2
b = Counter(a)
c = b[1]
d = b[0]
ans = 0
if p ==0:
    for i in range(0,c+1,2):
        ans += combination(c,i)
else:
    for i in range(1,c+1,2):
        ans += combination(c, i)
ans *= 2**d
print(ans)

Submission status: Accepted

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

for i in input().split():
    if int(i) % 2 == 0:
        continue
    else:
        print(2 ** (N - 1))
        break
else:
    if P == 0:
        print(2 ** N)
    else:
        print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, P] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    E_count = 0
    O_count = 0
    for i in range(N):
        if int(input_raw[i]) % 2 == 0:
            E_count += 1
        else:
            O_count += 1

    if P == 1:
        if O_count==0:
            print 0;
            return

    if O_count > 0:
        print (2**E_count ) * (2 ** (O_count - 1))
    else:
        print (2**E_count )


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

    e_count, o_count = 0, 0
    for dum in a:
        if dum % 2 == 0:
            e_count += 1
        else:
            o_count += 1

    total = 0
    if p == 0:
        dum = 1
        for i in range(o_count // 2):
            n = (i + 1) * 2
            dum += (math.factorial(o_count) // (math.factorial(o_count - n) * math.factorial(n)))
        total += (2 ** e_count) * dum

    elif p == 1:
        if o_count == 0:
            pass
        else:
            dum = 0
            for i in range((o_count + 1) // 2):
                n = (i * 2) + 1
                dum += (math.factorial(o_count) // (math.factorial(o_count - n) * math.factorial(n)))
            total += (2 ** e_count) * dum

    print(total)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

numOdd = sum([A % 2 for A in As])

if numOdd == 0:
    print([2 ** N, 0][P])
else:
    print(2 ** (N - 1))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

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

    A = list(map(lambda x: x % 2, A))
    if A.count(1):
        ans = pow(2,N-1)
    else:
        if P == 0:
            ans = pow(2,N)
        else:
            ans = 0

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = 0

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

if P==0:
    for i in range(0,odd+1):
        if i%2==0:
            ans += combination(odd,i)*(2**even)
else:
    for i in range(1,odd+1):
        if i%2==1:
            ans += combination(odd,i)*(2**even)
print(ans)

Submission status: Accepted

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

n, p = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
# print(sorted(a))
# まず偶数の袋binaryと奇数の袋nonBinaryの数を算出
binary = 0
nonBinary = 0
for i in range(n):
    if a[i] % 2 == 0:
        binary += 1
    else:
        nonBinary += 1
if p == 0:
    count = 0
    for i in range(nonBinary+1):
        if i % 2 == 0:
            count += combinations_count(nonBinary, i)
    count *= 2 ** binary
    print(count)
else:
    count = 0
    for i in range(1, nonBinary + 1):
        if i % 2 == 1:
            count += combinations_count(nonBinary, i)
    count *= 2 ** binary
    print(count)

Submission status: Accepted

Solution code:
N,P = map(int, input().split())
A = list(map(lambda x:int(x)%2, input().split()))
A0 = A.count(0)
A1 = A.count(1)
if P == 1:
    if A1 == 0:
        print(0)
    else:
        print(2**(A1-1)*2**A0)
else:
    if A1 == 0:
        print(2**A0)
    else:
        print(int(2**(A1-1)*2**A0))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
a=[int(i) for i in input().split()]
odd=0
for i in a:
    if i%2: odd+=1
even=n-odd
if odd==0:
    print(2**n if p==0 else 0)
else:
    print(2**(n-1))

Submission status: Accepted

Solution code:
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def main() -> None:
    n, p = [next_int() for _ in range(2)]
    odd = even = 0

    for i in range(n):
        a = next_int()
        odd += a % 2
        even += (a % 2) ^ 1

    if odd == 0:
        print(2 ** even * int(p == 0))
    else:
        print((2 ** (odd - 1)) * (2 ** even))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, P = map(int, input().split())
A = list(map(lambda x:int(x)%2, input().split()))
one = A.count(1)
zero = A.count(0)
if P == 1:
    if one == 0:
        print(0)
    else:
        print(2**(one-1)*2**zero)
else:
    if one == 0:
        print(2**zero)
    else:
        print(int(2**(one-1)*2**zero))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def c(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()))
A_O = [e for e in A if e % 2 == 1]
A_E = [e for e in A if e % 2 == 0]
ans = 0
if P == 0:
    for k in range(math.floor(len(A_O)/2) + 1):
        for l in range(len(A_E) + 1):
            ans += c(len(A_O),2*k) * c(len(A_E),l)
elif P == 1:
    for k in range(math.floor((len(A_O) - 1) /2) + 1):
        for l in range(len(A_E) + 1):
            ans += c(len(A_O),2*k + 1) * c(len(A_E),l)
print(ans)

Submission status: Accepted

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 != 0 :
        odd += 1
if odd == 0 :
    if P == 0 :
        ans = 2**N
    else :
        ans = 0
else :
    ans = 2**(N-1)
print(ans)

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
a=list(map(int,input().split()))
j=True
for t in a:
    if t%2!=0:
        j=False
        break
if j:
    print(2**n if p==0 else 0)
else:
    print(2**(n-1))

Submission status: Accepted

Solution code:
N, P = map(int, input().split())
A = list(map(int, input().split()))
ev = 0
od = 0
for a in A:
    if a % 2 == 0:
        ev += 1
    else:
        od += 1
if P == 0 and od == 0:
    print(2**ev)
else:
    print(2**ev * (2**od//2))

Submission status: Accepted

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

p = [0,0]

if p_num[1] == 0:
    if P == 0:
        print(2**p_num[0])
    else:
        print(0)
    exit()

print(2**(N-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
a=list(map(int, input().split()))
a=[i%2 for i in a]
if sum(a)>0:print(2**(n-1))
else:
    if m==0:print(2**n)
    else:print(0)

Submission status: Accepted

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

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

ans = 0

if p:
    for i in range(zero+1):
        for j in range((one+1)//2 + 1):
            ans += comb(zero, i)*comb(one, 2*j+1)
else:
    for i in range(zero+1):
        for j in range((one+1)//2 + 1):
            ans += comb(zero, i)*comb(one, 2*j)
print(ans)

Submission status: Accepted

Solution code:
n, p=map(int, raw_input().split())
cnt=sum([a%2 for a in map(int, raw_input().split())])
print pow(2, n-1) if cnt else pow(2, n)*(1-p)

Submission status: Accepted

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

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 = list(map(int, input().split()))
    odd = 0
    even = 0
    ans = 1
    for a in a_list:
        if a % 2 == 0:
            even += 1
        else:
            odd += 1
    all_cnt = 0
    for i in range(n+1):
        all_cnt += combinations_count(n, i)
    odd_cnt = 0
    for i in range(0, odd+1, 2):
        odd_cnt += combinations_count(odd, i)
    even_cnt =0
    for i in range(even+1):
        even_cnt += combinations_count(even, i)
    if p == 0:
        ans = odd_cnt * even_cnt
    else:
        ans = all_cnt - odd_cnt * even_cnt
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,p=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in range(n):
  if a[i]%2==1:c+=1
if c==0:
  if p==0:print(2**n)
  else:print(0)
elif c==n:
  if n!=1:print(2**(n-1))
  else:print(0)
else:print(2**(n-1))

Submission status: Accepted

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

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

#print(a)

for i in a:
    if i % 2 == 1:
        print(2 ** (n - 1))
        exit(0)

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

else:
    print(0)

Submission status: Accepted

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

d = [1, 0]

for a in A:
    v = d[:]
    if a % 2 == 0:
        v[0] = d[0] + d[0]
        v[1] = d[1] + d[1]
    else:
        v[0] = d[0] + d[1]
        v[1] = d[0] + d[1]
    d = v[:]
    
print(d[P])

Submission status: Accepted

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

n,p = map(int, input().split())
list_a = list((map(int, input().split())))
for i in range(0,n):
    list_a[i] = list_a[i] % 2
odd = list_a.count(1)
even = list_a.count(0)
even_ans = int(2**even)
odd_ans = 0
if p == 0:
    for i in range(0,odd+1):
        if i % 2 == 0:
            odd_ans += nCr(odd, i)
else:
    for i in range(0,odd+1):
        if i % 2 == 1:
            odd_ans += nCr(odd, i)

print(int(even_ans * odd_ans))

Submission status: Accepted

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

c_odd , c_even = 0, 0

for a in A:
  if a%2 == 0:
    c_even += 1
  else:
    c_odd += 1

if c_odd == 0:
  print(2**N if P==0 else 0)
else:
  print(2**(N-1))
    
"""
fact = [1] * 51

for i in range(1,51):
  fact[i] = fact[i-1] * i
  
def comb(n,r):
  return int(fact[n] / fact[r] / fact[n-r])

idx = 1 if P == 1 else 0

work = 0
while idx <= c_odd:
  work += comb(c_odd, idx)
  idx += 2

print(work * ( 2 ** c_even) )
"""

Submission status: Accepted

Solution code:
n, p = map(int, input().split())
a = list(map(int, input().split()))
for i in a:
    if i % 2 == 1:
        print(2 ** (n - 1))
        exit()
if p == 0:
    print(2 ** n)
else:
    print(0)

Submission status: Accepted

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

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


if p == 0:
    rr = 1
    tt = 1
    jj = 1
    for i in range(g):
        rr = rr * (g-i)
        tt = tt * (i+1)
        if tt != 0:
            jj += rr //tt
    jkl = 1
    rr = 1
    tt = 1
    for i in range(k//2):
        rr = rr *(k-2*i)*(k-2*i-1)
        
        tt = tt * (2*i+1) * (2*i+2)

        if tt != 0:
            jkl += rr//tt
    ass += jj*jkl
else:
    rr = 1
    tt = 1
    jkl = 1
    for i in range(g):
        rr = rr * (g-i)
        tt = tt * (i+1)
        if tt != 0:
            jkl += rr //tt
    
    rr = 1
    tt = 1
    jj = 0
    if k % 2 == 1:
        u = k//2+1
    else:
        u = k//2
    for i in range(u):
        if i == 0:
            rr = k
            tt = 1
        else:
            rr = rr*(k-2*i)*(k-2*i+1)
            tt = tt*(2*i)*(2*i+1)
        jj += rr//tt
    ass += jj*jkl
print(int(ass))

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,p = inpl()
aa = inpl()
cnt = [0]*2
for a in aa:
    cnt[a%2] += 1

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

def C(n, r):
    if r == 0: return 1
    return P(n, r)//math.factorial(r)

if p == 0:
    ans = pow(2,(cnt[0]))
    tmp = 0
    for i in range(0,cnt[1]+1,2):
        tmp += C(cnt[1],i)
    ans *= tmp
else:
    ans = pow(2,(cnt[0]))
    tmp = 0
    for i in range(1,cnt[1]+1,2):
        tmp += C(cnt[1],i)
    ans *= tmp

print(ans)

Submission status: Accepted

Solution code:
import math
def c(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()))
for i in range(N):
    A[i] %= 2
A.sort()
i = 0
while True:
    if i >= len(A):
        break
    if A[i] == 0:
        i += 1
    elif A[i] == 1:
        i -= 1
        if i < 0:
            i = 0
        break
zero = i
not_zero = len(A) - zero
combination0 = 1
for i in range(1, zero + 1):
    combination0 += c(zero, i)
    
if P == 0:
    combination1_0 = 1
    for i in range(2, not_zero + 1, 2):
        combination1_0 += c(not_zero, i)
    print(combination0 * combination1_0)
else:
    combination1_1 = 0
    for i in range(1, not_zero + 1, 2): #1
        combination1_1 += c(not_zero, i)
    print(combination1_1 * combination0)

Submission status: Accepted

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

ch = [a for a in A if a%2 == 0]
if len(ch) == len(A):
    if P == 0:
        ans = 2**N
    else:
        ans = 0
else:
    ans = 2**(N-1)

print(ans)

Submission status: Accepted

Solution code:
import math

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

#奇数の数と偶数の数を数えておこうね。
even = 0
odd = 0
for i in range(N):
    if A[i]%2 == 0:
        even += 1
    else:
        odd += 1

if P == 0: #偶数を探すよ。
    #奇数を偶数個
    odds = 0
    for i in range(odd+1):
        if i % 2 == 0:
            odds += math.factorial(odd)/(math.factorial(i)*math.factorial(odd-i))
    #偶数を何個でも
    evens = 0
    for i in range(even+1):
        evens += math.factorial(even)/(math.factorial(i)*math.factorial(even-i))

elif P == 1: #奇数を探そう。
    #奇数を奇数個
    odds = 0
    for i in range(odd+1):
        if i % 2 != 0:
            odds += math.factorial(odd)/(math.factorial(i)*math.factorial(odd-i))
    #偶数を何個でも
    evens = 0
    for i in range(even+1):
        evens += math.factorial(even)/(math.factorial(i)*math.factorial(even-i))


print(int(odds*evens))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,P,*A=map(int,open(0).read().split())
print([(1^P)*2**N,2**~-N][any(a&1 for a in A)])

Submission status: Accepted

Solution code:
N, P, *A = map(int, open(0).read().split())
e, o = 1, 0
for a in A:
    if a % 2:
        e, o = e + o, e + o
    else:
        e, o = 2 * e, 2 * o
print([e, o][P])