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

count = 0
for x in range(N - 2):
    if (p[x] < p[x + 1] and p[x + 1] < p[x + 2]) or (p[x] > p[x + 1] and p[x + 1] > p[x + 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-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()))
count = 0

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

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

for p1, p2, p3 in zip(P, P[1:], P[2:]):
    p = [p1, p2, p3]
    p.sort()
    if p2 == p[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):
    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()))
ans = 0

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

print(ans)

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

for num in range(1,len(p)-1):
    p1 = p[num - 1]
    p2 = p[num]
    p3 = p[num + 1]
    
    p_list = [p1,p2,p3]
    p_list.sort()
    if p_list[1] == p2:
        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()))
count=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]):
        count+=1
print(count)

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
L=[]*3
ans=0
for i in range(n-2):
    L=p[i:i+3]
    L.sort()
    if L[1]==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],p[i+1]) and p[i]!=min(p[i-1],p[i],p[i+1]):
    ans=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):
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    n = int(input())
    p_list = list(map(int, input().split()))
    count = 0
    for i in range(0,n-2):
        if ((p_list[i] < p_list[i+1] < p_list[i+2]) or (p_list[i+2] < p_list[i+1] < p_list[i])):
            count += 1
    print(count)

if __name__ == "__main__":
    main()

Solution (Python):
input()
p = list(map(int, input().split()))
print(sum(pi < pj < pk or pk < pj < pi for pi, pj, pk in zip(p, p[1:], p[2:])))

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

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

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)


from collections import Counter,deque,defaultdict





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

Solution (Python):



def main():
    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)


if __name__ == '__main__':
    main()

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(1,n-1):
    t = p[i-1:i+2]
    if max(t)>t[1]>min(t):
        ans+=1
print(ans)

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

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

ans = 0

for i in range(n-2):
    
    buf = p[i:i+3]
    
    buf1 = buf[1]
    
    buf.sort()
    if buf[1] == buf1:
        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()))
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 = 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())
l=list(int(i) for i in input().split())
a=0
for i in range(n-2):
  if sorted(l[i:i+3])[1]==l[i+1]:
    a+=1
print(a)

Solution (Python):


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

count = 0
for i in range(1, len(p)-1):
    min_ = min(p[i-1], p[i], p[i+1])
    max_ = max(p[i-1], p[i], p[i+1])
    if p[i] != min_ and p[i] != max_:
        count += 1
print(count)

Solution (Python):
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    n = int(input())
    p_list = list(map(int, input().split()))
    count = 0
    for i in range(0,n-2):
        if ((p_list[i] < p_list[i+1] < p_list[i+2]) or (p_list[i+2] < p_list[i+1] < p_list[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 = []
    a.extend([p[i], p[i+1], p[i+2]])
    s = set(a)
    if len(s)==3:
        a3 = sorted(a)
        if a3[1]==a[1]:
            ans += 1
    elif len(s)==2:
        if a[1]<a[2] and a[1]<a[0]:
            ans += 1

print(ans)

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

for i in range(n):
  if L[i] < L[i+1] and L[i+1] < L[i+2]:
    a = a+1
  elif L[i+2] < L[i+1] and L[i+1] < L[i]:
    a = a+1
    
print(a)

Solution (Python):


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

count = 0
for i in range(1, len(p)-1):
    min_ = min(p[i-1], p[i], p[i+1])
    max_ = max(p[i-1], p[i], p[i+1])
    if p[i] != min_ and p[i] != max_:
        count += 1
print(count)

Solution (Python):
import copy
n = int(input())
s = list(map(int, input().split()))

count = 0

for i in range(n - 2):
  t = copy.copy(s[i:i + 3])
  if(s[i + 1] == sorted(t)[1]):
    count += 1

print(count)

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

cnt = 0
for i, c in enumerate(p):
    if i == 0 or i == n-1:
        continue
    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()))
cnt = 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]:
        cnt+=1
print(cnt)

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

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
for i in range(1,n-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()))
count = 0
for i in range(1, n-1):
  num = [p[i-1], p[i], p[i+1]]
  if (max(num) == num[0] or max(num) == num[2]) and\
  (min(num) == num[0] or min(num) == num[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):
  pre=p[i-1]
  cur=p[i]
  nex=p[i+1]
  if (pre<cur and cur<nex) or(pre>cur and cur>nex):
    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-1] > p[i] and p[i+1] < p[i]) or (p[i-1] < p[i] and p[i+1] > p[i]):
    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 sorted(p[i - 1:i + 2])[1] == p[i]:
        cnt += 1

print(cnt)

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

ans = 0

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

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

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

for i in range(1,n-1):
    if sorted(ps[i-1:i+2]).index(ps[i]) == 1:
        ans += 1

print(ans)

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

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

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]:
        c += 1
    elif P[i] >  P[i+1] > P[i+2]:
        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 (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())
a=[0]*n
a[:]=map(int,input().split())
r=0
import copy
for ii in range(n-2):
  b=copy.copy(a[ii:ii+3])
  c=copy.copy(b)
  b.sort()
  if b[1]==c[1]:
    r+=1
print(r)

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

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

for i in range(1,n-1):
  num.append([p[i-1],p[i],p[i+1]])

for i in num:
  a=i[1]
  i.sort()
  if i[1]==a:
    count+=1
    
print(count)

Solution (Python):
import itertools
import math
import fractions
import functools
import copy

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],p[i+1]]) != p[i] and max([p[i-1],p[i],p[i+1]]) != p[i]:
        count += 1

