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())
ps=list(map(lambda x: int(x),input().split()))
count=0
for i in range(N-2):
    if max(ps[i],ps[i+2],ps[i+1])!=ps[i+1] and min(ps[i],ps[i+1],ps[i+2])!=ps[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(n-2):
    tmp = P[i:i+3]
    tmps = sorted(tmp)
    if tmps[1] == tmp[1]:
        ans += 1
print(ans)

Solution (Python):
n = int(input())
p = [int(x) for x in input().split()]
a = 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]:
        a += 1
        
print(a)

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 max(l) != p[i+1] and min(l) != p[i+1]:
                cnt += 1
print(cnt)

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

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

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

ans = 0


for i in range(n-2):

    if min(p[i],p[i+2]) <= p[i+1] and max(p[i],p[i+2]) > p[i+1]:

        ans += 1

print (ans)

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

ans = 0

for i in range(1, len(perm) - 1):
    a = [perm[i - 1], perm[i], perm[i + 1]]
    a.sort()

    ans += perm[i] == a[1]

print(ans)

Solution (Python):
n = int(input())
p = [int(x) for x in input().split()]
ans = 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]):
        ans += 1
print(ans)

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

cnt = 0
for i in range(n-2):
    s1 = li[i]
    s2 = li[i+1]
    s3 = li[i+2]
    if s1 < s2 and s3 > s2:
        cnt += 1
    elif s1 > s2 and s3 < s2:
        cnt += 1

print(cnt)

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

print(cnt)

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

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

Solution (Python):
n = int(input())
Ps = [int(n) for n in input().split()]
score=0
for ind in range(len(Ps)-2):
    p1 = Ps[ind]
    p2 = Ps[ind+1]
    p3 = Ps[ind+2]
    l = [p1,p2,p3]
    if max(l)!=p2 and min(l)!=p2:
       score+=1
print(score)

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

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]
  if p1 <= p2 <= p3 or p3 <= p2 <= p1:
    c += 1
print(c)

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

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

Solution (Python):
n=int(input())
p=input().rstrip().split(' ')
S=0;
for i in range(1,len(p)-1):
    a=int(p[i])
    b=int(p[i-1])
    c=int(p[i+1])
    T=min(a,b,c)
    if T==a:
        continue;
    elif T==b:
        B=min(a,c)
        if B==a:
            S+=1;
            continue;
    elif T==c:
        B=min(a,b)
        if B==a:
            S+=1;
            continue;
print(S)

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())
a = list(map(int,input().split()))
c = 0
for i in range(len(a)):
  if (i == 0 or i == len(a)-1):
    pass
  else:
    
    if a[i-1]<a[i]<a[i+1] or a[i-1]>a[i]>a[i+1]:
      c+=1
print(c)

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

ans = 0
for a, b, c in zip(p, p[1:], p[2:]):
    if (b < a and b > c) or (b > a and b < c):
        ans += 1
print(ans)

Solution (Python):
import sys

fin = sys.stdin.readline

n = int(fin())
p = list(map(int, fin().split()))

count = 0
for i in range(len(p)-2):
    if (p[i] - p[i + 1]) * (p[i+1]-p[i+2]) >0:
        count += 1

print(count)

Solution (Python):

from collections import defaultdict 

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

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

print(cnt)

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

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())
a=list(map(int,input().split()))
cnt=0
for i in range(1,n-1):
    if a[i-1]<a[i] and a[i]<a[i+1]:
        cnt+=1
    elif a[i-1]>a[i] and a[i]>a[i+1]:
        cnt+=1
print(cnt)

Solution (Python):


import sys
sys.setrecursionlimit(1000000)
from collections import deque

N = int(input())
P = list(map(int,input().split()))
ans = 0
for i in range(1,N-1):
    if max(P[i-1],P[i],P[i+1]) == P[i]:
        continue
    elif min(P[i-1],P[i],P[i+1]) == P[i]:
        continue
    else:
        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 max(P[i], P[i+2]) > P[i+1] and min(P[i], P[i+2]) < P[i+1]:
        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] != max(p[i-1],p[i],p[i+1]) and p[i] != min(p[i-1],p[i],p[i+1]):
        ans += 1
print(ans)

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

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()))
ret = 0
for i in range(1,len(p)-1):
    if p[i-1] < p[i] and p[i] <= p[i+1]:
        ret += 1
    if p[i+1] < p[i] and p[i] <= p[i-1]:
        ret += 1
