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: Runtime Error

Solution code:
# 二項係数を"やるだけ"にしてくれるライブラリ
from collections import Counter
MAX = 1000005
MOD = 10**9+7
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()


N, P = map(int, input().split())  # 袋がN個, mod2をPにしたい
A = list(map(lambda x: int(x)%2, input().split()))
# print(A)

kisuu = sum(A)  # 奇数個の袋の数
guusuu = N-kisuu  # 偶数個の袋の数

# Pが1のとき，偶数側の袋を任意の数と，奇数側の数を奇数個選ぶ
if P == 1:
    aaa
    tmp_guusuu = 0
    tmp_kisuu = 0
    # 偶数側を任意の個数選ぶ
    for i in range(guusuu+1):
        tmp_guusuu += COM(guusuu, i)
    for i in range(kisuu+1):
        if i % 2 == 0:
            continue
        tmp_kisuu += COM(kisuu, i)
    print(tmp_guusuu*tmp_kisuu)

# Pが0のとき，偶数側の袋を任意の数と，奇数側の数を偶数個選ぶ
elif P == 0:
    tmp_guusuu = 0
    tmp_kisuu = 0
    # 偶数側を任意の個数選ぶ
    for i in range(guusuu+1):
        tmp_guusuu += COM(guusuu, i)
    # 奇数側を0個数以上の偶数個選ぶ
    for i in range(kisuu+1):
        if i % 2 == 1:
            continue
        tmp_kisuu += COM(kisuu, i)
    print(tmp_guusuu*tmp_kisuu)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

num_evens = len([a for a in as_ if a % 2 == 0])
num_odds = len([a for a in as_ if a % 2 == 1])

counts = 0
if p == 0:
    # 全部で偶数枚食べる = 偶数枚の袋 a 個 + 奇数枚の袋 b = 2k 個
    # 0袋食べる場合も OK.
    counts += 1
    # 1袋以上食べる場合
    for i in range(1, n + 1):
        # 全部で i 袋食べるとする i = 1 〜 n
        for a in range(i + 1):
            # そのうち偶数枚の袋を a 個食べる方法
            even_ways = comb(num_evens, a, exact=True)
            # 奇数枚の袋は (i - a) 個食べるが、それは偶数でなければならない
            b = (i - a)
            if b % 2 == 1 or b < 0:
                continue
            else:
                odd_ways = comb(num_odds, b, exact=True)

            counts += even_ways * odd_ways

else:
    # 全部で奇数枚食べる = 偶数枚の袋 a 個 + 奇数枚の袋 b = 2k + 1個 (k > 0)
    # 奇数の袋は0ではいけない (k > 0)
    # 0袋食べるのはダメ
    # 1袋以上食べる場合
    for i in range(1, n + 1):
        # 全部で i 袋食べるとする
        for b in range(1, i + 1):
            # 奇数枚の袋を b = 2k + 1 個食べる
            if b % 2 == 0:
                continue
            # すると偶数枚の袋は a = i - b 個食べる
            a = i - b
            if a < 0:
                continue

            odd_ways = comb(num_odds, b, exact=True)
            even_ways = comb(num_evens, a, exact=True)
            counts += even_ways * num_odds

print(counts)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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
#print(even,odd)

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

#print("0,0 = ", comb(0,0))

if P == 0:
    ans = 0
    for x in range(odd+2):
        #print(odd, x)
        if x % 2 == 0:
            ans += comb(odd,x)
    ans *= 2**even
    print(ans)
else:
    ans = 0
    for x in range(odd+1):
        if x % 2 == 1:
            if odd != 0:
                ans += comb(odd,x)
    ans *= 2**even
    print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque

nCr = {}


def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


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

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = cmb(one, c)
    right += tmp

print(2**zero * right)

Submission status: Runtime Error

Solution code:
from collections import deque
from functools import lru_cache

nCr = {}


@lru_cache(maxsize=None)
def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


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

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = cmb(one, c)
    right += tmp

