
뭔가 수학적으로 엄청 복잡해 보이는 문제지만 파이썬의 문자열과 combinations 라이브러리를 이용하면 엄청나게 쉽게 구할 수 있다.
파이썬 조합 라이브러리를 이용해서 숫자 범위 내 모든 조합을 구한 후 그걸 역전시키면 그게 감수하는 수이기 때문이다.
(조합 라이브러리 사용하면 오름차순의 집합모양으로 결과값이 나오게 된다.)
모든 감수하는 수를 구한 후 입력값에 맞는 값 출력하면 끝ㅋ
import sys
from itertools import combinations
input=sys.stdin.readline
n=int(input())
ar=list()
for i in range(1,11):
for j in combinations(range(0,10),i): #모든 감수하는수 구하기
j=list(j)
j.sort(reverse=True)
ar.append(int("".join(map(str,j))))
ar.sort()
try:
print(ar[n])
except: # 인덱스가 넘어가는 경우 -1 출력. 마지막 수 9876543210
print(-1)