PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000152. Số nhỏ nhất có các chữ số khác nhau (Minimum Varied Number)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Số nhỏ nhất có các chữ số khác nhau (Minimum Varied Number)

Minimum Varied Number

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Find the smallest positive integer whose decimal digits are pairwise distinct and whose digit sum equals a given integer ss. Every ss in the input range has at least one answer.

Input

The input contains one integer ss.

Output

Print the minimum positive integer with pairwise distinct decimal digits and digit sum ss.

Subtasks

  • Subtask 1 (20 points): 1≤s≤201\le s\le20.
  • Subtask 2 (30 points): 1≤s≤351\le s\le35.
  • Subtask 3 (50 points): 1≤s≤451\le s\le45.

Examples

Input

20

Output

389

Explanation

The number 389389 has digit sum 3+8+9=203+8+9=20 and distinct digits. No one- or two-digit number with distinct digits can have digit sum 2020, and 389389 is the smallest feasible three-digit number.