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())
P = list(map(int, input().split()))

ans = 0
for i in range(1, N - 1):
	cnt = 0
	if P[i - 1] < P[i]: cnt += 1
	if P[i] > P[i + 1]: cnt += 1
	if cnt == 1: ans += 1

print(ans)

Solution (Python):


def main():
    N =int(input())
    ps = [int(s) for s in input().split()]
    result = 0
    for i, p in enumerate(ps):
        if i==0 or i==N-1:
            continue
        if (ps[i-1] > p and p > ps[i+1]) or (ps[i-1] < p and p < ps[i+1]):
            result += 1
    print(result)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
ans = 0
def is_order(a, b, c):
  if (a > b and b > c) or (a < b and b < c):
    return True
  else:
    return False

for i in range(n-2):
  if is_order(p[i], p[i+1], p[i+2]):
    ans += 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-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(1,n-1):
    if p[i-1] < p[i] < p[i+1]:
        ans += 1
    elif 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(len(P) - 2):
    if (P[i] < P[i+1] < P[i+2]) or (P[i+2] < P[i+1] < P[i]):
        ans += 1
    else:
        ans = ans

print(ans)

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

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

print(ans)

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

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

for i in range(n-2):
  if p[i+1] != max(p[i:i+3]) and p[i+1] != min(p[i:i+3]):
    ans += 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] >= P[i-1] and P[i] <= P[i+1]:
    ans += 1
  elif P[i] <= P[i-1] and P[i] >= P[i+1]:
    ans += 1
print(ans)

Solution (Python):

"""
B - Ordinary Number
https://atcoder.jp/contests/abc132/tasks/abc132_b

"""
import sys


def solve(numbers):
    ans = 0
    for a, b, c in zip(numbers, numbers[1:], numbers[2:]):
        t = sorted([a, b, c])
        ans += t[1] == b
    return ans


def main(args):
    _ = input()
    numbers = [int(x) for x in input().split()]
    ans = solve(numbers)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
n=int(input())
d=list(map(int,input().split()))
s=[]
count=0
for i in range(1,n-1):
  s.append(d[i])
  s.append(d[i-1])
  s.append(d[i+1])
  s.sort()
  if s[1]==d[i]:
    count+=1
  s=[]
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]-a[i]) <0:
    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 p[i] > min(p[i-1],p[i+1]) and p[i] < max(p[i-1],p[i+1]):
    count += 1
    
print(count)

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

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


if __name__ == '__main__':
    main()

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

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

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

count = 0
diff = p_list[1] - p_list[0]
for idx in range(2, n):
    if (0 < diff):
        if (p_list[idx-1] < p_list[idx]):
            count += 1
    elif (diff == 0):
        if (p_list[idx] != p_list[idx-1]):
            count += 1
    else:
        if (p_list[idx] < p_list[idx-1]):
            count += 1
    
    diff = p_list[idx] - p_list[idx-1]

print(count)

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

b = list(map(int, input().split()))
count = 0
for i in range(1, N-1):
    a = [b[i-1], b[i], b[i+1]]
    a.sort()
    if b[i] == a[1]:
        count += 1
print(count)

Solution (Python):
S = int(input())
A = list(map(int, input().split()))  

preAns = A[0] < A[1]
count = 0
for a in zip(A[1:], A[2:]):
  temp = a[0] < a[1]
  if (preAns and temp) or (not preAns and not temp):
    count += 1
  preAns = temp
print(count)

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

P = list(map(int, input().split()))

cnt = 0
i = 1
for _ in range(n):
    if n-2 < i:
        break
    cond = 0
    if P[i] < P[i-1]:
        cond += 1
    if P[i] < P[i+1]:
        cond += 1
    if cond == 1:
        cnt += 1
    i += 1

print(cnt)

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

c = 0
for x in zip(P,P[1:],P[2:]):
    c += int(x[1] == sorted(x)[1])
print(c)

Solution (Python):
a = [input().split() for l in range(2)]
n = int(a[0][0])
count=0
for i in range(n-2):
    p1=int(a[1][i])
    p2=int(a[1][i+1])
    p3=int(a[1][i+2])
    p=[p1,p2,p3]
    p.sort()
    if p.index(p2)==1:
        count=count+1

