from itertools import combinations
from math import prod

def ok(cs):
    n = len(cs)
    for i in range(0, n - 1, 2):
        if cs[i] % 2 == 1 or cs[i + 1] % 2 == 0:
            return False
    if cs[-1] % 2 == 1:
        return False
    return True

def sum_of_prods(xs):
    n = len(xs)
    ans = 0
    for k in range(1, n + 1, 2):
        for cs in combinations(range(n), r=k):
            if ok(cs):
                print(cs)
                ans += prod([xs[i] for i in cs])
    return ans

print(sum_of_prods(([1,2,5])))
print(sum_of_prods(([2,4,6,8,10])))

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: