TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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?

Submission attempts (in order):
from collections import Counter
import itertools
import math

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

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

# print(d)

zeros = 2 ** d[0]


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




print(zeros * ones)


from collections import Counter
import itertools
import math

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

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

# print(d)

zeros = 2 ** d[0]


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




print(zeros * ones)


Verdicts: Wrong Answer

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

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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
from operator import mul
from functools import reduce


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

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

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

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


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

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

from operator import mul
from functools import reduce


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

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

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

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


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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
import math

def cc(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()))
o = 0
e = 0
s = 0
for i in a:
  if i%2:
    o += 1
  else:
    e += 1
if p:
  for j in range(1,o,2):
    s += cc(o, j)
else:
  for k in range(0,o,2):
    s += cc(o, k)
print(s*2**e)
  

import math

def cc(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()))
o = 0
e = 0
s = 0
for i in a:
  if i%2:
    o += 1
  else:
    e += 1
if p:
  for j in range(1,o+1,2):
    s += cc(o, j)
else:
  for k in range(0,o+1,2):
    s += cc(o, k)
print(s*2**e)
  


Verdicts: Wrong Answer

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

Submission attempts (in order):
n,p=map(int,input().split())
a=list(map(int,input().split()))
print(2**(N-1))

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

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

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

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

    


Verdicts: Runtime Error

Wrong Answer

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

Submission attempts (in order):
n, p = map(int, input().split())
a = list(map(int, input().split()))

odd = 0
even = 0

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

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

odd = 0
even = 0

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

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

odd = 0
even = 0

for i in a:
    if 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))

Verdicts: Runtime Error

Runtime Error

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

Submission attempts (in order):
import math
def ncr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
n,p=map(int,input().split())
a=list(map(int,input().split()))
odd=0
even=0

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

if p==1:
    ans=2**even
    odd_choice=0
    for i in range(1,odd+1,2):
        odd_choice+=ncr(odd,i)
    print(ans*odd_choice if even!=0 else odd_choice)

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

import math
def ncr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
n,p=map(int,input().split())
a=list(map(int,input().split()))
odd=0
even=0

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

if p==1:
    ans=2**even
    odd_choice=0
    for i in range(1,odd+1,2):
        odd_choice+=ncr(odd,i)
    print(ans*odd_choice if even!=0 else odd_choice)

else:
    ans=2**even
    if even==0:
        ans=0
    odd_choice=0
    for i in range(0,odd+1,2):
        odd_choice+=ncr(odd,i)
    print(ans*odd_choice if even!=0 else odd_choice)

Verdicts: Wrong Answer

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

Submission attempts (in order):
def comb(n,k):
    nCk = 1
    MOD = 10**9+7

    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk
n,p=map(int,input().split())
a=list(map(lambda x:int(x)%2,input().split()))
on=a.count(1)
ze=a.count(0)
print(on,ze)
ans=0
if on==0:
    if p==0:
        print(2**n)
        exit()
    if p==1:
        print(0)
        exit()
    
print(2**(n-1))

n,p=map(int,input().split())
a=list(map(lambda x:int(x)%2,input().split()))
on=a.count(1)
ze=a.count(0)
ans=0
if on==0:
    if p==0:
        print(2**n)
        exit()
    if p==1:
        print(0)
        exit()
    
print(2**(n-1))

Verdicts: Wrong Answer

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

Submission attempts (in order):
n, p = map(int, input().split())

a = list(input())

if p == 1:
    print(0)

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

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


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

a = list(input())

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

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

else:
    print(0)


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

a = list(input())

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

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

else:
    print(0)


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)


Verdicts: Wrong Answer

Runtime Error

Runtime Error

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

Submission attempts (in order):
N,P = map(int,input().split())
A = list(map(int,input().split()))

A = [a % 2 for a in A]

acc = [1] * 60
for i in range(60):
  if i == 0:
    continue
  acc[i] = acc[i-1] * i

odd = sum(A)
even = N - odd

ans = 0
if P == 0:
  
  j = 0
  for i in range(0,odd,2):
    j += acc[odd] // (acc[odd-i] * acc[i])
  
else:
  
  j = 0
  for i in range(1,odd,2):
    j += acc[odd] // (acc[odd-i] * acc[i])
  
ans = 0
for i in range(even):
  k = acc[even] // (acc[even-i] * acc[i])
  ans += k * j
  
print(ans)
                        

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

A = [a % 2 for a in A]

acc = [1] * 60
for i in range(60):
  if i == 0:
    continue
  acc[i] = acc[i-1] * i

odd = sum(A)
even = N - odd