print(count)

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

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

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

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

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 = tuple(map(int, input().split()))

print(len(tuple(
    filter(lambda x: (x[0] < x[1] < x[2]) or (x[0] > x[1] > x[2])
           , zip(p, p[1:], p[2:])
           )
)))

Solution (Python):
def solve():
    n = int(input())
    l = [int(i) for i in input().split()]
    count = 0
    for i in range(n-2):
        if l[i] >= l[i+1] >= l[i+2] or l[i] <= l[i+1] <= l[i+2]:
            count += 1
    return count
    
if __name__ == '__main__':
    print(solve())

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

for index in range(2, len(p)):
    if p[index - 2] < p[index - 1] and p[index - 1] < p[index]:
        counter = counter + 1
    elif p[index - 2] > p[index - 1] and p[index - 1] > p[index]:
        counter = counter + 1

print(counter)

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

count = 0
for i in range(len(p) - 2):
    x = p[i:i+3]
    if x[1] == sorted(x)[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):
    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())
S = input().split()
series = []
left = 0
mid = 0
right = 0
counter = 0
for i in range(N):
    series.append(int(S[i]))
for i in range(N-1):
    if i == 0:
        left = series[i]
        continue
    left = series[i-1]
    mid = series[i]
    right = series[i+1]
    if (left > mid and right < mid) or (left < mid and right > mid):
        counter += 1
print(counter)

Solution (Python):
n = int(input())
s = input().split()
ans = 0

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

print(ans)

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

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

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

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

Solution (Python):
n = int(input())
P = list(map(int,input().split()))
p = [0]*3
cnt = 0
for i in range(1,n-1):
    for j in range(0,len(p)):
        p[j] = P[i+(j-1)] - P[i]
    p.sort()
    if p.index(0) == 1:
        cnt += 1
print(cnt)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
total = 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]:
    total += 1
print(total)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
total = 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]:
        total += 1
print(total)

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

ans = 0

for n in range(1, N-1):
    if P[n-1] < P[n] & P[n] < P[n+1]:
        ans += 1
    elif P[n-1] > P[n] & P[n] > P[n+1]:
        ans +=1

print(ans)

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

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

cnt = 0
for i in range(1,n-1):
  if (max(p[i-1],p[i],p[i+1]) != p[i])and(min(p[i-1],p[i],p[i+1]) != p[i]):
    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] and P[i] < P[i+1]) or (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()))

ans = 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]):
        ans += 1

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*P = map(int,read().split())

answer = sum(x<y<z or x>y>z for x,y,z in zip(P,P[1:],P[2:]))
print(answer)

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

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

print(cnt)

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

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

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

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

Solution (Python):

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

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

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

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
print(len([1 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]]))

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]<p[i+1] or p[i-1]>p[i]>p[i+1]:
            c+=1
print(c)

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

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

print(count)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(1,n-1):
  q = p[i-1:i+2]
  asc = sorted(q)
  des = sorted(q,reverse=True)
  if q==asc or q==des:
    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] or L[i-1]>L[i]>L[i+1]:
    cnt += 1
print(cnt)

Solution (Python):
n=int(input())
p=input()
P=p.split()
x=[]
ans=0
for j in range(n):
    P[j]=int(P[j])
for i in range(n-2):
    x.append([])
    x[i].append(P[i])
    x[i].append(P[i+1])
    x[i].append(P[i+2])
for k in range(len(x)):
    if (x[k][0]<x[k][1] and x[k][1]<x[k][2]) or (x[k][1]>x[k][2] and x[k][1]<x[k][0]):
        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):
n = int(input())
p = list(input().split())
a = 0
for i in range(1,n-1):
    if int(p[i-1]) < int(p[i]) < int(p[i+1]) or int(p[i+1]) < int(p[i]) < int(p[i-1]):
        a += 1

print(a)

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 = list(map(int,input().split()))
count = 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]:
        count += 1
print(count)

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

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

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 = list(map(int, input().split()))

ans = 0
for idx in range(1,n-1):
    if p[idx-1]<p[idx]<p[idx+1] or p[idx-1]>p[idx]>p[idx+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+1] < max(p[i],p[i+1],p[i+2]):
        if p[i+1] > min(p[i],p[i+1],p[i+2]):
            ans+=1