print(ret)

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

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

print(ans)

Solution (Python):
n = int(input())
p = [int(i) for i in 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())
L=list(map(int,input().split()))
ans=0
for i in range(2,N):
    A=[L[i-2],L[i-1],L[i]]
    A.sort()
    if A[1]==L[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-1):
  a = p[i-1:i+2]
  if a[0] < a[1] < a[2] or a[0] > a[1] > a[2]:
    count += 1
print(count)

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

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

Solution (Python):
N = int(input())
p = [int(_) for _ in input().split()]
cnt = 0
for i in range(1, N - 1):
    L = p[i - 1]
    C = p[i]
    R = p[i + 1]

    if L < C < R or R < C < L:
        cnt += 1

print(cnt)

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

counter = 0
for i in range(1, n-1):
    _p = [p[i-1], p[i], p[i+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):
def resolve():

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

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

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

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

print(cnt)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    s = S()
    b = list(set(s))
    a = len(list(set(s)))
    if a == 2 and s.count(b[0]) == s.count(b[1]) == 2:
        print("Yes")
    else:
        print("No")
    return


def B():
    n = II()
    p = LI()
    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)
    return


def C():
    n = II()
    d = LI()
    d.sort()
    ans = 0
    for i in range(d[-1]):
        if n // 2 == bisect_left(d, i):
            ans += 1
    print(ans)
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    B()

Solution (Python):
import sys
sys.setrecursionlimit(4100000)
n = int(input())
p = [int(i) for i in input().split()]
counter = 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]:
        counter += 1
print(counter)

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]]
    l.sort()
    if p[i+1]==l[1]:
        ans+=1

print(ans)

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

print(ans)

Solution (Python):
n = int(input())
p = [int(i) for i in 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()))

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

Solution (Python):
a=int(input())
b=list(map(int,input().split()))
ans=0
for i in range(1,a-1):
    if (b[i-1]<b[i] and b[i]<b[i+1]) or (b[i-1]>b[i] and b[i]>b[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]-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(0,n-2):
    lis = p[i:i+3]
    a = p[i+1]
    lis.sort()
    if a == lis[1]:
        ans += 1

print(ans)

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

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

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

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

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

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

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

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

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

if __name__=="__main__": main()

Solution (Python):
n=int(input())
p=[int(x) for x in input().split()]
count=0
for i in range(1,n-1):
  a=p[i-1]
  b=p[i]
  c=p[i+1]
  l=[a,b,c]
  k=sorted(l)
  if(k[1]==l[1]):
    count+=1
print(count)

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

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

print(answer)

Solution (Python):
N = int(input())
*p, = 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]:
        ans += 1
    elif p[i+1] >= p[i] and p[i] >= p[i-1]:
        ans += 1

print(ans)

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

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

print(ans)

Solution (Python):

"""
AtCoder A
"""

import sys, math, random
import numpy as np








inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LLS(): return [list(sys.stdin.readline().rstrip()) for _ in sys.stdin.readlines()]
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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()



def main():
    N = I()
    P =LI()
    out=0
    for i in range(2,N):
        if (P[i-2]>P[i-1] and P[i-1]>P[i]) or(P[i-2]<P[i-1] and P[i-1]<P[i]):
            out+=1

    print(out)

    
    
if __name__ == "__main__":
    main()

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
a = list(li())
ans = 0

for i in range(n-2):
    p0, p1, p2 = a[i:i+3]
    st = sorted([p0, p1, p2])

    if p1 == st[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] 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()))
cnt = 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]):
        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]<=P[i+1]<=P[i+2] or P[i+2]<=P[i+1]<=P[i]:
        ans += 1
print(ans)

Solution (Python):


def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  n = readInts()[0]
  p = readInts()

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

if __name__ == "__main__":
  main()

Solution (Python):


import sys

n= int(sys.stdin.readline())
p= [ int(x) for x in sys.stdin.readline().split() ]

count = 0
for i in range(n-2):
    m= p[i+1]
    t= p[i:i+3]
    if m!=min(t) and m!=max(t): 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]<p[i+1]) or (p[i+1]<p[i]<p[i-1]):
        count += 1

print(str(count))

Solution (Python):
import sys
from collections import deque  
from collections import defaultdict  
from heapq import heapify, heappush, heappop, heappushpop  
from bisect import bisect_left, bisect_right  