ans = 0
if P == 0:
  
  j = 0
  for i in range(0,odd+1,2):
    j += acc[odd] // (acc[odd-i] * acc[i])
  
else:
  
  j = 0
  for i in range(1,odd+1,2):
    j += acc[odd] // (acc[odd-i] * acc[i])
  
ans = 0
for i in range(even):
  k = acc[even] // (acc[even-i] * acc[i])
  ans += k * j
  
print(ans)
                        


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

A = [a % 2 for a in A]

acc = [1] * 60
for i in range(60):
  if i == 0:
    continue
  acc[i] = acc[i-1] * i

odd = sum(A)
even = N - odd

ans = 0
if P == 0:
  
  j = 0
  for i in range(0,odd+1,2):
    j += acc[odd] // (acc[odd-i] * acc[i])

else:
  
  j = 0
  for i in range(1,odd+1,2):
    j += acc[odd] // (acc[odd-i] * acc[i])
  
ans = 0
for i in range(even+1):
  k = acc[even] // (acc[even-i] * acc[i])
  ans += k * j
  
print(ans)
                        


Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
n,p = map(int,input().split())
a = list(map(int,input().split()))

s = [0]*n
for i in range(n):
    if a[i]%2 == 0:
        s[i] = 0
    else:
        s[i] = 1
import collections
c = collections.Counter(s)
odd  = c[1]
even = c[0]
x = 0
i = 0
while  2*i+p <= even:
    x += comb(even, i, exact=True)
    i += 1
from scipy.special import comb
ans = 0
i = 0
while  2*i+p <= odd:
    ans += comb(odd, 2*i+p, exact=True)*x
    i += 1
if p == 0:
    print(ans)
else:
    print(ans*2)

import math
def comb(n, r): #comb(int, int)
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n,p = map(int,input().split())
a = list(map(int,input().split()))
a_even = 0
a_odd = 0
for i in range(n):
    if a[i]%2 == 0:
        a_even += 1
    else:
        a_odd += 1
ans = 0
if p%2 == 0:
    k = 0
    for i in range(10**10):
        if 2*i > a_odd:
            break
        k += comb(a_odd, 2*i)
    print(k*2**a_even)
else:
    k = 0
    for i in range(10**10):
        if 2*i+1 > a_odd:
            break
        k += comb(a_odd, 2*i+1)
    print(k*2**a_even)

Verdicts: Runtime Error

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

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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
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))

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


Verdicts: Wrong Answer

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

Submission attempts (in order):
from scipy.misc import comb
N, P = map(int, input().split())
A = list(map(int, input().split()))
odd = 0
even = 0
for i in range(N):
    if A[i]%2 == 0:
        even += 1
    else:
        odd += 1
m = 0
if P == 0:
    for i in range(0,odd+1,2):
        m += int(comb(odd,i))
else:
    for i in range(1,odd+1,2):
        m += int(comb(odd,i))

print(m*(2**even))


from scipy.misc import comb
N, P = map(int, input().split())
A = list(map(int, input().split()))
odd = 0
even = 0
for i in range(N):
    if A[i]%2 == 0:
        even += 1
    else:
        odd += 1
m = 0
if P == 0:
    for i in range(0,odd+1,2):
        m += int(comb(odd,i))
else:
    for i in range(1,odd+1,2):
        m += int(comb(odd,i))

print(m*(2**even))


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

C = {(0,0):1}
def comb(n,k):
    if n == 0 or k == 0 or k == n:
        return 1
    else:
        if (n,k) in C:
            return C[(n,k)]
        else:
            C[(n,k)] = comb(n-1,k) + comb(n-1,k-1)
            return C[(n,k)]
m = 0
if P == 0:
    for i in range(0,odd+1,2):
        m += int(comb(odd,i))
else:
    for i in range(1,odd+1,2):
        m += int(comb(odd,i))
print(m*(2**even))


Verdicts: Wrong Answer

Wrong Answer

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

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

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

Verdicts: Runtime Error

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

Submission attempts (in order):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

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

n,m = inpl()
a = inpl()
odd = even = 0
for x in a:
    if x%2: odd += 1
    else: even += 1
res = pow(2,even)
ores = eres = 0
for i in range(odd):
    if i%2 == 0:
        eres += conb(odd,i)
    else:
        ores += conb(odd,i)
if m:
    print(ores*res)
else:
    print(eres*res)

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

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

n,m = inpl()
a = inpl()
odd = even = 0
for x in a:
    if x%2: odd += 1
    else: even += 1
