
solve2 result  (i1:i2:[]) = result
solve2 result (i1:i2:i3:rest)  =
    solve2 (result + if ((i1 < i2) == (i3 < i2)) then 0 else 1) (i2:i3:rest) 

solve :: [Int] -> Int
solve (n:p)  = solve2 0 p
    
main = interact $ show.solve.map read.words
