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



""" convenient functions




"""

import sys
sys.setrecursionlimit(10**7)
from itertools import accumulate, combinations, permutations, product 

from math import factorial, ceil, floor
def factorize(n):
    """return the factors of the Arg and count of each factor
    
    Args:
        n (long): number to be resolved into factors
    
    Returns:
        list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
    """
    fct = []  
    b, e = 2, 0  
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
def combinations_count(n, r):
    """Return the number of selecting r pieces of items from n kinds of items.
    
    Args:
        n (long): number
        r (long): number
    
    Raises:
        Exception: not defined when n or r is negative
    
    Returns:
        long: number
    """
    
    if n < 0 or r < 0:
        raise Exception('combinations_count(n, r) not defined when n or r is negative')
    if n - r < r: r = n - r
    if r < 0: return 0
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combinations_with_replacement_count(n, r):
    """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
    
    Args:
        n (long): number
        r (long): number
    
    Raises:
        Exception: not defined when n or r is negative
    
    Returns:
        long: number
    """
    if n < 0 or r < 0:
        raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
    elif n == 0:
        return 1
    else:
        return combinations_count(n + r - 1, r)
from bisect import bisect_left, bisect_right
from collections import deque, Counter, defaultdict 
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
from copy import deepcopy, copy 
from operator import itemgetter


from functools import reduce
def chmin(x, y):
    """change minimum
    if x > y, x = y and return (x, True).
    convenient when solving problems of dp[i]
    
    Args:
        x (long): current minimum value
        y (long): potential minimum value
    
    Returns:
        (x, bool): (x, True) when updated, else (x, False)
    """
    if x > y:
        x = y
        return (x, True)
    else:
        return (x, False)
def chmax(x, y):
    """change maximum
    if x < y, x = y and return (x, True).
    convenient when solving problems of dp[i]
    
    Args:
        x (long): current maximum value
        y (long): potential maximum value
    
    Returns:
        (x, bool): (x, True) when updated, else (x, False)
    """
    if x < y:
        x = y
        return (x, True)
    else:
        return (x, False)

from fractions import gcd 
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)



INF = 10 ** 18
MOD = 10 ** 9 + 7
modpow = lambda a, n, p = MOD: pow(a, n, p) 
def modinv(a, p = MOD):
    
    
    return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
    if n <= 1:
        return [0,1][:n+1]
    else:
        inv_t = [0,1]
        for i in range(2, n+1):
            inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
        return inv_t
def modfactorial_list(n, p = MOD):
    if n == 0:
        return [1]
    else:
        l = [0] * (n+1)
        tmp = 1
        for i in range(1, n+1):
            tmp = tmp * i % p
            l[i] = tmp
        return l
def modcomb(n, k, fac_list = [], p = MOD):
    
    
    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if len(fac_list) <= n:
        a = factorial(n) % p
        b = factorial(k) % p
        c = factorial(n-k) % p
    else:
        a = fac_list[n]
        b = fac_list[k]
        c = fac_list[n-k]
    return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
    return (a + b) % MOD
def modsub(a, b, p = MOD):
    return (a - b) % p
def modmul(a, b, p = MOD):
    return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
    return modmul(a, modpow(b, p-2, p))

""" initialize variables and set inputs

    
    

    
    
    
    
    

    
    
    
    

    
    
"""


r = lambda: sys.stdin.readline().strip()
r_int = lambda: int(r())
R = lambda: list(map(int, r().split()))
Rfloat = lambda: list(map(float, r().split()))
Rtuple = lambda: tuple(map(int, r().split()))
Rmap = lambda: map(int, r().split())

""" how to treat input







"""





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




"""memo: how to use defaultdict of list

Dic = defaultdict(list)

Dic[x].append(y)

for k, v in Dic.items():
"""

Solution (Python):
n = int(input())
p = [int(x) for x in input().split()]
count = 0
for i in range(1,n-1):
  sor = sorted(p[i-1:i+2])
  if p[i] == sor[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):
n=int(input())
l=[int(s) for s in input().split()]
cnt=0
for i in range(1,len(l)-1):
  re1=l[i-1]
  re2=l[i]
  re3=l[i+1]
  if( (re2>re1 and re2<re3) or (re2>re3 and re2<re1)):
    cnt+=1
print(cnt)

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

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


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

Solution (Python):


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

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

print(cnt)

Solution (Python):

import sys


def solve(n: int, p: "List[int]"):
    res = 0
    for i in range(len(p)-2):
        if p[i+1] == list(sorted(p[i:i+3]))[1]:
            res += 1
    print(res)


    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 input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    P = LIST()

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

Solution (Python):
n = int(input())
a = 0
b = list(map(int,input().split()))
for x in range(1,n-1):
    if min(b[x-1], b[x], b[x+1]) == b[x]:
        a += 0
        continue
    elif max(b[x-1], b[x], b[x+1]) == b[x]:
        a += 0
        continue
    else:
        a += 1
        continue
print(a)

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

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

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

