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_s = list(map(int,input().split()))
cnt = 0
for i,p in enumerate(p_s):
  if i == 0 or i == len(p_s)-1:
    continue
  else:
    if (p_s[i] < p_s[i+1] and p_s[i] > p_s[i-1]) or (p_s[i] < p_s[i-1] and p_s[i] > p_s[i+1]):
      cnt += 1
print(cnt)

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

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

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

count = 0

for i in range(1,n-1):
    if ( p[i-1] < p[i] 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 = input()
p = input().split(" ")
for i, pp in enumerate(p):
    p[i] = int(pp)
count = 0
for i in range(len(p)-2):
    mirutoko = p[i:i+3]

    mirutoko_sort = sorted(mirutoko)

    if mirutoko[1] == mirutoko_sort[1]:
        count += 1

print(count)

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

Solution (Python):

def main():
    import numpy
    N = int(input())
    P =[int(i) for i in input().split()]
    
    count = 0
    for i in range(1,N-1):
        tmp = [P[i-1],P[i],P[i+1]]
        
        PP=numpy.array(tmp)
        
        PPI = PP.argsort()
        
        if PPI[1] == 1:
            count += 1
    print(count)

if __name__ == '__main__':
    main()

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

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

array = list(map(int, input().split()))
count = 0
for i in range (1,num-1,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)

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

for i in range(1,n-1):
    tmp = list((p[i-1],p[i],p[i+1]))
    tmp.sort()
    if p[i] == tmp[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] and p[i+1] < p[i+2]:
		ans += 1
	elif p[i+2] < p[i+1] and 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(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())
a = list(map(int,input().split()))
cnt = 0
for i in range(len(a)-2):
    c = a[i+1]
    a_sub = a[i:i+3]


    if sorted(a_sub)[1] == c:
        cnt += 1
print(cnt)

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

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

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

cnt = 0

for i in range(1, len(p_list) -1):
  check_list = [p_list[i-1], p_list[i], p_list[i+1]]
  check_p = p_list[i]
  check_list.sort()
  if check_list[1] == check_p:
    cnt += 1

print(cnt)

Solution (Python):

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

count = 0

for i in range(N):
    if i == 0 or i == 1:
        continue
    else:
        MAX = max(P[i-2],P[i-1],P[i])
        


        if MAX == P[i]:
            if P[i-1] >= P[i-2]:
                count += 1
                continue
            else:
                continue

        elif MAX == P[i-1]:
            continue

        elif MAX == P[i-2]:
            if P[i-1] >= P[i]:
                count += 1
                continue
            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] and p[i] < p[i+1]) or (p[i-1]>p[i] and p[i] > p[i+1]):
        ans += 1
    else:
        ans += 0
print(ans)

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


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

Solution (Python):
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    p_list = li()
    second_count = 0
    for i in range(n - 2):
        if p_list[i] < p_list[i + 1] < p_list[i + 2] or p_list[i] > p_list[i + 1] > p_list[i + 2]:
            second_count = second_count + 1
    print(second_count)

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

cnt = 0

p = list(p)
for i in range(1,n-1):
    a = p[i-1]
    b = p[i]
    c = p[i+1]
    ans = [a, b, c]
    
    ans.pop(ans.index(min(ans)))
    if b == min(ans):
        cnt+=1

print(cnt)

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

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

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

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

print(co)

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

Solution (Python):
import numpy as np

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

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

Solution (Python):



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


counter = 0

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

print(counter)

Solution (Python):
import re

n = int(input())
p = [int(i) for i in re.split(" ", input())]
count = 0
for i in range(n - 2):
    if p[i + 1] > p[i] and p[i + 1] > p[i + 2]:
        pass
    elif p[i + 1] < p[i] and p[i + 1] < p[i + 2]:
        pass
    else:
        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] < 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 i in range(1,n-1):
    if max(p[i-1],p[i],p[i+1])!=p[i]:
        if min(p[i-1],p[i],p[i+1])!=p[i]:
            ans += 1