print(2**zero * right)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
from collections import deque

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

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = comb(one, c, exact=True)
    right += tmp

print(2**zero * right)

Submission status: Runtime Error

Solution code:
#3問目
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)
#奇数グループは組み合わせの総数を出す
#もしP=1なら奇数グループから奇数個を出す組み合わせの数、P=0なら奇数グループから偶数個を出す組み合わせの数
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)

Submission status: Runtime Error

Solution code:
import math
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
ans = 0
if p == 0:
    ans += 1<<even
    i = 2
    while(i <= odd):
        ans += math.comb(odd, i)
        i+=2

    print(ans)

else:
    evens = 0
    i = 1
    while(i <= even):
        evens += math.comb(even, i)

        i+=1

    i = 1
    while(i <= odd):
        ans += math.comb(odd, i) + math.comb(odd, i)*evens

        i+=2
    print(ans)

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

Solution code:

  
  import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


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


def readstrs():
    return input().split()


N, P = readnums()
A = map(lambda x: x % 2, readnums())

if not sum(A):
    print(0)
else:
    print(2 ** N // 2)

Submission status: Runtime Error

Solution code:
odds=sum(A)
evens=N-odds 
if odds>0:
    ans=2**evens 
    ans*=2**(odds-1)
    print(ans)
else:
    if P==0:
        print(2**evens)
    else:
        print(0)

Submission status: Runtime Error

Solution code:
import math
def AGC017C(a,f):
    p=0
    for i in range(f,a,2):
        p+=math.factorial(a)//math.factorial(a-i)//math.factorial(i)
    return p

n,p=map(int,input().split())
d={1:0,0:0}
a=list(map(int,input().split()))
for i in a:
    d[i%2]+=1
if p==0:
    print((2**d[0])*AGC017C(d[1]),0)
else:
    if d[1]==0:
        print(0)
    else:
        print((2**d[0])*(AGC017C(d[1],1)))

Submission status: Runtime Error

Solution code:
import math
def AGC017C(a,f):
    p=0
    for i in range(f,a,2):
        p+=math.factorial(a)//math.factorial(a-i)//math.factorial(i)
    return p

n,p=map(int,input().split())
d={1:0,0:0}
a=list(map(int,input().split()))
for i in a:
    d[i%2]+=1
print(d)
print(AGC017C(2,0))
if p==0:
    print((2**d[0])*AGC017C(d[1]),0)
else:
    if d[1]==0:
        print(0)
    else:
        print((2**d[0])*(AGC017C(d[1],1)))

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

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
    if remainder == 0:
        print(n_pow(2, count[0]) + n_pow(2, count[1] - 1))
    else:
        print(n_pow(2, count[0] + count[1] - 1, 0))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

n = int(input())
a = list(map(int,input().split()))
ans = 0
b = []

for i in range(n):
    for j in range(i+1,n+1):
        b = a[i:j]
#        print(b)

        if sum(b) == 0:
            ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
lst = list(map(int,input().split()))
e,o = 0,0
for i in range(n):
    if lst[i]%2==0:
        e += 1
    else:
        o += 1

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

Submission status: Runtime Error

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

even_num=0
odd_num=0

for a in A:
    if a%2==0:
        even_num+=1
    else:
        odd_num+=1

ev_case = 2**even_num

from scipy.special import comb

res=0
for i in range(P,odd_num+1,2):
    res += comb(odd_num, i, exact=True)

print(ev_case*res)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N,P=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
odd = 0
even = 0
for i in A:
    if i%2 !=0:
        odd += 1
    else:
        even += 1

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

Submission status: Runtime Error

Solution code:
from sys import stdin
from math import factorial

n,p = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

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

guusu = 0
kisuu = 0

for i in li:
    if i%2 == 0:
        guusu += 1
    else:
        kisuu += 1

point = 0

if p == 0:
    for i in range(guusu//2+1):
        point += combinations_count(guusu,i*2)
    for j in range(kisuu//2+1):
        point += combinations_count(kisuu,i*2)
if p == 1:
    for i in range(guusu+1):
        for j in range(kisuu//2 if kisuu%2 == 0 else kisuu//2+1):
            point += combinations_count(guusu,i)*combinations_count(kisuu,j*2+1)

print(point)

Submission status: Runtime Error

Solution code:
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))) )

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;

