Problem:
 Score : 200 points    Problem Statement We have a permutation p = { p_1,\ p_2,\ ...,\ p_n } of { 1,\ 2,\ ...,\ n }.  Print the number of elements p_i ( 1 < i < n ) that satisfy the following condition:   p_i is the second smallest number among the three numbers p_{i - 1} , p_i , and p_{i + 1} .       Constraints  All values in input are integers.  3 \leq n \leq 20  p is a permutation of { 1,\ 2,\ ...,\ n }.         Input Input is given from Standard Input in the following format:  n  p_1  p_2  ...  p_n       Output Print the number of elements p_i ( 1 < i < n ) that satisfy the condition.        Sample Input 1 5
1 3 5 4 2      Sample Output 1 2  p_2 = 3 is the second smallest number among p_1 = 1 , p_2 = 3 , and p_3 = 5 . Also, p_4 = 4 is the second smallest number among p_3 = 5 , p_4 = 4 , and p_5 = 2 . These two elements satisfy the condition.       Sample Input 2 9
9 6 3 2 5 8 7 4 1      Sample Output 2 5

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

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

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

cnt=0
for i in range(1,n-1):
  p0 = plist[i-1]
  p1 = plist[i]
  p2 = plist[i+1]
  
  if p0 < p1 and p1 < p2:
    cnt += 1
  elif p0 > p1 and p1 > p2:
    cnt += 1
    
print(cnt)

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

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

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

for i in range(n-2):
    x=[plist[i], plist[i+1], plist[i+2]]
    if x[1]>x[0] and x[1]<x[2]:
        answer+=1
    elif x[1]<x[0] and x[1]>x[2]:
        answer+=1

print(answer)

Solution (Python):
n = int(input())
ps = list(map(int,input().split()))
count = 0
for i in range(1,len(ps)-1):
    if ps[i]>ps[i-1] and ps[i]<ps[i+1]:
        count+=1
    elif ps[i]<ps[i-1] and ps[i]>ps[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-1]<P[i]<P[i+1] or P[i-1]>P[i]>P[i+1]:
    ans += 1

print(ans)

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

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

p = [int(i) for i in input().split()]
ans = 0
for i in range(1, n-1):
    if p[i-1] < p[i] and p[i] < p[i+1]:
        ans += 1
    elif p[i+1] < p[i] and p[i] < p[i-1]:
        ans += 1


print(ans)

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

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

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

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

def inpl(): return list(map(int, input().split()))
from collections import Counter
N = int(input())
P = inpl()
ans = 0
for i in range(N-2):
    ans += (P[i] < P[i+1] < P[i+2]) | (P[i+2] < P[i+1] < P[i])
print(ans)

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations

from itertools import accumulate
from bisect import bisect_left, bisect_right





def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

















n = i_inpl()
p = l_inpl()

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

print(cnt)

Solution (Python):

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

Solution (Python):
def count(n, ps):
    res = 0
    for i in range(1, n - 1):
        qs = (ps[i - 1], ps[i], ps[i + 1])
        if ps[i] == sorted(qs)[1]:
            res += 1
    return res


def main():
    n = int(input())
    ps = [int(p) for p in input().split()]
    res = count(n, ps)
    print(res)


if __name__ == "__main__":
    main()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

n = int(input())
p = LI()

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

print(ans)

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

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

Solution (Python):
n=int(input())
p = list(map(int,input().split(' ')))
i = 1
count=0
while i+1 < n:
    if (p[i]>p[i-1] and p[i]<p[i+1]) or (p[i]<p[i-1] and p[i]>p[i+1]):
        count += 1
    i += 1
print(count)

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+1]) or (p[i-1] > 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):
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]





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

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

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

Solution (Python):

import sys
from operator import itemgetter

from fractions import gcd

from math import ceil, floor

from copy import deepcopy

from itertools import accumulate






from collections import Counter
import math
from functools import reduce




input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())



def solve(n: int, p: "List[int]"):
    cnt = 0
    for i in range(1, n - 1):
        if (p[i - 1] - p[i]) * (p[i + 1] - p[i]) < 0:
            cnt += 1
    print(cnt)


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

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

print(count)

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

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

Solution (Python):

from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    n = int(input())
    p = [int(pi) for pi in input().split()]
    cnt = 0
    for i in range(1, n - 1):
        if sorted([p[i - 1], p[i], p[i + 1]])[1] == p[i]:
            cnt += 1

    print(cnt)




BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict
import math


def main():
    num = int(input())
    data = list(map(int, input().split()))

    ans = 0
    for i in range(1, num - 1):
        aaa = data[i - 1:i + 2]

        if max(aaa) != aaa[1] and min(aaa) != aaa[1]:
            ans += 1

    print(ans)






if __name__ == '__main__':
    main()

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

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

print(ans)

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

Solution (Python):
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op



inf = float('inf')
input = stdin.readline


