import Data.List

is2nd :: Int -> Int -> Int -> Bool
is2nd p1 p2 p3 = (p2 `elemIndex` sort [p1, p2, p3]) == Just 1

solve :: [Int] -> Int
solve [p1, p2, p3] = if is2nd p1 p2 p3 then 1 else 0
solve (p1:p2:p3:ps) = solve (p2:p3:ps) + if is2nd p1 p2 p3 then 1 else 0

main :: IO ()
main = do
  getLine
  ps <- map read . words <$> getLine
  print $ solve ps