int n, p;
ll memo[55][2];
int a[55];

ll dp(int pos, int o) {
	if (pos == n) return o==0;
	if (memo[pos][o] != -1) return memo[pos][o];
	return memo[pos][o] = dp(pos+1, o) + dp(pos+1, (o+a[pos])%2);
}

int main() {
	memset(memo, -1, sizeof memo);
	scanf("%d%d", &n, &p);
	for (int i=0 ; i<n ; i++) {
		scanf("%d", a+i);
	}
	printf("%lld\n", dp(0, p));
	return 0;
}

Submission status: Runtime Error

Solution code:
import math
a,b = map(int,input().split())
L = list(map(int,input().split()))
Le = [x for x in L if x%2 == 0]
Lo = [x for x in L if x%2 == 1]
#print(Le,Lo)
def nCr(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
    
if b == 0:
    ev = 0
    od = 1
    while ev <= len(Le)//2:
        ev += nCr(len(Le),ev)
        ev += 2
    while od <= len(Lo)+1:
        od += nCr(len(Lo),od)
        od += 2
elif b == 1:
    ev = 0
    od = 0
    while ev <= len(Le)//2:
        ev += nCr(len(Le),ev)
        ev += 2
    while od <= len(Lo)+1:
        od += nCr(len(Lo),od)
        od += 2
print(ev*od)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

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

s_even = 0
for i in range(even):
    s_even += comb(even, i+1, exact=True)

s_odd = 0
ans = 0
if p == 0:
    for i in range(odd)[1::2]:
        s_odd += comb(odd, i+1, exact=True)
        ans = max(1,s_even) * max(1,s_odd) + s_odd
else:
    for i in range(odd)[::2]:
        s_odd += comb(odd, i+1, exact=True)
        ans = max(1,s_even) * max(1,s_odd) + s_odd

print(ans)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

odd = []
even = []

#偶奇わけ
for _a in a:
        if _a%2 == 0:
                even.append(_a)
        else:
                odd.append(_a)

lenE = len(even)
lenO = len(odd)

totalE = 0
totalO = 0
for i in range(1, lenE+1):
        totalE += comb(lenE, i)


if p == 0:
        #偶数
        ans += 1
        for i in range(1, lenO+1):
                if i%2 == 0:
                        totalO += comb(lenO, i)
        ans += totalO + totalE + totalE*totalO
        print(int(ans))
elif p == 1:
        #奇数
        for i in range(1, lenO+1):
                if i%2 != 0:
                        totalO += comb(lenO, i)

        ans += totalO*totalE
        print(int(ans))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N,P=map(int,input().split())
A=list(map(int,input().split()))
A=[i%2 for i in A]
A0,A1=A.count(0),A.count(1)
if P==1:
    if not A1:
        print(0)
        exit()
value0=0
for i in range(0,A0+1):
    value0+=comb(A0, i, exact=True)
value1=0
for i in range(2-P,A1+1,2):
    value1+=comb(A1, i, exact=True)
print(value0*value1+(1 if not P else 0))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N,P=map(int,input().split())
A=list(map(lambda x:int(x)%2,input().split()))
A0,A1=A.count(0),A.count(1)
if P==1:
    if not A1:
        print(0)
        exit()
value0=0
for i in range(0,A0+1):
    value0+=comb(A0, i, exact=True)
value1=0
for i in range(2-P,A1+1,2):
    value1+=comb(A1, i, exact=True)
print(value0*value1+(1 if not P else 0))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N,P=map(int,input().split())
A=list(map(lambda x:int(x)%2,input().split()))
A0,A1=A.count(0),A.count(1)
if P==1:
    if not A1:
        print(0)
        exit()
value0=0
for i in range(0,A0+1):
    #print(value0)
    value0+=comb(A0, i, exact=True)
value1=0
for i in range(2-P,A1+1,2):
    #print(value1,i)
    #print(comb(A1, i, exact=True))
    value1+=comb(A1, i, exact=True)
print(value0*value1+(1 if not P else 0))

Submission status: Runtime Error

Solution code:
a,b = [int(i) for i in input().split()]

l = [int(i) for i in input().split()]

l2 = [i for i in l if i %2 == 1]

if not l2 :
    print(2**n if b == 0 else 0)
else:
    print(2**(a-1))

Submission status: Runtime Error

Solution code:
N,P=map(int,input().split())
L=list(map(int,input().split()))
for q in range(N):
  L[q]=L[q]%2
s=0
if P==0:
  s+=1
for i in range(N):
  m=L[i]
  for j in range(i+1,N):
    for k in range(j,N+1):
      m+=L[k]
  i+=1
print(s)

Submission status: Runtime Error

Solution code:
from math import factorial as f
n,p,*a=map(int,open(0).read().split())
x=len([i for i in a if i%2])
y=n-x

xx=0
for i in range(p,x,2):
    xx+=f(x)//f(i)//f(x-i)

yy=0
for i in range(0,y):
    yy+=f(y)//f(i)//f(y-i)

if x>0 and y>0:
    print(xx*yy+xx*(p^0)+yy*(p^1))
elif x==0:
    print(yy(p^1))
else:
    print(xx)

Submission status: Runtime Error

Solution code:
n,p=map(int, input().split())
a=list(map(int, input().split()))
total=sum( n%2 for i in a )

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

odd = sum(x&1 for x in A)

if odd:
  # どちらも半分ずつ
  answer = 2**(N-1)
else:
  answer = (2 ** N) * P

print(answer)

Submission status: Runtime Error

Solution code:
num_bags, congr_factor = list(map(int, input().split()))
bags = list(map(int, input().split()))
odd = len([a for a in bags if (a % 2 == 1]))

if congr_factor == 0 and odd == 0:
  print(2 ** num_bags)
elif congr_factor == 1 and odd == 0:
  print(0)
else:
  print(2 ** (num_bags-1))

Submission status: Runtime Error

Solution code:
num_bags, congr_factor = list(map(int, input().split()))
bags = list(map(int, input().split()))
odd_bags = len([bag for bag in bags if (bag % 2 == 1]))

if congr_factor == 0 and odd == 0:
  print(2 ** num_bags)
elif congr_factor == 1 and odd == 0:
  print(0)
else:
  print(2 ** (num_bags-1))

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,p=map(int,input().split())
a = list(map(int,input().split()))
for a_ in a:
    if not a_%2==0:
        k=1
        break
if k:
    print(1<<(n-1))
else:
    print(0) if p==1 else print(1<<n)

Submission status: Runtime Error

Solution code:
import math
def ncr(n,r):
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
n,p=map(int,input().split())
l=list(map(int,input().split()))
l1=[]
l2=[]
for i in l:
  if i%2==0:
    l1.append(i)
  else:
    l2.append(i)
c=0
su=0
le1=len(l1)
le2=len(l2)
while True:
  if le1+le2<c:
    break
  if c%2==0:
    if le1+le2>=c:
      su+=ncr(le1+le2,c)
    c+=1
  else:
    if le1>=c:
      su+=ncr(le1,c)
    c+=1
if p==0:
  print(su)
else:
  dkafj;lsjfal;

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N, P = map(int,input().split())
A = list(map(int,input().split()))

odd = 0
even= 0

res = 0

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

'''
if P==0:
    res += 1
    if odd >= 2:
        odd -= 2
        res += uoo(odd)
    if even >= 1:
        res += 2**even
'''


evensum = 0
oddsum = 0

if P == 0: 
    # odd 
    for i in range(2,odd+1,2):
        oddsum += comb(odd, i)
    # even
    for i in range(1,even+1):
        evensum += comb(even, i)
    res = oddsum + evensum

# P == 1
else: 
    # odd
    if odd >= 1:
        for i in range(1,odd+1,2):
            oddsum += comb(odd, i)
        res += 1
    # even
    #if even >= 1:

    for i in range(1,even+1):
        evensum += comb(even, i)
    res += oddsum * evensum



print(int(res))

Submission status: Runtime Error

Solution code:
import collections, scipy.special 
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.special.comb(one, i, exact=True)

print(ans)

Submission status: Runtime Error

Solution code:
import collections, scipy.special 
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, 2):
    ans += 2 ** zero * scipy.special.comb(one, i, exact=True)

