{"problem":{"name":"Previous Permutation","description":{"content":"You are given a permutation $P = (P_1, \\dots, P_N)$ of $(1, \\dots, N)$, where $(P_1, \\dots, P_N) \\neq (1, \\dots, N)$. Assume that $P$ is the $K$\\-th lexicographically smallest among all permutations o","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc276_c"},"statements":[{"statement_type":"Markdown","content":"You are given a permutation $P = (P_1, \\dots, P_N)$ of $(1, \\dots, N)$, where $(P_1, \\dots, P_N) \\neq (1, \\dots, N)$.\nAssume that $P$ is the $K$\\-th lexicographically smallest among all permutations of $(1 \\dots, N)$. Find the $(K-1)$\\-th lexicographically smallest permutation.\nWhat are permutations?A **permutation** of $(1, \\dots, N)$ is an arrangement of $(1, \\dots, N)$ into a sequence.\nWhat is lexicographical order?For sequences of length $N$, $A = (A_1, \\dots, A_N)$ and $B = (B_1, \\dots, B_N)$, $A$ is said to be **strictly lexicographically smaller** than $B$ if and only if there is an integer $1 \\leq i \\leq N$ that satisfies both of the following.\n\n*   $(A_{1},\\ldots,A_{i-1}) = (B_1,\\ldots,B_{i-1}).$\n*   $A_i < B_i$.\n\n## Constraints\n\n*   $2 \\leq N \\leq 100$\n*   $1 \\leq P_i \\leq N \\, (1 \\leq i \\leq N)$\n*   $P_i \\neq P_j \\, (i \\neq j)$\n*   $(P_1, \\dots, P_N) \\neq (1, \\dots, N)$\n*   All values in the input are integers.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$\n$P_1$ $\\ldots$ $P_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc276_c","tags":[],"sample_group":[["3\n3 1 2","2 3 1\n\nHere are the permutations of $(1, 2, 3)$ in ascending lexicographical order.\n\n*   $(1, 2, 3)$\n*   $(1, 3, 2)$\n*   $(2, 1, 3)$\n*   $(2, 3, 1)$\n*   $(3, 1, 2)$\n*   $(3, 2, 1)$\n\nTherefore, $P = (3, 1, 2)$ is the fifth smallest, so the sought permutation, which is the fourth smallest $(5 - 1 = 4)$, is $(2, 3, 1)$."],["10\n9 8 6 5 10 3 1 2 4 7","9 8 6 5 10 2 7 4 3 1"]],"created_at":"2026-03-03 11:01:13"}}