Problem:
 Score : 200 points    Problem Statement We have a permutation p = { p_1,\ p_2,\ ...,\ p_n } of { 1,\ 2,\ ...,\ n }.  Print the number of elements p_i ( 1 < i < n ) that satisfy the following condition:   p_i is the second smallest number among the three numbers p_{i - 1} , p_i , and p_{i + 1} .       Constraints  All values in input are integers.  3 \leq n \leq 20  p is a permutation of { 1,\ 2,\ ...,\ n }.         Input Input is given from Standard Input in the following format:  n  p_1  p_2  ...  p_n       Output Print the number of elements p_i ( 1 < i < n ) that satisfy the condition.        Sample Input 1 5
1 3 5 4 2      Sample Output 1 2  p_2 = 3 is the second smallest number among p_1 = 1 , p_2 = 3 , and p_3 = 5 . Also, p_4 = 4 is the second smallest number among p_3 = 5 , p_4 = 4 , and p_5 = 2 . These two elements satisfy the condition.       Sample Input 2 9
9 6 3 2 5 8 7 4 1      Sample Output 2 5

Solution (Python):
n = int(input())
num = list(map(int,input().split()))
ans = 0
for idx in range(n-2):
  if num[idx] < num[idx+1] and num[idx+1] < num[idx+2]:
    ans += 1
  elif num[idx+2] < num[idx+1] and num[idx+1] < num[idx]:
    ans += 1
  else:
    pass

print(ans)

Solution (Python):
n = int(input())
L = list(map(int, input().split()))
count = 0
for i in range(n-2):
    subList = L[i:i+3]
    if subList[0] < subList[1] < subList[2] or subList[0] > subList[1] > subList[2]:
        count += 1
print(count)

Solution (Python):
n = int(input())
S = list(map(int,input().split()))
cnt = 0
for i in range(1,n-1,1):
    temp = [S[i-1],S[i],S[i+1]]
    temp.sort()
    
    if temp[1] == S[i]:
        cnt += 1
print(cnt)

Solution (Python):
n = int(input())
P = [int(x) for x in input().split()]

count = 0
for i in range(1, n-1):
    p1 = P[i-1]
    p2 = P[i]
    p3 = P[i+1]
    if (p1 < p2 < p3) or (p3 < p2 < p1):
        count += 1
        
print(count)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(1, len(p)-1):
    if p[i-1] <= p[i] and p[i] < p[i+1]:
        cnt += 1
    elif p[i-1] > p[i] and p[i] >= p[i+1]:
        cnt += 1
print(cnt)

Solution (Python):
n = int(input())
L = [int(s) for s in input().split()]

ans = 0
for i in range(n-2):
    Lbc = L[i:i+3]
    Lbs = sorted(Lbc)
    if Lbc[1] == Lbs[1]:
        ans += 1
    else:
        pass
print(ans)

Solution (Python):
import sys

def main():
    n = int(sys.stdin.readline().strip())
    p = [int(i) for i in sys.stdin.readline().strip().split()]
    ret = 0
    for i in range(n - 2):
        s = p[i:i+3]
        ss = sorted(s)
        if ss[1] == s[1]:
            ret += 1
    return ret
    
print(main())

Solution (Python):
n = int(input())
p = [int(i) for i in input().split()]
sum = 0
for i in range(n - 2):
    pp = p[i:i + 3]
    if pp[1] == sorted(pp)[1]:
        sum += 1
print(sum)

Solution (Python):
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial

sys.setrecursionlimit(1000000)










n = int(input())
p = [int(x) for x in input().split()]

cnt = 0
for i in range(n - 2):
    L = [p[i], p[i + 1], p[i + 2]]
    L.sort()
    
    if p[i + 1] == L[1]:
        cnt += 1

print(cnt)

Solution (Python):
from statistics import median

n = int(input())
p =  [int(i) for i in input().split(" ")]
count = 0

for i in range(1, n-1) :
    if p[i] == median([p[i-1], p[i], p[i+1]]) :
        count+=1