s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    n = i2n()
    p = i2nn()
    ans = 0
    for i in range(1, n-1):
        x, y, z = p[i-1:i+2]
        if x < y and y < z:
            ans += 1
        elif x > y and y > z:
            ans += 1
    print(ans)

main()

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

s = 0
for i in range(1,N-1):
    s += p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]

print(s)

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

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

print(res)

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
cnt=0
for i in range(N-2):
    M=L[i:i+3]
    if L[i+1]>min(M) and L[i+1]<max(M):
        cnt+=1
print(cnt)

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

ans = 0

for i in range(N-2) :
    a = P[i]
    b = P[i+1]
    c = P[i+2]
    
    Z = sorted([a,b,c])
    
    if max(Z) != b and min(Z) != b :
        ans += 1
print(ans)

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

cnt = 0
for i in range(1, n - 2 + 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())
ps = list(map(int, input().split()))

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

print(ans)

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

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

Solution (Python):
from heapq import heappush, heappop
import re
from collections import deque
import sys
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_invs(n, mod=DIV):
    inv = [0]*(n+1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, n+1):
        inv[i] = (-(mod//i)*inv[mod % i]) % mod
    return inv


def main():
    N= int_raw()
    ps = ints_raw()
    ans =0
    for i in range(1,N-1):
        p = ps[i]
        p_sub = ps[i-1:i+2]
        if(min(p_sub)!=p and max(p_sub)!=p):
            ans+=1
    return ans

print(main())

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

Solution (Python):
n = int(input())
p = [int(x) for x in 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):
    tmp_list = [p[i-1], p[i], p[i+1]]
    tmp_list.sort()


    if tmp_list[1] == p[i]:
        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] == sorted(p[i-1:i+2])[1]:
        ans += 1
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
p = na()
a = 0

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

print(a)

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

print(c)

Solution (Python):
n=int(input())
p=[int(i) for i 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(ans)

Solution (Python):
import bisect
from operator import itemgetter
import math
import copy
import collections
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
A = IL()

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

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))

n = onem()
l = l()
co = 0
for i in range(1,n-1):
    a = l[i-1]
    b = l[i]
    c = l[i+1]
    k = [a,b,c]
    k.sort(reverse = True)
    if k[1] == b and k[0] != k[1]:
        co += 1
print(co)

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

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

print(ans)

Solution (Python):
import numpy as np
from collections import defaultdict
from functools import reduce

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

cnt = 0
for i in range(n-2):
    if ((p[i+1] < p[i]) and (p[i+1] > p[i+2])) or ((p[i+1] > p[i]) and (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-2):
    a,b,c=p[i],p[i+1],p[i+2]
    if sorted([a,b,c]).index(b) == 1:
        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]<p[i+1]<p[i+2]:
        ans+=1
    if p[i]>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 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 = input()
p = [int(x) for x in input().split()]

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

print(ans)

Solution (Python):
def find(P):
    count=0
    for i in range(1,len(P)-1):
        x,y,z=P[i-1],P[i],P[i+1]
        if P[i]==sorted([x,y,z])[1]:
            count+=1
    return count
input()
A=list(map(int,input().strip().split(' ')))
print(find(A))

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



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

res = 0
for i in range(1, n-1):
    a, b, c = p[i-1], p[i], p[i+1]
    t = [a, b, c]
    t.sort()
    if b == t[1]:
        res += 1

print(res)

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())
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):
    l=[p[i],p[i+1],p[i+2]]
    l.sort()
    if l[1]==p[i+1]:
        ans+=1
print(ans)

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

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

res = 0
for i in range(1, N - 1):
    M = max(P[i - 1], P[i], P[i + 1])
    m = min(P[i - 1], P[i], P[i + 1])

    if M != P[i] and m != P[i]:
        res += 1

print(res)

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

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

print(ans)

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

ans = 0
plist = list(map(int, input().split()))

for i in range(len(plist)-2):
    tmp = plist[i:i+3]
    tmp.sort()
    if tmp[1] == plist[i+1]:
        ans += 1

print(ans)

Solution (Python):

n = int(input())

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

count = 0
for i in range(1, n - 1):
    if p_lst[i-1] < p_lst[i] < p_lst[i+1]:
        count += 1
    elif p_lst[i+1] < p_lst[i] < p_lst[i-1]:
        count += 1
    else:
        pass

print(count)

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

ans = 0

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

print(ans)