print(ans)

Submission status: Runtime Error

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 = 0L
    O_count = 0L
    for i in range(N):
        if int(input_raw[i]) % 2 == 0:
            E_count += 1L
        else:
            O_count += 1L

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

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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
    break
if c=1:print(2**(n-1))
else:
  if p=0:print(2**(n))
  else:print(0)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
 asdf1 (Guest) 
コンテスト時間: 2017-07-09(日) 21:00 ~ 2017-07-09(日) 23:00 AtCoderホームへ戻る
 トップ
 問題
 質問
 提出
 提出一覧
 順位表
 コードテスト
 解説
コードテスト
言語
C++14 (GCC 5.4.1)
ソースコード

Submission status: Runtime Error

Solution code:
from sys import stdin

n, p = map(int, stdin.readline().split(' '))
a = map(int, stdin.readline().split(' '))

dp = [ [[None] * (n + 1)], [[None] * (n + 1)] ]
dp[p][n] = 1
dp[1-p][n] = 0
for i in xrange(n-1, -1, -1):
   for k in [0,1]: dp[k][i] = dp[k][i+1] + dp[(k+a[i])%2][i+1]

#print dp

res = dp[0][0]

print res

Submission status: Runtime Error

Solution code:
tmp = list(map(int,input().split()))
As = list(map(int,input().split()))
n,p = tmp[0],tmp[1]
o ,e  = 0,0
for i in range(n):
  if As[i] % 2:
    o += 1
  else:
    e += 1