print(count)

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-2):
    if max(p[i], p[i+1], p[i+2]) != p[i+1] and min(p[i], p[i+1], p[i+2]) != p[i+1]:
        ans += 1
print(ans)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n-2):
    pi, pj, pk = p[i], p[i+1], p[i+2]
    pmax = max(pi, pj, pk)
    pmin = min(pi, pj, pk)
    if pj != pmax and pj != pmin:
        ans += 1

print(ans)

Solution (Python):
n = int(input())
ps = [int(s) for s in input().split() if s]

cnt = 0

for i in range(n-2):
    if ps[i] < ps[i+1] and ps[i+2] < ps[i+1]:
        continue
    if ps[i] > ps[i+1] and ps[i+2] > ps[i+1]:
        continue
    cnt += 1

print(cnt)

Solution (Python):
n = int(input())
p_list = list(map(int,input().split()))
count = 0
for i in range(1,len(p_list)-1):
    tmp_list = [p_list[i-1], p_list[i],p_list[i+1]]
    tmp_list.sort()
    if tmp_list[1] == p_list[i]:
        count += 1
print(count)

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
cnt = 0
for i in range(1,n-1):
  if li[i-1] < li[i] <li[i+1] or li[i+1] < li[i] < li[i-1]:
    cnt += 1
print(cnt)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

count = 0

for i in range(1,n-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
        count += 1
print(count)

Solution (Python):
def resolve():

    n = int(input())
    li_p = list(map(int, input().split()))

    cnt = 0

    for i in range(1, n-1):

        if li_p[i-1] < li_p[i] & li_p[i] < li_p[i+1]:
            cnt += 1

        elif li_p[i-1] > li_p[i] & li_p[i] > li_p[i+1]:
            cnt += 1

    print(cnt)
    
resolve()

Solution (Python):
def main():
	import sys
	input = sys.stdin.readline
	n = int(input())
	p = list(map(int, input().split()))
	count = 0
	for i in range(n-2):
		if ((p[i] <= p[i+1]) & (p[i+1] <= p[i+2])) | ((p[i] >= p[i+1]) & (p[i+1] >= p[i+2])):
			count += 1
	print(count)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
c = 0

for i in range(n - 2):
    a = []
    a.append(p[i])
    a.append(p[i + 1])
    a.append(p[i + 2])
    a.sort()
    if p[i + 1] == a[1]:
        c += 1

print(c)

Solution (Python):
n = int(input())
p = [int(x) for x in input().split()]
count = 0
for i in range(n-2):
    a,b,c = p[i],p[i+1],p[i+2]
    if (a > b and b > c) or (a < b and b < c):
        count += 1
print(count)

Solution (Python):
input()
P=list(map(int,input().split()))
count=0
for i in range(0,len(P)-2):
    count+=sorted([P[i],P[i+1],P[i+2]])[1]==P[i+1]
print(count)

Solution (Python):
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)

n = int(input())
p = list(map(int, input().split()))
count = 0

for i in range(1, n - 1):
	if (p[i - 1] < p[i] and p[i] < p[i + 1]) or (p[i - 1] > p[i] and p[i] > p[i + 1]):
		count += 1
		
print(count)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
	if a[i-1]<a[i]<a[i+1] or a[i-1]>a[i]>a[i+1]:
		ans+=1
print(ans)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
    if p[i]<p[i+1]<p[i+2] or p[i]>p[i+1]>p[i+2]:
        cnt += 1
print(cnt)

Solution (Python):
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    n = int(input())
    p = list(map(int, input().split()))

    count = 0
    for i in range(1, n-1):
        if max(p[i-1:i+2]) > p[i] and min(p[i-1:i+2]) < p[i]:
            
            count += 1

    print(count)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

ans = 0

for i in range(n - 2):
    a, b, c = p[i], p[i + 1], p[i + 2]
    s = sorted([a, b, c])
    if s[1] == b:
        ans += 1

print(ans)

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(len(p)-2):
  if p[i] < p[i+1] < p[i+2] or p[i] > p[i+1] > p[i+2]:
    cnt += 1
