1031: Previous Permutation

Memory Limit:1024 MB Time Limit:2.000 S
Judge Style:Text Compare Creator:
Submit:15 Solved:10

Description

You are given a permutation lns="http://www.w3.org/1998/Math/MathML">=(1,,) of lns="http://www.w3.org/1998/Math/MathML">(1,,), where lns="http://www.w3.org/1998/Math/MathML">(1,,)(1,,).

Assume that lns="http://www.w3.org/1998/Math/MathML"> is the lns="http://www.w3.org/1998/Math/MathML">-th lexicographically smallest among all permutations of lns="http://www.w3.org/1998/Math/MathML">(1,). Find the lns="http://www.w3.org/1998/Math/MathML">(1)-th lexicographically smallest permutation.

Input

The input is given from Standard Input in the following format:

 lns="http://www.w3.org/1998/Math/MathML"> lns="http://www.w3.org/1998/Math/MathML">

  • lns="http://www.w3.org/1998/Math/MathML">1(1)
  • lns="http://www.w3.org/1998/Math/MathML">()
  • lns="http://www.w3.org/1998/Math/MathML">(1,,)(1,,)
  • All values in the input are integers.


Output

Let lns="http://www.w3.org/1998/Math/MathML">=(1,,) be the sought permutation. Print lns="http://www.w3.org/1998/Math/MathML">1,, in a single line in this order, separated by spaces.

Sample Input Copy

3
3 1 2

Sample Output Copy

2 3 1

HINT

Here are the permutations of lns="http://www.w3.org/1998/Math/MathML">(1,2,3) in ascending lexicographical order.

  • lns="http://www.w3.org/1998/Math/MathML">(1,2,3)
  • lns="http://www.w3.org/1998/Math/MathML">(1,3,2)
  • lns="http://www.w3.org/1998/Math/MathML">(2,1,3)
  • lns="http://www.w3.org/1998/Math/MathML">(2,3,1)
  • lns="http://www.w3.org/1998/Math/MathML">(3,1,2)
  • lns="http://www.w3.org/1998/Math/MathML">(3,2,1)

Therefore, lns="http://www.w3.org/1998/Math/MathML">=(3,1,2) is the fifth smallest, so the sought permutation, which is the fourth smallest lns="http://www.w3.org/1998/Math/MathML">(51=4), is lns="http://www.w3.org/1998/Math/MathML">(2,3,1).