CF612F Simba on the Circle
Description
You are given a circular array with $ n $ elements. The elements are numbered from some element with values from $ 1 $ to $ n $ in clockwise order. The $ i $ -th cell contains the value $ a_{i} $ . The robot Simba is in cell $ s $ .
Each moment of time the robot is in some of the $ n $ cells (at the begin he is in $ s $ ). In one turn the robot can write out the number written in current cell or move to the adjacent cell in clockwise or counterclockwise direction. To write out the number from the cell Simba doesn't spend any time, but to move to adjacent cell Simba spends one unit of time.
Simba wants to write the number from each cell one time, so the numbers will be written in a non decreasing order. Find the least number of time units to write out all numbers.
Input Format
N/A
Output Format
N/A