print(ans)

Solution (Python):

def main():
    n = int(input())
    p = list(map(int, input().rstrip().split()))
    ans = 0
    for i, j, k in zip(p, p[1:], p[2:]):
        if i < j < k or k < j < i:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):


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

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

print(count)

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

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
def hantei(aa,b,c):
    if(b<=c and aa<=c and b <= aa):
        return 1
    elif (c<=b and aa <= b and c <= aa):
        return 1
    else:
        return 0

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

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

p = [int(_) for _ in 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
    
print (count)

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

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

num = 0
for i in range(len(s)-2):
    if ((s[i] < s[i+1] <s[i+2] ) or (s[i] > s[i+1] > s[i+2] )) == True:
        num +=1
print(num)

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

Solution (Python):
N=int(input())
lp=[int(e) for e in input().split(' ')]

c=0
for i,p in enumerate(lp):
    if i>=1 and i<= N-2:
        if (lp[i-1]<p<=lp[i+1]) or (lp[i+1]<p<=lp[i-1]):
            c+=1
print(c)

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

print(result)

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

Solution (Python):
def main():
    n = input()
    ps = input().split(' ')
    count = 0
    for i in range(1, len(ps) - 1):
        if int(ps[i]) > min(int(ps[i - 1]), int(ps[i + 1])):
            if int(ps[i]) <= max(int(ps[i - 1]), int(ps[i + 1])):
                count += 1
    print(str(count))


if __name__ == '__main__':
    main()

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

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

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

count = 0

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

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

print(count)

Solution (Python):
N = int(input())
numbers = [list(map(int, input().split()))]

numbers = numbers[0]

count = 0


for i in range(N-2):
    aaa = []
    number_a = int(numbers[i])
    aaa.append(number_a)
    number_b = int(numbers[i+1])
    aaa.append(number_b)
    number_c = int(numbers[i+2])
    aaa.append(number_c)
    if number_b == sorted(aaa)[-2]:
        count += 1
    else:
        continue

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

Solution (Python):
S = int(input())
P = list(map(int,input().split()))
c = 0
for i in range(S-2):
    p_list = [P[i],P[i+1],P[i+2]]
    p_list.sort()
    if p_list[1] == P[i+1]:
        c += 1
print(c)

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


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

print(count)

Solution (Python):
a=[]
i=2
k=0
a.append(int(input()))
for x in input().split(" "):
    a.append(int(x))

while i<=a[0]-1:
    if a[i]>=a[i-1] and a[i]>=a[i+1]:
        k+=0
    elif a[i]<=a[i-1] and a[i]<=a[i+1]:
        k+=0
    else:
        k+=1
    i+=1
print(k)

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

print(c)

Solution (Python):
def main():
    n = int(input())
    p = tuple(map(int, input().split()))
    count = 0
    for i in range(n - 2):
        if (p[i] < p[i + 1] < p[i + 2]) or (p[i + 2] < p[i + 1] < p[i]):
            count += 1
    return count

print(main())

Solution (Python):
n = int(input());
p = input().split(" ");
ans = 0;
for i in range(1,n-1) :
	if int(p[i]) < int(p[i+1]) and int(p[i]) >= int(p[i-1]) :
		ans += 1;
	elif int(p[i]) < int(p[i-1]) and int(p[i]) >= int(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]<p[i+1] and p[i+1]<p[i+2]) or (p[i]>p[i+1] and p[i+1]>p[i+2]):
		count = count + 1
print(count)

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

print sum(a[i] == sorted(a[i - 1: i + 2])[1] for i in xrange(1, n - 1))

Solution (Python):


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


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

print(counter)

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

ans = 0
for i in range(n):
    if i+3 <= n:
        tmp = p[i:i+3]
        if tmp[1] == sorted(tmp)[1]:
            ans += 1
            
