Consider a permutation of the numbers of 1 to , for a certain given . At every step, you can choose one between 1 and , and to turn the elements of the first positions of the permutation. The aim is to leave the permutation sorted (in increasing or decreasing order).
Write a program that computes the minimal number of necessary steps to sort a given permutation.
Input consists of a natural , followed by a permutation of the numbers from 1 to .
Your program must print the minimal number of necesary steps to sort the permutation, following the format of the instances.
Author: Unknown
Translator: Carlos Molina
Generation: 2026-01-25T11:14:52.585Z
© Jutge.org, 2006–2026.
https://jutge.org