from itertools import combinations input = [32, 37, 41, 42, 45, 49, 50, 51, 17, 54, 55, 28, 62] MAX = 249 table = list(combinations(input, 2)) + list(combinations(input, 3)) + list(combinations(input, 4)) + list(combinations(input, 5)) + list(combinations(input, 6)) + list(combinations(input, 7)) ctr = 0 for i in table: if sum(i) <= MAX: ctr += 1 print(ctr)