print(cnt)

Solution (Python):
N = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(N-3+1):
    if p[i] < p[i+1] < p[i+2] or p[i] > p[i+1] > p[i+2]:
        cnt += 1

print(cnt)

Solution (Python):
n = int(input())
dat = list(map(int, input().split()))

cnt = 0

for i in range(1, n-1):
  sub = dat[i-1:i+2]
  
  if max(sub) != sub[1] and min(sub) != sub[1]:
    cnt += 1

print(cnt)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, n-1):
  tmp = [p[i-1], p[i], p[i+1]]
  if min(tmp) != p[i] and max(tmp) != p[i]:
    ans += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
ps = [int(i) for i in input().split()]

count = 0
for i in range(1, n-1):
    if sorted([ps[i-1], ps[i], ps[i+1]])[1] == ps[i]:
        count +=1

print(count)

Solution (Python):
cnt = 0
n = int(input())
lst = [int(i) for i in input().split()]
for i in range(n-2):
    a,b,c = lst[i],lst[i+1],lst[i+2]
    if (a<b and b<c) or (c<b and b<a):
        cnt += 1
print(cnt)

Solution (Python):

import sys


def solve(n: int, p: "List[int]"):
    count = 0
    for i in range(n - 2):
        arr = sorted([p[i], p[i+1], p[i+2]])
        if arr[1] == p[i+1]:
            count += 1
    return count



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    p = [ int(next(tokens)) for _ in range(n) ]  
    print(solve(n, p))

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
ans=0
for i in range(1,N-1):
	if max(L[i-1],L[i],L[i+1])!=L[i] and min(L[i-1],L[i],L[i+1])!=L[i]:
		ans+=1
print(ans)

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(n-2):
        l=[p[i],p[i+1],p[i+2]]
        if max(l)!=p[i+1] and min(l)!=p[i+1]:
                ans+=1
print(ans)

Solution (Python):

def read_input():
    n = int(input())
    plist = list(map(int, input().split()))

    return plist


def submit():
    plist = read_input()

    count = 0
    for p1, p2, p3 in zip(plist, plist[1:], plist[2:]):
        if p1 < p2 < p3:
            count += 1
        elif p3 < p2 < p1:
            count += 1

    print(count)
    return


if __name__ == '__main__':
    submit()

Solution (Python):

n = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(1, n - 1):
    if p[i] < max(p[i - 1], p[i + 1]) and p[i] >= min(p[i - 1], p[i + 1]):
        c += 1
print(c)

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(N-2):
    if p[i] < p[i+1] < p[i+2] or p[i] > p[i+1] > p[i+2]:
        ans += 1
print(ans)

Solution (Python):
n = int(input())
p = [int(_) for _ in input().split()]
ans = 0
for i in range(1,n-1):
    a = p[i-1]
    b = p[i]
    c = p[i+1]
    if a > b > c:
        ans += 1
    elif c > b > a:
        ans += 1
        
print(ans)

Solution (Python):
n = int(input())
P = list(map(int, input().split()))

count = 0
for i in range(1, n-1):
    if min([P[i-1], P[i+1]]) < P[i] < max([P[i-1], P[i+1]]):
        count += 1

print(count)

Solution (Python):
n = int(input())

p = list(map(int, input().split(' ')))

cnt = 0
for i in range(1, n - 1):
    sub_i = p[i-1:i+2]
    if sorted(sub_i)[1] == p[i]:
        cnt += 1
print(cnt)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(1, n-1):
    pp = p[i-1: i+2]
    
    pp.sort()
    if p[i] == pp[1]:
        cnt += 1
print(cnt)

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
    if (p[i] < p[i+1] and p[i+1] < p[i+2]) or (p[i+2] < p[i+1] and p[i+1] < p[i]):
        cnt += 1
print(cnt)

Solution (Python):
n = int(input())
p =[int(i) for i in input().split()]
counter = 0
for i in range(1, n-1):
    if p[i] > min(p[i-1],p[i+1]) and p[i] < max(p[i-1], p[i+1]):
        counter += 1
