def solve(): n=ii() arr=li() p=[] for a,b in enumerate(arr): p.append((b,a)) p.sort(reverse=True) #print(p) ans=[] s=sum(arr) for x in range(n): if x==n-1: if s==p[x][0]: ans.append(p[x][1]+1) else: s-=p[x][0] if s<p[x][0]: ans.append(p[x][1]+1) break else: ans.append(p[x][1]+1) ans.sort() print(len(ans)) print(*ans)
string, num = input().split() from itertools import permutations permutations = list(permutations(string, int(num))) permutations.sort() permutations = set(permutations) [print("".join(i)) for i in permutations]
from itertools import permutations numbers = [''.join([str(i) for i in range(1, j)]) for j in range(11)] permutations = [[''.join(p) for p in list(permutations(n)) if p != ''] for n in numbers] permutations = [int(p) for row in permutations for p in row if p.strip() != ''] permutations.sort(reverse=True) idx = 0 while idx < len(permutations): is_prime = True for i in range(2, int(permutations[idx] / 2)): if permutations[idx] % i == 0: is_prime = False break if is_prime: print(permutations[idx], 'is prime') break else: print(permutations[idx]) idx += 1