import itertools input = 1881 liste = [12, 24, 31, 77, 87, 103, 112, 145, 181, 197, 205, 217, 224, 225, 228, 255, 263, 278, 289, 297] for i in range(2, len(liste)): r = itertools.combinations(liste, i) for j in r: if sum(j) == input: print(j) break