print(count)

Solution (Python):
def ordinary_number(n, pli):

    ans = 0

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

    return ans

def main():
    n = int(input())
    pli = list(map(int, input().split()))
    print(ordinary_number(n, pli))

if __name__ == '__main__':
    main()

Solution (Python):

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

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

Solution (Python):






import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)





n = inputI()
a = inputIL()

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

Solution (Python):
import sys
import math
import bisect

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

if __name__ == "__main__":
    main()

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]) or (p[i+1] < p[i] 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(n-2):
    l = p[i:i+3]
    ls = sorted(l)
    if l[1] == ls[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-1]<p[i]<p[i+1] or p[i-1]>p[i]>p[i+1]:
        ans += 1
        
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
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(input().split())
p = [int(p[i]) for i in range(n)]
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(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())
ps=list(map(int,input().split()))
c=0
for i in range(1,n-1):
    p1=ps[i-1]
    p2=ps[i]
    p3=ps[i+1]
    if p1<p2<p3 or p3<p2<p1:
        c+=1
print(c)

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

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

Solution (Python):

import sys


def solve(n: int, p: "List[int]"):
    ans = 0
    for i in range(1,n-1):
        if (p[i-1] > p[i]) ^ (p[i] < p[i+1]):
            ans +=1
    print(ans)
    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]"):
    ans = 0
    for i in range(1,n-1):
        if (p[i-1] > p[i]) ^ (p[i] < p[i+1]):
            ans +=1
    print(ans)
    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):
    l = p[i - 1: i + 2]
    a = sorted(l)
    if a[1] == l[1]:
        ans += 1
print(ans)

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

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

cnt = 0
for i in range(n-2):
    seq = p[i:i+3]
    
    a = seq[1]

    if sorted(seq)[1] == a:
        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):
def solve():
    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)


solve()

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

ans = []

def judge(l):
    if l[0]<l[1]<l[2]:
        return True
    elif l[0]>l[1]>l[2]:
        return True
    else:
        return False

for i in range(n-2):
    ans.append(judge(p[i:i+3]))

print(sum(ans))

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce


import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
P = LI()
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 = input()

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

ans = 0

for i in range(1,len(x)-1):
    t = [x[i-1],x[i],x[i+1]]
    t.sort()
    if t[1] == x[i]:
        ans += 1
        
print(ans)

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

for i in range(n-2):
  li2 = []
  li2.append(li[i])
  li2.append(li[i+1])
  li2.append(li[i+2])
  li2.sort()
  if li2[1] == 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):
    term3 = p[i-1:i+2]
    if sum(term3) - min(term3) - max(term3) == p[i]:
        count += 1
print(count)

Solution (Python):
n = int(input())
P = list(map(int, 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):
def main():
    n = int(input())
    p = [int(x) for x in input().split()]
    ans = 0
    for i in range(1, n - 1):
        a = [p[i - 1], p[i], p[i + 1]]
        if p[i] != max(a) and p[i] != min(a):
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

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

print(ans)

Solution (Python):
n = int(input())
assert n <= 20 and n >= 3,"input error(3 <= n <= 20)"
p = list(map(int,input().split()))
res = 0
for i in range(1,n-1,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]):
        res +=1

print(res)

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

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] or P[i + 1] < P[i] < P[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):
    a=[p[i-1],p[i],p[i+1]]
    if p[i]!=min(a) and p[i]!=max(a):
        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] > p[i] and p[i+1] < p[i+2]:
        ans += 1
    if p[i+1] < p[i] and p[i+1] > p[i+2]:
        ans += 1
print(ans)

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

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

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

Solution (Python):
from sys import argv

debug = "a" in argv
n = int(input())
a = tuple(map(int, input().split()))
ans = 0
for x in range(n - 2):
    if debug:
        print(x, a[x], a[x + 1], a[x + 2])
    if sorted([a[x], a[x + 1], a[x + 2]])[1] == a[x + 1]:
        ans += 1
print(ans)

Solution (Python):

import sys
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos, pi, e
from operator import itemgetter
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7

N = ri()
p = ri_()
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):

import sys
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos, pi, e
from operator import itemgetter
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7

N = ri()
p = ri_()
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 = [int(u) for u in input().split()]
res = 0
for i in range(1,n-1):
    if sorted(l[i-1:i+2])[1] == l[i]:
        res += 1
print(res)

Solution (Python):
n=int(input())
numeros=[int (x) for x in input().split()]
cont=0
for x in range(0,n-2):
    if (numeros[x+1]>numeros[x] and numeros[x+1]<numeros[x+2]) or (numeros[x+1]<numeros[x] and numeros[x+1]>numeros[x+2]):
        if x==n-2:
            break
        cont+=1
print(cont)

Solution (Python):
a=int(input())
seqS=input().split(" ")
num=[]
for q in seqS:
    num.append(int(q))
contador=0



    

for i in range(1,len(num)-1):
    if num[i-1] > num[i] and num[i] > num[i+1] or num[i-1] < num[i] and num[i] < num[i+1]:
        contador+=1



    
print(contador)

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

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

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

c = 0

for i in range(1, len(p)-1):
  f = p[i-1]
  s = p[i]
  t = p[i+1]
  ma = max(f,t)
  mi = min(f,t)
  if s > mi and s < ma:
    c += 1

print(c)

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

main()

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):
def resolve():
    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]]
        tmp.sort()

        if tmp[1] == P[i]:
            ans += 1

    print(ans)


resolve()

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

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

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

print(ans)