print(ans)

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

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

num = 0
for i in range(n):
  if i == 0 or i == n-1:
    pass
  else:
    if (P_n[i]-P_n[i-1])*(P_n[i]-P_n[i+1]) < 0:
      num += 1
    else:
      pass
print(num)

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

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

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

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

print(count)

Solution (Python):
import numpy as np


def resolve():
    n = int(input())
    p = [int(i) for i in input().split()]
    count = 0
    for i in range(n - 2):
        idx = np.argsort(p[i:i + 3])
        if (idx[1] == 1):
            count += 1
    print(count)
resolve()

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

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

print(count)

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

Solution (Python):

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  cnt=0
  for i in range(1,n-1):
    a,b,c=[l[i-1],l[i],l[i+1]]

    if b!=min(a,b,c) and b!=max(a,b,c):
      cnt+=1

  return cnt

print(main())

Solution (Python):
def check(l):
    a = l[1]
    l.sort()
    if a == l[1] and l.count(a) == 1:
        return True
    else:
        return  False

n = int(input())
p = list(map(lambda x:int(x),input().split()))
cnt = 0
for i in range(3,n+1):
    if check(p[i-3:i]):
        cnt += 1
print(cnt)

Solution (Python):
n = int(input())
p_lst = input().split()

for i in range(0, len(p_lst)):
    p_lst[i] = int(p_lst[i])

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

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(1,len(p)-1):
    c = p[i]
    l = p[i-1]
    r = p[i+1]
    judge = (l-c)*(r-c)
    if judge < 0:
        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] < p[i + 2] or p[i + 2] < p[i + 1] < p[i]:
        count += 1

print(count)

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

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

ans = 0

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

print(ans)

Solution (Python):


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

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

print(cnt)

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


if __name__ == '__main__':
    main()

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

Solution (Python):
S=int(input())
L=list(map(int,input().split()))
ans=0
for l in range(len(L)-2):
  if L[l]<L[l+1] and L[l+1]<L[l+2]:
    ans=ans+1
  elif L[l]>L[l+1] and L[l+1]>L[l+2]:
    ans=ans+1
  else:
    continue
print(ans)

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

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

count = 0

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

Solution (Python):
if __name__ == '__main__':
  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
  print(count)

Solution (Python):
n = int(input())
p = [int(x) for x in input().split()]
count = 0
for i in range(n):
    if i != 0 and i != 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

print(count)

Solution (Python):
N = input()
num = input().split(' ')
count = 0
for i in range(int(N) - 2):
  if (int(num[i]) < int(num[i+1]) and int(num[i+1]) < int(num[i+2])) or (int(num[i+2]) < int(num[i+1]) and int(num[i+1]) < int(num[i])):
      count += 1
print(count)

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

ans = 0

for i in range(n-2):
    tmp = list([l[i],l[i+1],l[i+2]])
    if max(tmp) != tmp[1] and min(tmp) != tmp[1]:
        ans += 1
print(ans)

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] 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())
input_line = [input() for i in range(1)]
p = list(map(int,input_line[0].split()))

counter = 0
for i in range(0,N-2):
    b = p[i:i+3]
    b.sort()
    if b[1] == p[i:i+3][1]:
        counter += 1
print(counter)

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

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

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

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

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

mycnt = 0
for i in range(n-2):
  j = int(p[i])
  k = int(p[i+1])
  l = int(p[i+2])
  if j < k < l or l < k < j:
    mycnt += 1

print(mycnt)

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

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

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

Solution (Python):

import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(n: int, p: "List[int]"):
    ret = 0
    for p0, p1, p2 in zip(p, p[1:], p[2:]):
        s0, s1, s2 = sorted([p0, p1, p2])
        ret += int(s1 == p1)
    return ret


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) ]  
    result = solve(n, p)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
xlist = [int(iz) for iz in input().split()]

run = n-2
ans = 0

