from itertools import permutations def task2() -> None: x = list(range(1, 17)) for perm in permutations(x): if ( perm[0] + perm[4] == 19 and perm[1] + perm[5] == 17 and perm[2] + perm[6] == 12 and perm[3] + perm[7] == 18 and perm[8] + perm[12] == 8 and perm[9] + perm[13] == 31 and perm[10] + perm[14] == 16 and perm[11] + perm[15] == 15 ): print(perm) def main() -> None: task2() if __name__ == "__main__": main()