with open("input") as f: jars = [int(n) for n in f.readlines()] jars.sort(reverse=True) def count_remaining_combinations(remaining_eggnog, remaining_jars): if remaining_eggnog == 0: return 1 if remaining_eggnog < 0: return 0 if len(remaining_jars) == 0: return 0 count = 0 for idx, jar in enumerate(remaining_jars): count += count_remaining_combinations( remaining_eggnog - jar, remaining_jars[idx + 1 :] ) return count print(count_remaining_combinations(150, jars))