print(counter)

Solution (Python):
n = int(input())
P = list(map(int, input().split()))
ans = 0

for i in range(n - 2):
    if min(P[i], P[i + 2]) <= P[i + 1] <= max(P[i], P[i + 2]):
        ans += 1

print(ans)

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
ct=0
for i in range(n-2):
  if (p[i]<p[i+1] and p[i+1]<p[i+2]) or (p[i]>p[i+1] and p[i+1]>p[i+2]):
    ct+=1
print(ct)

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
        ans+=1
print(ans)

Solution (Python):
n = int(input())
plist = list(map(int, input().split()))

c = 0
for a in range(n-2) :
    if plist[a] < plist[a+1] < plist[a+2] :
        c+=1
    elif plist[a] > plist[a+1] > plist[a+2] :
        c+=1
print(c)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))

def seccheck(i):
    if p[i-1]<p[i]<p[i+1] or p[i-1]>p[i]>p[i+1]:
        return True
    else:
        return False

count = 0
for i in range(1,n-1):
    if seccheck(i):
        count += 1

print(count)

Solution (Python):
a = int(input())
b = list(map(int,input().split()))
c = 0

for i in range(a-2):
  if b[i]<b[i+1]<b[i+2] or b[i+2]<b[i+1]<b[i]:
    c+=1
else:
  print(c)

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
counter=0
for i in range(1,n-1):
    if p[i-1]<p[i]<p[i+1] or  p[i-1]>p[i]>p[i+1]:counter+=1
print(counter)

Solution (Python):
n = int(input())
ps = [int(elem) for elem in input().split()]

cnt = 0
for a, b, c in zip(ps[:-2], ps[1:-1], ps[2:]):
    lst = sorted([a, b, c])
    if lst[1] == b:
        cnt += 1
    else:
        pass
print(cnt)

Solution (Python):
n=int(input())
lst=list(map(int,input().split()))

count = 0
for i in range(n-2):
    if lst[i] < lst[i+1] < lst[i+2] or lst[i] > lst[i+1] > lst[i+2]:
        count += 1
print(count)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

c=0
for i in range(1,n-1):
	if p[i-1]<p[i] and p[i]<p[i+1]:	c+=1
	if p[i+1]<p[i] and p[i]<p[i-1]:	c+=1

print(c)

Solution (Python):
n = int(input())
P = [int(p) for p in input().split()]

cnt = 0
for i in range(1, n-1):
    if (P[i-1] - P[i]) * (P[i+1] - P[i]) < 0:
        cnt += 1

print(cnt)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, n-1):
    if p[i-1] < p[i] < p[i+1] or p[i+1] < p[i] < p[i-1]:
        ans += 1
print(ans)

Solution (Python):
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n = II()
p = LI()
cnt = 0
for i in range(1, n-1):
    if p[i-1] < p[i] < p[i+1] or p[i+1] < p[i] < p[i-1]:
        cnt += 1
print(cnt)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

counter = 0

for i in range(1, n - 1):
	if (p[i - 1] < p[i] and p[i] < p[i + 1]) or (p[i - 1] > p[i] and p[i] > p[i + 1]):
		counter += 1
		
		
print(counter)

Solution (Python):
N = int(input())
arr = list(map(int, input().split()))
ans = 0
for a in range(1, N - 1):
    b = arr[a - 1 : a + 2]
    b.sort()
    if arr[a] == b[1]:
        ans += 1
print(ans)

Solution (Python):
n = int(input())
p = [int(i) for i in input().split()]
count = 0
for i in range(n-2):
    if p[i]<p[i+1]<p[i+2]:
        count +=1
    elif p[i]>p[i+1]>p[i+2]:
        count +=1

print(count)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
    if(sorted(l[i-1:i+2])[1]==l[i]):
        ans+=1
print(ans)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

ans = 0

for i in range(n - 2):
    if (p[i] - p[i + 1]) * (p[i + 2] - p[i + 1]) < 0:
        ans += 1

