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 = []
even = []
for i, aa in enumerate(a):
    if aa % 2 == 0:
        even.append(aa)
    else:
        odd.append(aa)
e = len(even)
o = len(odd)
ans = 2 ** e
od_list = [0]
bunsi = 1
bunbo = 1

for i in range(1,o):
    bunsi *= o - i + 1
    bunbo *= i
    od_list.append(bunsi//bunbo)
even_i = od_list[::2]
odd_i = od_list[1::2]
if p == 0:
    print(ans * sum(even_i))
else:
    print(ans * sum(odd_i))


    

import sys
from math import factorial
def main():
    packages, remainder = receiveInputData()

    packages.countOddAndEven()

    even_ways = packages.calculateEvenWays()
    odd_ways_remainder0, odd_ways_remainder1 = packages.calculateOddWays()

    if remainder.isZero():
        print(even_ways * odd_ways_remainder0)
        return

    print(even_ways * odd_ways_remainder1)






class Package():
    def __init__(self, packages_list, packages_num):
        if not isinstance(packages_list, list):
            print('Package Class argument error')
            sys.exit(1)

        
        if packages_num < 1 or packages_num > 50:
            print('Package Class Restriction error')
            print(packages_num)
            sys.exit(1)

        self.packages = packages_list
        self.packages_num = packages_num

    
    def countOddAndEven(self):
        self.packages_num_of_odd_biscuits  = 0
        self.packages_num_of_even_biscuits = 0
        for pack_i, biscuits_num in enumerate(self.packages):
            if biscuits_num % 2 == 0:
                self.packages_num_of_even_biscuits += 1
            else:
                self.packages_num_of_odd_biscuits += 1
        print(self.packages_num_of_odd_biscuits)

    
    
    
    def calculateEvenWays(self):
        return 2 ** self.packages_num_of_even_biscuits

    def calculateOddWays(self):
        count_combination_list = self.calculateCombination(self.packages_num_of_odd_biscuits)

        
        
        selected_even_odds = sum(count_combination_list[::2])

        
        
        selected_odd_odds = sum(count_combination_list[1::2])

        return selected_even_odds, selected_odd_odds

    def calculateCombination(self,n):
        
        select_ways_of_odd = [1]
        for select_num in range(1,n + 1):
            n_C_i = factorial(n) // (factorial(select_num) * factorial(n - select_num))
            select_ways_of_odd.append(n_C_i)
        return select_ways_of_odd











class Remainder():
    def __init__(self, remainder_0or1):
        if not isinstance(remainder_0or1, int):
            print('Remainder Class argument error')
            sys.exit(1)

        
        if remainder_0or1 != 0 and remainder_0or1 != 1:
            print('Remainder Class Restriction error')
            sys.exit(1)

        self.remainder = remainder_0or1


    def isZero(self):
        if self.remainder == 0:
            return True
        return False


def receiveInputData():

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

    return Package(A, N), Remainder(P)

if __name__ == '__main__':
    main()


import sys
from math import factorial
def main():
    packages, remainder = receiveInputData()

    packages.countOddAndEven()

    even_ways = packages.calculateEvenWays()
    odd_ways_remainder0, odd_ways_remainder1 = packages.calculateOddWays()

    if remainder.isZero():
        print(even_ways * odd_ways_remainder0)
        return

    print(even_ways * odd_ways_remainder1)






class Package():
    def __init__(self, packages_list, packages_num):
        if not isinstance(packages_list, list):
            print('Package Class argument error')
            sys.exit(1)

        
        if packages_num < 1 or packages_num > 50:
            print('Package Class Restriction error')
            print(packages_num)
            sys.exit(1)

        self.packages = packages_list
        self.packages_num = packages_num

    
    def countOddAndEven(self):
        self.packages_num_of_odd_biscuits  = 0
        self.packages_num_of_even_biscuits = 0
        for pack_i, biscuits_num in enumerate(self.packages):
            if biscuits_num % 2 == 0:
                self.packages_num_of_even_biscuits += 1
            else:
                self.packages_num_of_odd_biscuits += 1

    
    
    
    def calculateEvenWays(self):
        return 2 ** self.packages_num_of_even_biscuits

    def calculateOddWays(self):
        count_combination_list = self.calculateCombination(self.packages_num_of_odd_biscuits)

        
        
        selected_even_odds = sum(count_combination_list[::2])

        
        
        selected_odd_odds = sum(count_combination_list[1::2])

        return selected_even_odds, selected_odd_odds

    def calculateCombination(self,n):
        
        select_ways_of_odd = [1]
        for select_num in range(1,n + 1):
            n_C_i = factorial(n) // (factorial(select_num) * factorial(n - select_num))
            select_ways_of_odd.append(n_C_i)
        return select_ways_of_odd











class Remainder():
    def __init__(self, remainder_0or1):
        if not isinstance(remainder_0or1, int):
            print('Remainder Class argument error')
            sys.exit(1)

        
        if remainder_0or1 != 0 and remainder_0or1 != 1:
            print('Remainder Class Restriction error')
            sys.exit(1)

        self.remainder = remainder_0or1


    def isZero(self):
        if self.remainder == 0:
            return True
        return False


def receiveInputData():

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

    return Package(A, N), Remainder(P)

if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Wrong Answer

Accepted