res = pow(2,even)
ores = eres = 0
for i in range(odd+1):
    if i%2 == 0:
        eres += conb(odd,i)
    else:
        ores += conb(odd,i)
if m:
    print(ores*res)
else:
    print(eres*res)

Verdicts: Wrong Answer

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

Submission attempts (in order):
# 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()

# 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)
	else:
		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 = 1
	for i in range(1, n + 1):
		count += calcComb(n, i)
	return(int(count))

if __name__ == '__main__':
	main()

Verdicts: Wrong Answer

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

Submission attempts (in order):
import itertools
import math
from math import factorial

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


odd = 0
even = 0

for A in As:
    if(A % 2 == 0):
        even += 1
    else:
        odd += 1



even_combi = 0

for i in range(even+1):
    even_combi += math.factorial(even) // math.factorial(i) // math.factorial(even-i)

print(even_combi)





odd_combi = 0

if(P == 0):
    for i in range(0,odd + 1,2):
        odd_combi += math.factorial(odd) // math.factorial(i) // math.factorial(odd-i)

else:
    for i in range(1, odd + 1 , 2):
        odd_combi += math.factorial(odd) // math.factorial(i) // math.factorial(odd-(i))

print(odd_combi*even_combi)

import itertools
import math
from math import factorial

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


odd = 0
even = 0

for A in As:
    if(A % 2 == 0):
        even += 1
    else:
        odd += 1



even_combi = 0

for i in range(even+1):
    even_combi += math.factorial(even) // math.factorial(i) // math.factorial(even-i)

#print(even_combi)





odd_combi = 0

if(P == 0):
    for i in range(0,odd + 1,2):
        odd_combi += math.factorial(odd) // math.factorial(i) // math.factorial(odd-i)

else:
    for i in range(1, odd + 1 , 2):
        odd_combi += math.factorial(odd) // math.factorial(i) // math.factorial(odd-(i))

print(odd_combi*even_combi)

Verdicts: Wrong Answer

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

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

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

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

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

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

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

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

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

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

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

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

Submission attempts (in order):
print(2**int(input()[:2]))

i=int(input()[:2])-1;print((2**i,0)[i%2])

n,p,*a=map(int,open(0).read().split());print(2**~-n*(any(x%2for x in a)or(1^p)*2))

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, p, *a = map(int, read().split())
cnt_1 = 0
cnt_2 = 0
for i in a:
    if a[i] % 2 == 1:
        cnt_1 += 1
    else:
        cnt_2 += 1
ans = 2 ** max(0, cnt_1 - 1) * 2 ** cnt_2
if p == 1 and cnt_1 == 0:
    ans = 0
print(ans)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import defaultdict
from operator import mul
from functools import reduce


def nCr(n, r):
    if n < r:
        return 0
    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, readline().split())
a = list(map(lambda x: int(x) % 2, readline().split()))
dict = defaultdict(int)
for aa in a:
    dict[aa] += 1
memo = 2 ** dict[0]
ans = 0
if p == 0:
    ans += memo
    m = 2
else:
    m = 1
for i in range(m, dict[1] + 1, 2):
    ans += nCr(dict[1], i) * memo
print(ans)


Verdicts: Runtime Error

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

Submission attempts (in order):
def check(a):
    for i in a:
        if i%2:
            return True
    return False

n,p = map(int, input().split())
a = list(map(int,input().split()))
if check():
    print(2**(n-1))
elif p==0:
    print(2**n)
else:
    print(0)

def check(a):
    for i in a:
        if i%2:
            return True
    return False

n,p = map(int, input().split())
a = list(map(int,input().split()))
if check(a):
    print(2**(n-1))
elif p==0:
    print(2**n)
else:
    print(0)

Verdicts: Runtime Error

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

Submission attempts (in order):

import itertools

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

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

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


if P == 1:
    
    for i in range(1, len(odd)+1, 2):
        c += combinations_count(len(odd), i)
if P == 0:
    
    for i in range(0, len(odd)+1, 2):
        c += combinations_count(len(odd), i)
        
print(2 ** len(even) * c) 


import itertools
import math

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

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

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


if P == 1:
    
    for i in range(1, len(odd)+1, 2):
        c += combinations_count(len(odd), i)
if P == 0:
    
    for i in range(0, len(odd)+1, 2):
        c += combinations_count(len(odd), i)
        
print(2 ** len(even) * c) 

Verdicts: Runtime Error

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

Submission attempts (in order):
N,P= map(int, input().split())
A= list(map(int, input().split()))
A = [A[i] % 2 for i in range(N)] 
even = A.count(0)
odd = A.count(1)

