Problem Description

Read n integers in a circle. In one move, rotate left by 1 (first element goes to end). Compute minimum moves to make array non-decreasing. If not possible, output -1.

Input Format

First line n. Second line n integers.

Output Format

One integer moves or -1.

Sample Test Case

Input:
5 3 4 5 1 2
Output:
3

Constraints

1

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next