package main import "fmt" func max(a, b int) int { if a > b { return a } return b } func min(a, b int) int { if a < b { return a } return b } func main() { var N int fmt.Scan(&N) A := make([]int, N) for i := range A { fmt.Scan(&A[i]) } var ans int for i := 0; i+2 < N; i++ { maxk := max(A[i], max(A[i+1], A[i+2])) mink := min(A[i], min(A[i+1], A[i+2])) midk := A[i] + A[i+1] + A[i+2] - (maxk + mink) if maxk != mink && mink != midk && midk != maxk && (midk == A[i] || midk == A[i+2]) { ans++ } } fmt.Println(ans) }