print(ans)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(n-2):
    if p[i] < p[i+1] < p[i+2] or p[i+2] < p[i+1] < p[i]:
        ans += 1
print(ans)

Solution (Python):
N = int(input())
P = [int(x) for x in input().split()]

ans = 0

for i in range(len(P) - 2):
    if sorted(P[i:i+3])[1] == P[i+1]:
        ans += 1


print(ans)

Solution (Python):
n = input()

p = list(map(int, input().split()))
counter = 0

for i in range(int(n)-2):
    if (p[i] < p[i+1] and p[i+1] < p[i+2]) or (p[i+2] < p[i+1] and p[i+1] < p[i]):
        counter += 1

print(counter)

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
res = 0
for i in range(N-2):
  if p[i] < p[i+1] < p[i+2]:
    res += 1
  elif p[i] > p[i+1] > p[i+2]:
    res += 1
print (res)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    n = II()
    p = LI()

    counter = 0
    for i in range(1,n-1):  
        if (p[i-1] <= p[i] <= p[i+1]) or (p[i+1] <= p[i] <= p[i-1]):
            counter += 1

    print(counter)


main()

Solution (Python):
n = int(input())

ls = list(map(int,input().split()))
ans = 0
arr = []
for i in range(n-2):
  arr = sorted(ls[i:i+3])
  if ls[i+1] == arr[1]:
    ans+=1
print(ans)

Solution (Python):
N = int(input())
p = list(map(int,input().split()))
num = 0

for i in range(N-2):
  pThree = [p[i],p[i+1],p[i+2]]
  pn = sorted(pThree)
  if pn[1] == p[i+1]:
    num += 1
  
print(num)

Solution (Python):
def resolve():
    N = int(input())
    ps = list(map(int, input().split(" ")))
    cnt = 0
    for i in range(1, N-1):
        if (ps[i-1] < ps[i] and ps[i] < ps[i+1]) or (ps[i-1] > ps[i] and ps[i] > ps[i+1]):
            cnt += 1
    print(cnt)
    
if '__main__' == __name__:
    resolve()

Solution (Python):
def solve():
    n = int(input())
    P = list(map(int, input().split()))
    ans = 0
    for i in range(2, n):
        L = sorted(P[i - 2:i + 1])
        if P[i - 1] == L[1]:
            ans += 1
    print(ans)
solve()

Solution (Python):
n = int(input())
p = list(map(int,input().split()))

ans = 0
for i in range(n-2):
    if p[i]<p[i+1]<p[i+2]:
        ans += 1
    elif p[i+2]<p[i+1]<p[i]:
        ans += 1
        
print(ans)

Solution (Python):
import numpy as np
import copy


def main():
    n = input()
    p_arr = list(map(int, input().split()))
    p_arr = np.array(p_arr, dtype=np.int)

    ans = 0
    ans += np.sum(np.logical_and(p_arr[1:-1]
                                 > p_arr[:-2], p_arr[1:-1] < p_arr[2:]))
    ans += np.sum(np.logical_and(p_arr[1:-1]
                                 < p_arr[:-2], p_arr[1:-1] > p_arr[2:]))
    print(int(ans))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
p_array = list(map(int, input().split()))

ans = 0

for i in range(n - 2):
    if (p_array[i] - p_array[i + 1])*(p_array[i + 1] - p_array[i + 2]) > 0:
        ans += 1
print(ans)

Solution (Python):

n = int(input())
p = list(map(int, str(input()).split()))

count = 0
for i in range(len(p)-2):
    tmp = [p[i], p[i+1], p[i+2]]
    tmp.sort()
    if tmp[1] == p[i+1]:
        count += 1

print(str(count))

Solution (Python):
inpl = lambda: list(map(int,input().split()))
n = int(input())
p = inpl()
print(len([1 for i in range(n-2)
           if p[i] < p[i+1] < p[i+2] or p[i+2] < p[i+1] < p[i]]))

Solution (Python):
n = int(input())
Ps =  list(map(int,input().split(" ")))
ans = 0
for i in range(0,n-2):
    a,b,c = Ps[i:i+3]
    temp = Ps[i:i+3]
    temp.sort()
    if temp[1] == b:
        ans += 1
