import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B
main=print.solve.map(fst.fromJust.B.readInt).B.words=<<B.getContents
solve(n:a:as)=minimum$map(\f->fst$foldl' g(f 0 a)as)[fp,fn]
ft c b v=(c+abs(b-v),v)
fp c b=ft c b$max 1 b
fn c b=ft c b$min(-1)b
g(c,p)a
  |p<0=fp c$p+a
  |p>0=fn c$p+a