Solution (Python):




 
from collections import* 
from fractions import gcd
from functools import* 
from itertools import* 
from operator import mul,itemgetter
from bisect import* 
from heapq import* 
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)

 
def main():
    n,*a=map(int,open(0).read().split())
    ans=0
    for i in range(3,n+1):
        if a[i-3:i][1]==sorted(a[i-3:i])[1]:
            ans+=1
    print(ans)
if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
p=list(map(int,input().split()))
count = 0
for i in range(n-2):
    if sorted(p[i:i+3])[1] == 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):
    p1, p2, p3 = P[i - 1], P[i], P[i + 1]
    if (p1 < p2 < p3) or (p3 < p2 < p1):
        ans += 1

print(ans)

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

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

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

print(ans)

Solution (Python):


n = int(input())

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

def isSecond(tgt, p1, p2) :
    if p1 > p2 :
        tmp = p1
        p1 = p2
        p2 = tmp
    if p2 > tgt and tgt > p1 :
        return True
    return False

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

print(count)

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

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

Solution (Python):

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

print(count)

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

Solution (Python):
def solve(n, p):
    ans = 0
    for i in range(1, n-1):
        if p[i] == sorted(p[i-1:i+2])[1]:
            ans += 1
    return ans

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

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

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

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

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

Solution (Python):
import numpy as np
n = int(input())
p = np.array(list(map(int,input().split())))
print(np.count_nonzero((p[1:n-1]-p[:n-2])*(p[2:n]-p[1:n-1])>0))

Solution (Python):
N = int(input())
*P, = 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):
N = int(input())
p = list(map(int, input().split()))
count = 0


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

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

three_nums = [0,0,0]

ans = 0

for i in range(len(num_array)-2):
	three_nums[0] = num_array[i]
	three_nums[1] = num_array[i+1]
	three_nums[2] = num_array[i+2]
	
	if three_nums[0] < three_nums[1] < three_nums[2] or three_nums[2] < three_nums[1] < three_nums[0]:
		ans += 1
		
print(ans)

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

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

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

count = 0

for i in range(n-2):
    maxim = max(ps[i], ps[i+1], ps[i+2])
    minim = min(ps[i], ps[i+1], ps[i+2])
    
    if ps[i] + ps[i+1] + ps[i+2] - maxim - minim == ps[i+1]:
        count += 1

print(count)

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

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

numbers = [int(x)  for x in numbers.split()]

smallest = set()
for i in range(1,len(numbers) - 1):
    
    if (numbers[i] < numbers[i -1] and numbers[i] > numbers[i + 1] ) or (numbers[i] < numbers[i +1] and numbers[i] > numbers[i - 1] ):
        if not(numbers[i] in smallest):
            smallest.add(numbers[i])
    
        
print(len(smallest))

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())
lis = list(map(int,input().split()))
count = 0
i = 0
while(i < n-2):
  temp = lis[i:i+3]
  if temp[1] == sorted(temp)[1]:
    count += 1
  i += 1
  
print(count)

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

Solution (Python):
input_n = int(input())
input_items = list(map(int, input().split(' ')))

cnt = 0
for i in range(input_n - 2):
    targets = [input_items[i + j] for j in range(3)]
    if input_items[i + 1] != min(targets) and input_items[i+1] != max(targets):
        cnt += 1
print(cnt)

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


a=0
i=1

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

    if (p[i-1]<p[i]<p[i+1]) or (p[i+1]<p[i]<p[i-1]):
        a=1+a
print(a)

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

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

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

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

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

Solution (Python):
import numpy as np

size=input()
P=input()

p=P.split(" ")
p=np.array(p,dtype=np.int32)

counter=0

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

print(counter)

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):
number = int(input())
numbers = tuple(map(lambda x:int(x), input().split(" ")))

counts = sum(map(lambda i: 1 if (numbers[i]-numbers[i+1])*(numbers[i+1]-numbers[i+2])>0 else 0 ,range(number-2)))

print(counts)

Solution (Python):
def calc(n, p):
    count = 0
    for i in range(1, n-1):
        if p[i-1] < p[i] and p[i] < p[i+1]:
            count += 1
            continue
        if p[i-1] > p[i] and p[i] > p[i+1]:
            count += 1
            continue
    return count
print(calc(int(input()), [int(a) for a in input().split()]))

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

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

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

print('{}'.format(ans))

Solution (Python):
N = int(input())
P = [int(i) for i in input().split()]
print(sum([1 for i in range(1, N - 1) if P[i - 1] < P[i] < P[i + 1] or P[i - 1] > P[i] > P[i + 1]]))

Solution (Python):

import sys


def solve(n: int, p: "List[int]"):
    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)
    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=input()
S=list(map(int,input().split()))
count=0
for i in range(1,len(S)-1):
    if (S[i-1]<=S[i] and S[i+1]>=S[i]):
      count+=1
      continue
    if (S[i-1]>=S[i] and S[i+1]<=S[i]):
      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):
def main():
    n = int(input())
    p = list(map(int,input().split()))
    cnt = 0

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

    print(cnt)

main()

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

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

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

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

print('{}'.format(ans))

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

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

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

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

count=0