print(ans)

Solution (Python):


def solve():
    n = int(input())
    P = [int(i) for i in input().split()]
    count = 0
    for i in range(1, n - 1):
        PP = [P[i - 1], P[i], P[i + 1]]
        PP.sort()
        if P[i] == PP[1] and PP[1] != PP[2]:
            count += 1
    print(count)


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
para = [i for i in map(int,input().split())]
ans = 0
for i in range(1,n-1):
    if max(para[i-1],para[i],para[i+1]) != para[i] and min(para[i-1],para[i],para[i+1])!= para[i]:
        ans += 1
    else:
        pass
print(ans)

Solution (Python):
N = int(input())
p = [int(x) for x in input().split()]
ans = 0
for i in range(N - 2):
    if p[i] < p[i + 1] < p[i + 2] or p[i] > p[i + 1] > p[i + 2]:
        ans += 1
print("{}".format(ans))

Solution (Python):



def solv(n, p):
    count = 0
    for i in range(n-2):
        if p[i] < p[i+1] and p[i+1] < p[i+2]:
            count += 1
        elif p[i] > p[i+1] and p[i+1] > p[i+2]:
            count += 1
    return count


if __name__ == '__main__':

    n = int(input())
    p = [int(x) for x in input().split()]

    ans = solv(n, p)

    print(ans)

Solution (Python):
n = int(input())
p = [int(_) for _ in input().split()]

res = 0
for i in range(1,n-1):
    l = [p[i-1],p[i],p[i+1]]
    if p[i] != min(l) and p[i] != max(l):
        res += 1

print(res)

Solution (Python):
n = int(input())
p_list = list(map(int, input().split()))

count = 0
for i in range(n-2):
    p0 = p_list[i]
    p1 = p_list[i+1]
    p2 = p_list[i+2]
    if (p0 < p1 and p1 < p2) or (p0 > p1 and p1 > p2):
        count += 1

print (count)

Solution (Python):
n = int(input())
p = [int(i) for i in input().split()]

c = 0
for i in range(n-2):
	p1 = p[i]
	p2 = p[i+1]
	p3 = p[i+2]
	r = sorted([p1,p2,p3])
	if r[1] == p2:
		c+=1
print(c)

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

n = int(stdin.readline().rstrip())
p = list(map(int, stdin.readline().rstrip().split()))

ans = 0

for i in range(1, n-1):
    if p[i-1] < p[i] and p[i] < p[i+1]:
        ans += 1
    elif p[i-1] > p[i] and p[i] > p[i+1]:
        ans += 1


print(ans)

Solution (Python):
N = int(input())
P = list(map(int, input().split()))

count = 0
for i in range(1, N):
    ma = max(P[i-1: i+2])
    mi = min(P[i-1: i+2])
    if P[i] != ma and P[i] != mi:
        count += 1
    
print(count)

Solution (Python):
N = int(input())
P = list(map(int, input().split()))
cnt = 0
for i in range(1, N-1):
    if P[i] != max(P[i-1], P[i], P[i+1]) and P[i] != min(P[i-1], P[i], P[i+1]):
        cnt += 1
print(cnt)

Solution (Python):
n=int(input())
ans=0
p=list(map(int,input().split()))
for i in range(1,n-1):
    if p[i-1]<p[i]<p[i+1] or p[i-1]>p[i]>p[i+1]:
        ans+=1
print(ans)

Solution (Python):
n = int(input())
pn = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
  p1, p2, p3 = pn[i:i+3]
  if p1 < p2 and p2 < p3:
    cnt += 1
  elif p3 < p2 and p2 < p1:
    cnt += 1
print(cnt)

Solution (Python):
N=int(input())
P=list(map(int, input().split()))
ans=0
for i in range(1, N-1):
    if sorted(P[i-1:i+2])[1]==P[i]:
        ans+=1