anseven = 1
ansodd = 0

dic = {0:1}
for i in range(1, 51):
    dic[i] = dic[i - 1] * i


for i in range(1, even + 1):
    anseven += dic[even] // dic[even - i] // dic[i]

if P == 0:
    
    for i in range(2, odd + 1, 2):
        ansodd += dic[odd] // dic[odd - i] // dic[i]

else:
    if odd == 0:
        print(0)
        exit()
    
    for i in range(1, odd + 1, 2):
        ansodd += dic[odd] // dic[odd - i] // dic[i]

print(anseven * ansodd)

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

anseven = 1
ansodd = 1

dic = {0:1}
for i in range(1, 51):
    dic[i] = dic[i - 1] * i


for i in range(1, even + 1):
    anseven += dic[even] // dic[even - i] // dic[i]

if P == 0:
    
    for i in range(2, odd + 1, 2):
        ansodd += dic[odd] // dic[odd - i] // dic[i]

else:
    if odd == 0:
        print(0)
        exit()
    ansodd = 0
    
    for i in range(1, odd + 1, 2):
        ansodd += dic[odd] // dic[odd - i] // dic[i]

print(anseven * ansodd)

Verdicts: Wrong Answer

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

Submission attempts (in order):
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))
if p:
    print(0)
else:
    print(2 ** n)

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)

Verdicts: Wrong Answer

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

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

print( (2**zero) * (2**(max(0, one-1))) )


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

if one == 0 and P == 1:
    print(0)
else:
    print( (2**zero) * (2**(max(0, one-1))) )


Verdicts: Runtime Error

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

Submission attempts (in order):
#AGC017-A
from math import factorial
def nCr(n,r):
    return factorial(n) / factorial(r) / factorial(n - r)
n,p = map(int,input().split())
a = list(map(int,input().split()))
even = 0
odd = 0
for i in a:
    if i % 2 == 0:
        even += 1
    else:
        odd += 1


if p == 0:
    temp = 0
    for i in range(0,odd+1,2):
        print(i)
        temp += nCr(odd,i)
    print(int(2**even * temp))

else:
    temp = 0
    for i in range(1,odd+1,2):
        temp += nCr(odd,i)
    print(int(2**even * temp))

#AGC017-A
from math import factorial
def nCr(n,r):
    return factorial(n) / factorial(r) / factorial(n - r)
n,p = map(int,input().split())
a = list(map(int,input().split()))
even = 0
odd = 0
for i in a:
    if i % 2 == 0:
        even += 1
    else:
        odd += 1


if p == 0:
    temp = 0
    for i in range(0,odd+1,2):
        temp += nCr(odd,i)
    print(int(2**even * temp))

else:
    temp = 0
    for i in range(1,odd+1,2):
        temp += nCr(odd,i)
    print(int(2**even * temp))

Verdicts: Wrong Answer

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

Submission attempts (in order):
from scipy.special import comb
n, p, *A = map(int, open(0).read().split())
odd = sum(a%2 for a in A)
even = n - odd

if p:
  s = 0
  for i in range(1, odd, 2):
    s += comb(odd, i, exact=True)
  s *= pow(2, even)
  print(s)
else:
  s = 0
  for i in range(0, odd, 2):
    s += comb(odd, i, exact=True)
  s *= pow(2, even)
  print(s)

from scipy.special import comb
n, p, *A = map(int, open(0).read().split())
o = sum(a%2 for a in A)
e = n - o

s = 0
for i in range(p, o+1, 2):
  s += comb(o, i, exact=True)
s *= pow(2, e)
print(s)

Verdicts: Wrong Answer

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

Submission attempts (in order):
def nCr(n, r):
    ret = 1
    for i in range(1, n+1):
        ret *= i
    for i in range(1, r+1):
        ret //= i
    for i in range(1, n-r+1):
        ret //= i
    return ret

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

for i in a:
  if i & 1:
    odd += 1
  else:
    even += 1

c_even = 2**even
c_odd = 0

start = 1 if p else 0

while start <= odd:
    c_odd += nCr(odd, start)
    start += 2
print(c_even, c_odd)
print(c_even * c_odd)


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

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

for i in a:
  if i & 1:
    odd += 1
  else:
    even += 1

c_even = 2**even
c_odd = 0

start = 1 if p else 0

while start <= odd:
    c_odd += nCr(odd, start)
    start += 2

print(c_even * c_odd)

Verdicts: Wrong Answer

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

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

print(ans*tmp)


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

print(ans*tmp)

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

print(ans*tmp)


Verdicts: Wrong Answer

