{"raw_statement":[{"iden":"problem statement","content":"Given is a permutation $p_1,\\dots,p_n$ of $1,\\dots,n$. On this permutation, you can do the operations below any number of times in any order.\n\n*   Reverse the entire permutation. That is, rearrange $p_1,p_2,\\dots,p_n$ to $p_n,p_{n-1},\\dots,p_1$.\n*   Move the term at the beginning to the end. That is, rearrange $p_1,p_2,\\dots,p_n$ to $p_2,\\dots, p_n, p_1$.\n\nFind the minimum number of operations needed to sort the permutation in ascending order. In the given input, it is guaranteed that these operations can sort the permutation in ascending order."},{"iden":"constraints","content":"*   $2 \\leq n \\leq 10^5$\n*   $p_1,\\dots,p_n$ is a permutation of $1,\\dots,n$.\n*   The operations in Problem Statement can sort $p_1,\\dots,p_n$ in ascending order."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$n$\n$p_1$ $\\dots$ $p_n$"},{"iden":"sample input 1","content":"3\n1 3 2"},{"iden":"sample output 1","content":"2\n\nYou can sort it in ascending order in two operations as follows.\n\n1.  Move the term at the beginning to the end: now you have $3, 2, 1$.\n2.  Reverse the whole permutation: now you have $1, 2, 3$.\n\nYou cannot sort it in less than two operations, so the answer is $2$."},{"iden":"sample input 2","content":"2\n2 1"},{"iden":"sample output 2","content":"1\n\nDoing either operation once will sort it in ascending order.\nYou cannot sort it in less than one operation, so the answer is $1$."},{"iden":"sample input 3","content":"10\n2 3 4 5 6 7 8 9 10 1"},{"iden":"sample output 3","content":"3\n\nYou can sort it in ascending order in three operations as follows.\n\n1.  Reverse the whole permutation: now you have $1,10,9,8,7,6,5,4,3,2$.\n2.  Move the term at the beginning to the end: now you have $10,9,8,7,6,5,4,3,2,1$.\n3.  Reverse the whole permutation: now you have $1,2,3,4,5,6,7,8,9,10$.\n\nYou cannot sort it in less than three operations, so the answer is $3$."},{"iden":"sample input 4","content":"12\n1 2 3 4 5 6 7 8 9 10 11 12"},{"iden":"sample output 4","content":"0\n\nNo operation is needed."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}