for i in range(1,N-1):
    re_list=list([H[i-1],H[i],H[i+1]])
    re_list.sort()
    if re_list[1]==H[i]:
        count+=1


print(count)

Solution (Python):
_,p=open(0);*p,=map(int,p.split());print(sum(sorted(a)[1]==a[1]for a in zip(p,p[1:],p[2:])))

Solution (Python):
_,p=open(0);*p,=map(int,p.split());print(sum(sorted(a)[1]==a[1]for a in zip(p,p[1:],p[2:])))

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

Solution (Python):
_,p=open(0);*p,=map(int,p.split());print(sum(a<b<c or c<b<a for a,b,c in zip(p,p[1:],p[2:])))

Solution (Python):


import sys
from sys import stdin
import numpy as np

def main():
    
    n = int(stdin.readline().rstrip())
    p = np.array([int(x) for x in stdin.readline().rstrip().split()])
    
    count=0
    for i in range(1,n-1):
        
        
        if p[i-1]<p[i]<=p[i+1]:
            count+=1
        if p[i-1]>=p[i]>p[i+1]:
            count+=1
    print(count)
    return

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

print(count)

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

n = int(input())
p = li()
count = 0
for i in range(n-2):
    i_n = p[i]
    ni = p[i+1]
    n_i = p[i+2]
    if (i_n < ni < n_i) or (i_n > ni > n_i):
        count += 1
print(count)

Solution (Python):
long = int(input())
p = input()
plng = []
pstr = p.split(" ")
n = 0

for i in range(long):
    plng.append(int(pstr[i]))



for i in range(long-2):
    three = [plng[i],plng[i+1],plng[i+2]]
    three.sort()

    if three[1] == plng[i + 1]:
     n = n + 1

print(n)

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


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

Solution (Python):
n = input()
nums = input().split(' ')

nums = [int(num) for num in nums]
cnt=0

for i in range(1,len(nums)-1):
  if nums[i-1] < nums[i] and nums[i] < nums[i+1]:
    cnt += 1
  if nums[i+1] < nums[i] and nums[i] < nums[i-1]:
    cnt += 1
      
print(cnt)

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

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 = input().split()
P = [int(n) for n in P]
A = 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]):
        A += 1
print(A)

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

for i in range(0,n-2):
    p1 = p[i]
    p2 = p[i+1]
    p3 = p[i+2]
    
    if not(p1>p2 and p3>p2):
        if not(p1<p2 and p3<p2):
            count += 1
print(count)

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

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

print(count)

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

print(count)

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

for i in range(1,N-1):
  q=[p[i-1],p[i],p[i+1]]
  r=sorted(q)

  if q[1] == r[1]:
    count+=1
print(count)

Solution (Python):
import sys

if sys.platform =='ios':
	sys.stdin=open('inputFile.txt')
		


def main():
	n = int(input())
	ll=list(map(int, input().split()))
	
	count=0
	for i in range(n-2):
		a=ll[i]
		b=ll[i+1]
		c=ll[i+2]
		
		if (a < b and b < c) or (a>b and  b>c) :
			count+=1
			
	return count

	

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

Solution (Python):
n1=int(input())
n2 = [int(x) for x in input().split()]

cnt = 0

len_min2 = len(n2) - 2

for i in range(len_min2):
  if n2[i+2] >= n2[i+1] and n2[i+1] >= n2[i]:
    cnt += 1
  elif n2[i+2] <= n2[i+1] and n2[i+1] <= n2[i]:
    cnt += 1
    
print(cnt)

Solution (Python):
from sys import stdin


def main():
    n = int(input())

    p = [int(x) for x in stdin.readline().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)


if __name__ == "__main__":
    main()

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

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

for i in range(len(p) - 2):
  k += 1 if min(p[i:i+3]) != p[i+1] and max(p[i:i+3]) != p[i+1] else 0
  
print(k)

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

print(count)

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

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

    if p[i] == k[1]:
        c += 1

print(c)

Solution (Python):
import sys
n = int(input())
l = input().split()
count = 0
l = [int(i) for i in l]
for i in range(n-2):
    tmp = l[i:i+3]
    c = tmp[1]
    changed = sorted(tmp)
    if c == changed[1]:
        count += 1
print(count)

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

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

Solution (Python):
total = int(input())
element = [int(s) for s in input().split()]

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

print(count)

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

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

print(a)

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

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


count = 0
for num in range(1, len(p)-1):

    if (p[num - 1] < p[num] < p[num + 1]) or (p[num - 1] > p[num] > p[num + 1]) :
        count+=1
print(count)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
i=1
count=0
while i < n-1:
    if i != n-1:
        pa=[p[i],p[i-1],p[i+1]]
        pa=sorted(pa)
        if pa[1]==p[i]:
            count+=1
            i+=1
        else:
            i+=1
print(count)

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

c = 0
for d in range((p-2)):
  if(d+1 < p):
    s1 = n[d]
    s2 = n[d+1]
    s3 = n[d+2]
  
    if s1 < s2 and s2 < s3:
      c += 1
    if s1 > s2 and s2 > s3:
      c += 1
  else:
    break
    
print(c)