Runtime Error

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

Submission attempts (in order):
for i in a:
    if i%2==0:
        k +=1
m=n-k

ans_x=ans_y=0

def cbn(b,c):
    z=1
    for i in range(2,b+1):
        z *= i
    for i in range(2,c+1):
        z //= i
    for i in range(2,b-c+1):
        z //= i
    return(z)


if p==0:

    for i in range(k+1):
        ans_x += cbn(k,i)
    for i in range(0,m+1,2):
        ans_y += cbn(m,i)

    print(ans_x * ans_y)

else:

    for i in range(k+1):
        ans_x += cbn(k,i)
    for i in range(1,m+1,2):
        ans_y += cbn(m,i)

    print(ans_x * ans_y) 

n,p=map(int,input().split())
a=list(map(int,input().split()))
k=m=0
for i in a:
    if i%2==0:
        k +=1
m=n-k

ans_x=ans_y=0

def cbn(b,c):
    z=1
    for i in range(2,b+1):
        z *= i
    for i in range(2,c+1):
        z //= i
    for i in range(2,b-c+1):
        z //= i
    return(z)


if p==0:

    for i in range(k+1):
        ans_x += cbn(k,i)
    for i in range(0,m+1,2):
        ans_y += cbn(m,i)

    print(ans_x * ans_y)

else:

    for i in range(k+1):
        ans_x += cbn(k,i)
    for i in range(1,m+1,2):
        ans_y += cbn(m,i)

    print(ans_x * ans_y)    


Verdicts: Runtime Error

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

Submission attempts (in order):

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

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


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

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


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

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




Verdicts: Runtime Error

Wrong Answer

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

Submission attempts (in order):
import math
n, p, *a = map(int, open(0).read().split())


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


memo = [0, 0]
for i in range(n):
    memo[a[i] % 2] += 1
# p == 0


ans = 0
if p == 0:
    for i in range(0, memo[1], 2):
        ans += c(memo[1], i) * pow(2, memo[0])
else:
    for i in range(1, memo[1], 2):
        ans += c(memo[1], i) * pow(2, memo[0])
# p == 1
print(ans)


import math
n, p, *a = map(int, open(0).read().split())


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


memo = [0, 0]
for i in range(n):
    memo[a[i] % 2] += 1
# p == 0


ans = 0
if p == 0:
    for i in range(0, memo[1] + 1, 2):
        ans += c(memo[1], i) * pow(2, memo[0])
else:
    for i in range(1, memo[1] + 1, 2):
        ans += c(memo[1], i) * pow(2, memo[0])
# p == 1
print(ans)


Verdicts: Wrong Answer

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

Submission attempts (in order):
N, P = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
odd = [ tmp for tmp in a if tmp%2 != 0]
even = [ tmp for tmp in a if tmp%2 == 0]
if P == 0:
    ans += 1
    b = sum([ len(list(itertools.combinations(odd,tmp))) for tmp in range(2, len(odd)+1, 2) ])
else:
    b = sum([ len(list(itertools.combinations(odd,tmp))) for tmp in range(1, len(odd)+1, 2) ])
c = [ len(list(itertools.combinations(even, tmp))) for tmp in range(1, len(even)+1) ]
factor = 0
for tmp in c:
    ans += tmp*b
    factor += tmp
else:
    if P == 0:
        ans += b+factor
    else:
        ans += b
print(ans)

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

Verdicts: Runtime Error

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

Submission attempts (in order):
import math


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


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

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

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

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

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

    print(int(t_comb * f_comb))

    return 0


if __name__ == '__main__':
    main()


import math


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


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

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

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

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

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

    print(int(t_comb * f_comb))

    return 0


if __name__ == '__main__':
    main()


import math
 
 
def comb(n, r):
    return math.factorial(n) / math.factorial(r) / math.factorial(n - r)
 
 
def main():
    n, p = map(int, input().split())
    a = tuple(map(lambda x: int(x) % 2, input().split()))
 
    if n == 1 and a[0] % 2 != p:
        print(0)
        return 0
 
    t = len(tuple(filter(lambda x: x == 1, a)))
    f = n - t
 
    f_comb = 0
    for j in range(f + 1):
        f_comb += comb(f, j)
 
    t_comb = 0
    if p == 0:
        for i in range(t + 1):
            if i % 2 == 0:
                t_comb += comb(t, i)
    else:
        for i in range(t + 1):
            if i % 2 == 1:
                t_comb += comb(t, i)
 
    print(int(t_comb * f_comb))
 
    return 0
 
 
if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Wrong Answer

Accepted