import Data.List

main = do
   n <- readLn :: IO Int
   s <- map read.words<$>getLine
   solve n s

solve 1 s =(print (travel(cancel 1 s)))
solve n s =((print (travel(cancel n s)))>>=solve (n-1) s)

move a b = abs  (a-b)

cancel::Int->[Int]->[Int]
cancel 1 s = tail s
cancel a s = (drop (a-1) s) ++(take a s)

travel::[Int]->Int
travel s = foldl' move 0 (s++0)