There are n rockers, numbered from 1 to n from left to right. A few easy chairs are involved by individuals (at most one individual for each rocker), others are not. The number of involved rockers isn't more noteworthy than n2. For reasons unknown, you might want to advise individuals to move from their rockers to
Computer science. Correct answer will be upvoted else downvoted.
There are n rockers, numbered from 1 to n from left to right. A few easy chairs are involved by individuals (at most one individual for each rocker), others are not. The number of involved rockers isn't more noteworthy than n2.
For reasons unknown, you might want to advise individuals to move from their rockers to some different ones. In the event that the I-th easy chair is involved by somebody and the j-th rocker isn't, you can perceive the individual sitting in the I-th rocker to move to the j-th rocker. The time it takes an individual to move from the I-th rocker to the j-th one is |i−j| minutes. You might play out this activity quite a few times, however these tasks should be done consecutively, i. e. you can't see an individual to move until the individual you requested to move in the last activity has completed the process of moving to their objective easy chair.
You need to accomplish the accompanying circumstance: each seat that was at first involved should be free. What is the base time you wanted to do it?
Input
The principal line contains one integer n (2≤n≤5000) — the number of rockers.
The subsequent line contains n integers a1,a2,… ,an (0≤
Output
Print one integer — the base number of minutes you need to spend to accomplish the accompanying circumstance: each seat that was at first involved should be free.
Step by step
Solved in 3 steps with 1 images