for i in range(run):
    a = xlist[i]
    b = xlist[i+1]
    c = xlist[i+2]

    if (a < b < c) or (c < b < a):
        ans +=1





print(ans)

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

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

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

print(c)

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

Solution (Python):
N = int(input())
data_list = [int(x) for x in input().split()]
count = 0
test = []
for i in range(1,N-1):
    test = sorted(data_list[i-1:i+2])
    if data_list[i] == test[1]:
        count += 1
print(count)

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

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

print(c)

Solution (Python):

def main():

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

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




if __name__=='__main__':
    main()

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

Solution (Python):



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


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


print(ans)

Solution (Python):
N = int(raw_input())
S = map(int, raw_input().split(' '))

count = 0
for i in range(N-2):
      b = S[i:i+3]
      c = b[:]
      c.sort()
      if b[1] == c[1]:
            count += 1
      else:
            pass
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])
    num.append(p[i])
    num.append(p[i+1])
    num.sort()
    if(num[1] == p[i]):
        count += 1
    num = []
print(count)

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

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

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

count = 0

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

print(count)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
plen = len(p)
num = 0
for i in range(plen):

    if i == 0 or i == plen-1:
        continue
    ls = [p[i-1], p[i], p[i+1]]
    max_ = ls.index(max(ls))
    min_ = ls.index(min(ls))
    if max_ != 1 and min_ != 1:
        num += 1
print(num)

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

Solution (Python):

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

sum = 0
for m in range(len(L)):
  if m >= 2 and m <= len(L)-1:
    if (L[m-2] < L[m-1] < L[m]) or (L[m-2] > L[m-1] > L[m]):
      sum += 1
print(sum)

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())
inputData = input().split()
P = [int(x) for x in inputData]
c = 0
for i in range(1, N-1):
    threenum = [P[i-1], P[i], P[i+1]]
    st_threenum = sorted(threenum)
    if threenum[1] == st_threenum[1]:
        c += 1
    if i == (N - 1):
        break
print(c)

Solution (Python):
N = int(input())
C = list(map(int,input().split()))
cnt = 0

for i in range(N-2):
    if (C[i] < C[i+1] < C[i+2]) or (C[i+2] < C[i+1] < C[i]):
        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]:
        ans += 1
    elif P[i+1] < P[i] < P[i-1]:
        ans += 1
print(ans)

Solution (Python):


''' 
------------------------
author : iiou16
------------------------
'''

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

    count = 0
    for i in range(len(P) - 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)

if __name__ == '__main__':
    main()

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

Solution (Python):


from fractions import gcd
from math import ceil,floor
import collections







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

ans = 0

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

print(ans)

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
C=0


for i in range(N-2):
  if (L[i]>L[i+1] and L[i+1]>L[i+2]) or (L[i]<L[i+1] and L[i+1]<L[i+2]):
    C=C+1
    
print(C)

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

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

print(ans)

Solution (Python):
N = int(input())
pl = list(map(int,input().split(" ")))
ans = 0
for i in range(N-2):
    num_l = pl[i:i+3]
    if(num_l[1]==sorted(num_l)[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 l[i] > l[i-1]:
        if l[i] < l[i+1]:
            c += 1
    else:
        if l[i] > l[i+1]:
            c += 1
print(c)

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

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


sc=0
for s in range(n-2):
    if (P[s]<P[s+1]) and (P[s+1]<P[s+2]):
        sc+=1
        
    elif (P[s]>P[s+1]) and (P[s+1]>P[s+2]):
        sc+=1
        

print(sc)

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):
def no2(tar,r,l):
  if tar > r and tar < l:
    return True
  elif tar > l and tar < r:
    return True
  else:
    return False

x = input()
x = input()
nums = x.split()

n = 0

for i in range(1,len(nums)-1):
  
  if no2(int(nums[i]),int(nums[i-1]),int(nums[i+1])) == True:
    n += 1
    
print(n)