def main():
    n = get_int()
    P = get_li()
    ans = 0
    for a, b, c in zip(P, P[1:], P[2:]):
        if a < b < c or a > b > c:
            ans += 1
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def gets(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()

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

Solution (Python):
def cnt(a):
    k=a[1]
    a.sort()
    if k==a[1]:
        return 1
    return 0

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

ans=0
for i in range(n-2):
    ans+=cnt(p[i:i+3])
print(ans)

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

ans = 0
for i in range(1, n - 1):
    a, b, c = p[i - 1], p[i], p[i + 1]
    if a < b < c or c < b < a:
        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] < p[i+1]:
        count += 1
    elif p[i-1] > p[i] and p[i] > p[i+1]:
        count += 1
    else:
        pass
print (count)

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

print(ans)

Solution (Python):




n = int(input())

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


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

print(ans)

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

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

Solution (Python):
N = int(input())
P = list(map(int, input().split()))
num = 0
for i in range(1, N - 1):
    tmp = [P[i - 1], P[i], P[i + 1]]
    tmp = sorted(tmp)
    if tmp[1] == P[i]:
        num += 1

print(num)

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

Solution (Python):
N = int(input())
p = [int(x) for x in input().split()]
cnt = 0
for ind,i in enumerate(p[1:-1]):
    if(i>min(p[ind],p[ind+2]) and i<max(p[ind],p[ind+2])):
        cnt+=1
print(cnt)

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

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

ans = 0
for i in range(n-2):
    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):
import sys
input = sys.stdin.readline

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

print(ans)

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

ans = sum(p[i] == (p[i + 1] + p[i] + p[i - 1] - max(p[i + 1], p[i], p[i - 1]) - min(p[i + 1], p[i], p[i - 1])) for i in range(1, n - 1))

print(ans)

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

Solution (Python):
n = int(input())
p = [int(i) for i in input().split()]
count = 0
for k in range(n-2):
    if (p[k+1] - p[k]) * (p[k+2] - p[k+1]) > 0:
        count += 1
print(count)

Solution (Python):
n = int(input())
arr = list(map(int, input().split(' ')))
ans = 0
for i in range(1, len(arr) - 1):
    p2 = arr[i]
    p1 = arr[i-1]
    p3 = arr[i+1]

    x = [p1, p2, p3]
    x = sorted(x)
    if x[1] == p2:
        ans += 1

print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    
    n = int(input())
    arr = list(map(int, input().split()))
    
    ans = 0
    for i in range(1, n - 1):
        b = sorted(arr[i - 1: i + 2])[1]
        if b == arr[i]:
            ans += 1
    
    print(ans)
    
    return 0

main()

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

Solution (Python):

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

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

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

Solution (Python):


def main():
    n = input()
    p = map(int, raw_input().split())
    count = 0
    for i in xrange(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())
P = list(map(int, input().split()))

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

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

Solution (Python):
def solve(N, Ps):
    ans = 0
    for i in range(1, N-1):
        if Ps[i-1] < Ps[i] < Ps[i+1]:
            ans += 1
        if Ps[i-1] > Ps[i] > Ps[i+1]:
            ans += 1
    return ans

if __name__ == "__main__":
    N = int(input())
    Ps = list(map(int, input().split(" ")))
    print(solve(N, Ps))

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

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

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

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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, P):
    ans = 0
    for i in range(N-2):
        if P[i] < P[i+1] < P[i+2]:
            ans += 1 
        elif P[i] > P[i+1] > P[i+2]:
            ans += 1
            

    return ans


def main():
    N = read_int()
    P = read_int_n()
    print(slv(N, P))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
listP = list(map(int, input().split()))
index=1
counter=0
while index < len(listP)-1:
    if listP[index-1] < listP[index] < listP[index+1]:
        counter+=1
    elif listP[index-1] > listP[index] > listP[index+1]:
        counter += 1
    index+=1
print(counter)

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
p = LIST()

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

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

ret = 0
for i in range(0, N - 2) :
    p_ = p[i:i+3]
    if p_[0] < p_[1] < p_[2] or p_[2] < p_[1] < p_[0] :
        ret += 1
        
print(ret)

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

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

cnt = 0
for i in range(1, n-1):
    mn = min([ps[i-1], ps[i+1]])
    mx = max([ps[i-1], ps[i+1]])
    if ps[i] > mn and ps[i] < mx:
        cnt += 1
print(cnt)

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

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

print(ans)

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

ans = 0

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

Solution (Python):
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

N = int(sys.stdin.readline())
P = list(map(int, sys.stdin.readline().split()))


def ok(i):
    return P[i - 1] <= P[i] < P[i + 1] or P[i + 1] <= P[i] < P[i - 1]


ans = 0
for i in range(1, N - 1):
    ans += ok(i)
print(ans)

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

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

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

print(ans)

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

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

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

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

print(ret)

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