def comb(j,k):
  if k == 1:
    return(j)
  else:
    return comb(j-1,k-1) * j / k
ans = 0
if p == 0:
  for i in range(o+1):
    if not i % 2:
      ans += int(comb(o,i))
else:
  for i in range(o+1):
    if i % 2:
      ans += int(comb(o,i))
ans *= (2 ** e)
print(ans)

Submission status: Runtime Error

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

    editorial(N, P, A)

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

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n,p=map(int,input().split())
a=list(map(int,input().split()))
print(2**(N-1))

Submission status: Runtime Error

Solution code:
,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))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

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)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
N,A,B,C,D = map(int,input().split())
if N > 30 and D > 1:
	flag = 10 **9
else:
	flag = pow(D,N -1)
B -= A
if N % 2 == 1:
	if (B % (C + D) <= (N - 1) * (D - C) / 2 or abs(B % (C + D) - (C + D)) <= (N - 1) * (D - C) / 2) and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")
else:
	if abs(B % (C + D) - (D + C) / 2) <= (N - 1) * (D - C) / 2 and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
import numpy as np
hoge = input()
N,A,B,C,D = list(map(int,hoge.split(" ")))
k = np.abs(B-A)//D
l = np.abs(B-A)%D
times = k + 2 * np.ceil (l/ (D-C))
if times > N-2:
    print("NO")
else:
    print("YES")

Submission status: Runtime Error

Solution code:
hoge = input()
N,A,B,C,D = list(map(int,hoge.split(" ")))
k = np.abs(B-A)//D
l = np.abs(B-A)%D
times = k + 2 * np.ceil (l/ (D-C))
if times > N-2:
    print("NO")
else:
    print("YES")