print(ans)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n-2):
    if p[i] > p[i+1] and p[i+1] > p[i+2]:
        ans += 1
    elif p[i] < p[i+1] and p[i+1] < p[i+2]:
        ans += 1

print(ans)

Solution (Python):
n = int(input())
p = [int(i) for i in input().split()]

count = 0
for i in range(n-2):
    if p[i] < p[i+1] < p[i+2] or p[i+2] < p[i+1] < p[i]:
        count += 1

print(count)

Solution (Python):
n = int(input())
p = input().split(" ")
p = [int(i) for i in p]
c = 0
for i in range(n - 2):
    n1 = p[i]
    n2 = p[i+1]
    n3 = p[i+2]
    
    if (n2 > n1 and n2 < n3) or (n2 < n1 and n2 > n3):
        c += 1
print(c)

Solution (Python):
N = int(input())
p = list(map(int, input().split()))


c = 0
for i in range(1, N-1):
    com = sorted([p[i-1], p[i], p[i+1]])
    if com[1] == p[i]:
        c += 1

print(c)

Solution (Python):
n = int(input())
P = [int(s) for s in input().split()]
count = 0
for i in range(n-2):
  tmp = []
  
  tmp.append(P[i])
  tmp.append(P[i+1])
  tmp.append(P[i+2])
  
  if (tmp[1] < tmp[2] and tmp[0] < tmp[1]) or (tmp[0] > tmp[1] and tmp[2] < tmp[1]):
    count += 1
print(count)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(1, n - 1):
    pp = p[i-1:i+2]
    mid = pp[1]
    pp.sort()
    if mid == pp[1]: cnt += 1

print(cnt)

Solution (Python):
n = int(input())
p = [ int(i) for i in input().split()]
ans = 0

for j in range(n-2):
    if p[j] < p[j+1] and p[j+1] <= p[j+2]:
        ans += 1
    elif p[j] >= p[j+1] and p[j+1] > p[j+2]:
        ans += 1

print(ans)

Solution (Python):
N = int(input())
P = list(map(int, input().split()))
cnt = 0
for i in range(1, N-1):
	lst = [P[i-1], P[i], P[i+1]]
	lst.sort()
	if P[i] == lst[1]: cnt += 1
print(cnt)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
c = 0

for i in range(1, n-1):
    if p[i] != max(p[i-1:i+2]) and p[i] != min(p[i-1:i+2]):
        c += 1

print(c)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
    if (p[i-1] < p[i] < p[i+1]) or (p[i-1] > p[i] > p[i+1]):
        ans += 1

print(ans)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-2):
    if p[i]<p[i+1]<p[i+2] or p[i]>p[i+1]>p[i+2]:
        ans += 1
print(ans)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

count = 0
for i in range(n-2):
    l = p[i:i+3]
    two = l[1]
    l.sort()
    if l[1] == two :
        count += 1
print(count)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
cnt=0
for i in range(1,n-1):
    if (l[i-1]-l[i])*(l[i+1]-l[i])<0:
        cnt+=1
print(cnt)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  if a[i-1]<a[i] and a[i]<a[i+1]:
    ans+=1
  elif a[i-1]>a[i] and a[i]>a[i+1]:
    ans+=1
  else:
    pass
  
print(ans)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

count = 0
for i in range(1, n - 1):
  if p[i] > p[i - 1] and p[i] < p[i + 1]:
    count += 1
  elif p[i] < p[i - 1] and p[i] > p[i + 1]:
    count += 1

print(count)

Solution (Python):
n = int(input())
p = [int(v) for v in input().split()]


cnt = 0
for i in range(1, n - 1):
    if p[i-1] < p[i] and p[i] < p[i+1] or p[i-1] > p[i] and p[i] > p[i+1]:
        cnt += 1
print(cnt)

Solution (Python):
n = int(input())
P = list(map(int, input().split()))

counter = 0
for i in range(1, n-1):
    buff = []
    buff = P[i-1:i+2]
    buff.sort()
    if P[i] == buff[1]:
        counter += 1


print(counter)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(1,n-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1] :
        count += 1
print(count)