print(ans)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
m=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]):
    m +=1
  else:
    m +=0

    
print(m)

Solution (Python):
n = input()
src = list(map(int, input().split()))
count = 0
for i in range(len(src)-2):
    if src[i]<src[i+1]<src[i+2]:
        count += 1
new_li = list(reversed(src))
for n in range(len(new_li)-2):
    if new_li[n]<new_li[n+1]<new_li[n+2]:
        count += 1
print(count)

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(0,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):
n = int(input())
p = [int(i) for i in input().split()]

ans = 0
for i, j, k in zip(p[:-2], p[1:-1], p[2:]):
    if i < j < k or i > j > k:
        ans += 1
print(ans)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for p1, p2, p3 in zip(p, p[1:], p[2:]):
    if p2 != max(p1, p2, p3) and p2 != min(p1, p2, p3):
        cnt += 1
print(cnt)

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
result = 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])):
    result += 1

print(result)

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

d = 0
for i in range(1,n-1):
  a, b, c = p[i-1:i+2]
  
  if (a < b and b < c) or (a > b and b > c):
    d += 1

print(d)

Solution (Python):


n = int(input().split()[0])
p_list = list(map(int, input().split()))
count = 0

for i in range(1, n - 1):
    a, b, c = p_list[i - 1], p_list[i], p_list[i + 1]
    if a <= b <= c or c <= b <= a:
        count += 1

ans = count
print(ans)

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

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

print(count)

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

a = 0

for i in range(n - 2):
  p_l = [p[i], p[i + 1], p[i + 2]]
  p_l2 = sorted(p_l)
  if p_l2[1] == p_l[1]:
    a += 1
    
print(int(a))

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    p = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for i in range(1, n-1):
        if p[i-1] < p[i] < p[i+1]:
            cnt += 1
        elif p[i-1] > p[i] > p[i+1]:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()

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

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n - 2):
    if (p[i + 0] < p[i + 1] and p[i + 1] < p[i + 2]) or (p[i + 0] > p[i + 1] and p[i + 1] > p[i + 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):
    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())
li = list(map(int,input().split()))
cnt = 0
for i in range(len(li)-2):
    a = li[i]
    b = li[i+1]
    c = li[i+2]
    if max(a,c)>b and b>min(a,c):
        cnt+=1
print(cnt)

Solution (Python):

N = int(input())
lst = [int(x) for x in input().split()]
ans = 0

for i in range(1, len(lst)-1):
    first = lst[i-1]
    second = lst[i]
    third = lst[i+1]

    if first < second < third or third < second < first:
        ans += 1

print(ans)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
  q = p[i:i+3]
  if min(q) == q[1] or max(q)==q[1]:
    pass
  else:
    cnt += 1
print(cnt)

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

ans = 0
for i in range(1, len(p)-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(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())
l = list(map(int, input().split()))
c = 0
for i in range(1, n - 1):
    if (not (min(l[i - 1], l[i], l[i+1]) == l[i])) and (not (max(l[i - 1], l[i], l[i+1]) == l[i])):
        c += 1
print(c)

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

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
num = 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]):
        num +=1
print(num)

Solution (Python):



n = int(input())
P = list(map(int,input().split()))
N = 0

for i in range(n-2):
    s = []
    s.append(P[i])
    s.append(P[i+1])
    s.append(P[i+2])
    if s[1] != max(s) and s[1] != min(s):
        N += 1

print(N)

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

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

print(count)

Solution (Python):
n=int(input())
P=list(map(int,input().split()))
c=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]:
        c+=1
print(c)

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

Solution (Python):
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+2]:
    count = count + 1
  elif p[i]>p[i+1]>=p[i+2]:
    count = count + 1
else:
  print(count)

Solution (Python):
import copy
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(1, n - 1):
    tre_p = [p[i - 1], p[i], p[i + 1]]
    tre_p_copyed = copy.copy(tre_p)
    tre_p.remove(min(tre_p))
    if tre_p_copyed[1] == min(tre_p):
        count += 1
print(count)

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
count=0
for i in range(1,len(p)-1):
    s=[p[i-1],p[i],p[i+1]]
    s.remove(min(s))
    s.remove(max(s))
    if s[0]==p[i]:
        count+=1
