eolymp
bolt
Try our new interface for solving problems
Problems

Beautiful Permutation

Beautiful Permutation

Consider a permutation of integer numbers from \textbf{1} to \textbf{n}. Let us call length of the longest monotonic subsequence of the permutation its \textit{ugliness}. For example, the ugliness of the permutation <\textbf{1}, \textbf{2}, \textbf{5}, \textbf{3}, \textbf{4}> is \textbf{4} because it has a monotonic subsequence (\textbf{1}, \textbf{2}, \textbf{3},\textbf{4}) of length \textbf{4}, but has none of length \textbf{5}. The ugliness of the permutation <\textbf{5}, \textbf{6}, \textbf{3}, \textbf{4}, \textbf{1}, \textbf{2}> is \textbf{3} because it has a monotonic subsequence (\textbf{5}, \textbf{3}, \textbf{1}) of length \textbf{3}. Let us call \textit{beautiful} those permutations that have a smallest possible ugliness for given \textbf{n}. Given \textbf{n}, you must find the first in lexicographic order beautiful permutation of size \textbf{n}. \InputFile Input file contains \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{10000}). \OutputFile Output the first in lexicographic order beautiful permutation of size \textbf{n}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
1
Output example #1
1
Source Russian Teams Training Sessions in Petrozavodsk, Summer 2004, Andrew Stankevich Contest 8, Thursday, August 26, 2004