Solution (Python):
n=int(input())
s=list(map(int,input().split()))
i=1
ans=0

while i!=n-1:
    d=[s[i-1],s[i],s[i+1]]
    d.sort()
    if d[1]==s[i]:
        ans+=1
    i+=1
print(ans)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))

ans = 0
for i in range(1,n-1):
    if p[i] != max(p[i-1:i+2]) and p[i] != min(p[i-1:i+2]):
        ans += 1

print(ans)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(0, n-2):
    if p[i] < p[i+1] and p[i+1] < p[i+2]:
        count += 1
    elif p[i] > p[i+1] and p[i+1] > p[i+2]:
        count += 1
print(count)

Solution (Python):
n = int(input())
pl = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
    if (pl[i-1] < pl[i] <= pl[i+1]) | (pl[i+1] < pl[i] <= pl[i-1]):
        ans += 1
        
print(ans)

Solution (Python):
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    n = int(input())
    P = [int(c) for c in input().split()]
    num = 0
    for i in range(1, n - 1):
        lists = [P[i - 1], P[i], P[i + 1]]
        max_ = max(lists)
        min_ = min(lists)
        if (P[i] != max_ and P[i] != min_):
            num += 1
    print(num)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input().strip())
P = list(map(int, input().strip().split()))

counter = 0
for i in range(1, N - 1):
  a = P[i - 1]
  b = P[i]
  c = P[i + 1]
  

  if a < b < c or c < b < a:
    counter += 1

print(counter)

Solution (Python):
inp = input()
n = int(inp)
inp = input()
split_inp = inp.split()
total_count = 0
ppre = int(split_inp[0])
pre = int(split_inp[1])
for st in split_inp[2:]:
    p = int(st)
    if pre != max(ppre, pre, p) and pre != min(ppre, pre, p):
        total_count += 1
    ppre = pre
    pre = p
print(total_count)

Solution (Python):
words = lambda t : list(map(t, input().split()))
n = int(input())
a = words(int)

ans = 0
for i in range(n-2):
    if (a[i] < a[i+1] and a[i+1] < a[i+2]) or a[i] > a[i+1] and a[i+1] > a[i+2]:
        ans += 1

print(ans)

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
res=0
for i in range(n-2):
    if p[i]<p[i+1] and p[i+1]<p[i+2]:
        res+=1
    if p[i]>p[i+1] and p[i+1]>p[i+2]:
        res+=1
print(res)

Solution (Python):




def solve():
    N = int(input())
    P = list(map(int, input().split()))
    count = 0
    for i in range(1, N - 1):
        pack = [P[i - 1], P[i], P[i + 1]]
        if P[i] != max(pack) and P[i] != min(pack):
            count += 1
    return count


def main():
    print(solve())


if __name__ == "__main__":
    main()

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    P = list(map(int, input().split()))

    cnt = 0
    for i in range(1, N-1):
        p = P[i]
        if min(P[i-1:i+2]) < p < max(P[i-1:i+2]):
            cnt += 1

    return cnt


if __name__ == '__main__':
    print(main())

Solution (Python):



import sys
from collections import defaultdict

N = int(input())
A = list(map(int, input().rstrip().split(' ')))

count = 0
for i in range(N-2):
    if A[i] <= A[i+1] and A[i+1] <= A[i+2]:
        count += 1
    elif A[i] >= A[i+1] and A[i+1] >= A[i+2]:
        count += 1
        
print(count)

Solution (Python):
n = int(input())
plist = list(map(int, input().split()))

cnt = 0
for num in range(2, n):
    p1 = plist[num-2]
    p2 = plist[num-1]
    p3 = plist[num]
    if p1 > p3:
        if p1 > p2 > p3:
            cnt = cnt + 1
    else:
        if p3 > p2 > p1:
            cnt = cnt + 1

print(cnt)

Solution (Python):
n = int(input())
P = list(map(int, input().split()))
assert n == len(P)

m = sum(1 for p in zip(P, P[1:], P[2:]) if p[1] == sorted(p)[1])
print(m)