print(count)

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


for i in range(1,n-1):
    p_3list = [p[i-1],p[i],p[i+1]]

    if p_3list == sorted(p_3list):
        count += 1
    elif p_3list == sorted(p_3list,reverse=True):
        count += 1

print(count)

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

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

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(1, len(p)-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 p_b():
    N = int(input())
    p = list(map(int, input().split()))
    ans = 0
    for i in range(N - 2):
        if max(p[i:i + 3]) != p[i + 1] and min(p[i:i + 3]) != p[i + 1]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    p_b()

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

a=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]):
        a+=1
print(a)

Solution (Python):

import sys


def solve(n: int, p: "List[int]"):
    result = 0
    for i in range(len(p) - 2):
        if p[i] < p[i + 1] and p[i + 1] < p[i + 2]:
            result += 1
        elif p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
            result += 1
    print(result)
    return



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)]  
    solve(n, p)

if __name__ == '__main__':
    main()

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())

li = list(map(int,input().split()))

co = 0

for i in range(1,len(li)-1):
  work = sorted([li[i-1],li[i],li[i+1]])

  if work.index(li[i]) == 1:
    co += 1
print(co)

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())
p = list(map(int, input().split()))

ans = 0
for i in range(n - 2):
    tmp_p = p[i:i + 3]
    if sorted(tmp_p)[1] == tmp_p[1]:
        ans += 1

print(ans)

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

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

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
count = 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]):
        count += 1

print(count)

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

cnt = 0
i = 1
while i < 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
    i += 1

print(cnt)

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

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

print(ans)

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

l = [int(i) for i in input().split()]
count = 0
for i in range(n - 2):
    tmp = []
    for j in range(i, i + 3):
        tmp.append(l[j])
    if tmp[1] == max(tmp) or tmp[1] == min(tmp):
        pass
    else:
        count += 1

print(count)

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


counter =0
for i in range(1,n-1):
  K=[p[i-1], p[i], p[i+1]]
  K.sort()
  if K[1]==p[i]:
    counter=counter+1
print(counter)

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

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] or a[i-1] > a[i] and a[i] > a[i+1]:
    ans += 1

print(ans)

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

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

Solution (Python):
n, *p = map(int, open(0).read().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(1,n-1):
         pp = (p[i-1],p[i],p[i+1])
         pp = sorted(pp)
         if pp[1] == p[i]:
                  ans+= 1
print(ans)

Solution (Python):
input()
p=[int(x) for x in input().split()]
q=[x-y for x,y in zip(p[1:],p[:])]
r=[1 for x,y in zip(q[1:],q[:]) if x*y>0]
print(len(r))

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 = 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]:
        count += 1
    elif p[i-1] > p[i] and p[i] > p[i+1]:
        count += 1
    else:
        pass

print(count)

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

Solution (Python):

import sys


def solve(n: int, p: "List[int]"):

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

    print(count)

    return


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)]  
    solve(n, p)


if __name__ == "__main__":
    main()

Solution (Python):

import sys


def solve(n: int, p: "List[int]"):

    count = 0
    for i in range(n - 2):
        partial = p[i : i + 2 + 1]
        if min(partial) != partial[1] and max(partial) != partial[1]:
            count += 1
        else:
            pass

    print(count)

    return


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)]  
    solve(n, p)


if __name__ == "__main__":
    main()

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

Solution (Python):
n = int(input())
a = list(map(int, input().split())) 
count = 0

for i in range(len(a)-2):
  if a[i] < a[i+1] and a[i+1] < a[i+2]:
      count += 1
  if a[i] > a[i+1] and a[i+1] > a[i+2]:
    count += 1
  
print(count)

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

ans = 0
for i in range(1, n-1):
    if (p[i] - p[i-1]) * (p[i] - p[i+1]) < 0:
        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 p[i] != max(p[i-1],p[i],p[i+1]) and p[i] != min(p[i-1],p[i],p[i+1]):
        count+=1
        
print(count)

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

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

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
    
print(count)

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

ans = 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]):
    ans += 1
print(ans)

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

count = 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]):
        count += 1

print(count)

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