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

Solution (Python):


import sys

def min2nd(ls):
    return sorted(ls)[1]

def solve(input):
    count = 0
    for i in range(0, len(input) - 2):
        slice_ = input[i:i+3]
        if slice_[1] == min2nd(slice_):
            count += 1
    return count

def main():
    sys.stdin.readline()
    inputs = [int(s) for s in sys.stdin.readline().rstrip().split(" ")]
    print(solve(inputs))

main()

Solution (Python):


n = int(input())

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

cnt = n - 2

for i in range(1,len(p)-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()))

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

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

count = 0
for i, pi in enumerate(p):
    if i == 0 or i == n-1:
        continue
    if p[i-1] < pi < p[i+1] or p[i-1] > pi > p[i+1]:
        count += 1
print(count)

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

def solve():
    N = int(raw_input())
    p = [int(_) for _ in raw_input().split()]
    ret = 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]):
            ret += 1
    print ret

if __name__ == '__main__':
    solve()

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

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

cnt = 0
for i in range(n-2):
    list = [p[i], p[i+2]]
    mini = min(list)
    maxi = max(list)
    if mini < p[i+1] <= maxi:
        cnt += 1

print(cnt)

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

Solution (Python):


"""
Created on Sat Jun 29 20:55:46 2019

@author: YudNK
"""

n = int(input())
l = [int(i) for i in input().split()]
count = 0
for i in (range(len(l) - 2)):
    s = l[i:i + 3]
    t = sorted(s)
    if s[1] == t[1]:
        count +=1

print(count)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
ans=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]:
   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]) 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()))
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())
s= list(input().split())
for i in range(n):
    s[i] = int(s[i])

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

print(count)

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

    def is_second_biggest(p0, p1, p2):
        return p1 != min(p0, p1, p2) and p1 != max(p0, p1, p2)

    cnt = 0
    for i in range(n-2):
        if is_second_biggest(P[i], P[i+1], P[i+2]):
            cnt += 1
    
    print(cnt)


main()

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

cnt = 0
for n in range(1, N-1):
    if ((P[n-1] < P[n] and P[n] < P[n+1]) or (P[n+1] < P[n] and P[n] < P[n-1])):
        cnt+=1
print(cnt)

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

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

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

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

cnt=0

for i in range(1,n-1):
	j=i-1
	if (x[j]>x[j+1] and x[j+1]>x[j+2]) or (x[j]<x[j+1] and x[j+1]<x[j+2]):
		cnt+=1

print(cnt)

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

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

Solution (Python):
input()
a = list(map(int, input().split()))
print(sum(s[1] == sorted(s)[1] for s in zip(a, a[1:], a[2:])))

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

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    count = 0
    p_list = [int(i) for i in input().split()]
    for i in range(1, n - 1):
        hoge = p_list[i - 1 : i + 2]
        if min(hoge) == p_list[i]:
            continue
        if len(set(hoge)) == 3 and max(hoge) == p_list[i]:
            continue
        count += 1
    print(count)


if __name__ == "__main__":
    main()

Solution (Python):


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

count = 0

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

Solution (Python):
n = int(input())
P = [int(p) for p in 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 = [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]) or (p[i + 1] < p[i] and p[i] < p[i - 1]):
        ans += 1
print(ans)

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

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

print(num)

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

count = 0
for i in range(1, n - 1):
    all = []
    all.append(pl[i - 1])
    all.append(pl[i])
    all.append(pl[i+1])
    all.sort()
    if all[1] == pl[i]:
        count += 1

print(count)

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

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
an = list(map(int, input().split()))


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

print(ans)

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

cnt = 0
for i in range(N-2):
  sort_arr = sorted([arr[i],arr[i+1],arr[i+2]])
  if sort_arr[1] == arr[i+1]:
    cnt += 1
    
print(cnt)

Solution (Python):
def check(i):
    if(p_list[i-1]< p_list[i] and p_list[i] < p_list[i+1]):
        return 1
    if(p_list[i-1] > p_list[i] and p_list[i] > p_list[i+1]):
        return 1
    return 0

n = int(input().strip())
p_list = list(map(int, input().split()))

ans = 0
for i in range(1, n - 1):
    ans += check(i)
print(ans)

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

for i in range(n):
    if n < i+3:
        break
    a, b, c = p[i:i+3]
    if a < b < c or a > b > c:
        count += 1

print(count)

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


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

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

Solution (Python):
N = int(input())
p = [int(num) for num in input().split(" ")]
counter = 0
for i in range(N-2):
  if (p[i] < p[i+1] < p[i+2]) or (p[i+2] < p[i+1] < p[i]):
    counter	+= 1

print(counter)

Solution (Python):
n  = int(input())
P = list(map(int, input().split()))
ans = 0
p1 = P[0]
p2 = P[1]
for p3 in P[2:]:
  l = [p1, p2, p3]
  if sorted(l)[1] == p2:
    ans+=1
  p1 = p2
  p2 = p3
print(ans)

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

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

n=int(input())
s = list(map(int,input().split()))
cnt=0

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

print(cnt)

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

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

import collections

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

counter = 0
for i in range(1,n-1):
        tmp = [p[i-1], p[i], p[i+1]]
        tmp = collections.Counter(tmp)
        tmp = sorted(tmp)
        if len(tmp) > 1 and tmp[0] < tmp[1] and tmp[1] == p[i]:
                counter += 1
print(counter)

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

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

count=0
i=1
while i<n-1:
    a=p[i]-p[i+1]
    b=p[i]-p[i-1]
    if a*b<0:
        count+=1
    i+=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+1] > p[i]):
        ans += 1
    elif (p[i] < p[i-1]) and (p[i+1] < p[i]):
        ans += 1

print(ans)

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

print(count)

Solution (Python):


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

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

Solution (Python):
n = int(input())
P = list(map(int, input().split()))
cnt = 0
for i in range(1, n - 1) :
  if(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
  else :
    pass
print(cnt)

Solution (Python):
n = int(input())
p = [int(x) for x in 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
    else:
        count += 0
print(count)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
c = 0
k =0
L = n - 3
while(k <= L):
	if (p[k+1] - p[k])*(p[k+1] - p[k+2]) < 0:
		c += 1
	k +=1
print(c)

Solution (Python):
import sys

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

Solution (Python):
n = int(input())
ps = list(map(int, input().split(" ")))
res = 0
for i in range(1, n-1):
    p1 = ps[i-1]
    p2 = ps[i]
    p3 = ps[i+1]
    minimum = min(p1, p2, p3)
    maximum = max(p1, p2, p3)
    if p2 != minimum and p2 != maximum:
        res += 1
print(res)

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

ans = 0

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

print(ans)

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

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
cnt = n-2
ans = 0
for i in range(cnt):
    a1 = li[i]
    a2 = li[i+1]
    a3 = li[i+2]
    if (a1 < a2) & (a2 < a3):
        ans += 1
    if (a3 < a2) & (a2 < a1):
        ans += 1
print(ans)

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

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    p = [int(i) for i in input().split()]
    f = p[0]
    s = p[1]
    ans = 0
    for i in range(2, len(p)):
        if (f < s and s < p[i]) or (f > s and s > p[i]):
            ans += 1
        f = s
        s = p[i]
    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] != max(p[i-1:i+1+1]) and p[i] != min(p[i-1:i+1+1]):
        count +=1
print(count)

Solution (Python):

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

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


import sys

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

def main():
    n = i2n()
    p = i2nn()
    s = 0
    for i in range(1, n - 1):
        s += int(p[i - 1] < p[i]  < p[i + 1])
        s += int(p[i - 1] > p[i]  > p[i + 1])
    print(s)
    return

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

print(count)

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

print(counter)

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

Solution (Python):
import numpy as np
N = int(input())
P = list(map(int, input().split()))

count = 0
for i in range(N-2):
  if np.median(P[i:i+3])==P[i+1]:
    count+=1
print(count)

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

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


print(count)

Solution (Python):

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

count = 0
for index in range(1, n-1):
    tmp = p_list[index - 1:index + 2]

    max_index = tmp.index(max(tmp))
    min_index = tmp.index(min(tmp))

    if max_index != 1 and min_index != 1:
        count += 1

print(count)

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

def isCenter(l3):
  center = l3[1]
  l3.sort()
  return center == l3[1] and l3[0] != l3[1]

cnt = 0

for i in range(n - 2):
  if isCenter(p[i:i+3]):
    cnt += 1

print(cnt)

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

Solution (Python):
n = int(input())
l = [int(x) for x in input().split()]
result = 0
for n in range(1,n):
    if (l[n] < max(l[n-1:n+2])) & (l[n] > min(l[n-1:n+2])):
        result += 1
print(result)

Solution (Python):
def is_ok(a, b, c):
    if a == b and b == c:
        return False

    s = sorted([a,b,c])
    if s[0] == s[1] and s[2] == b:
        return True
    if s[1] == s[2] and (s[1] == b or s[2] == b):
        return True
    if s[1] == b:
        return True
    return False

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

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

print(ans)

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

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

print(count)

Solution (Python):

n = int(input())
p = list(map(int,input().split()))
cnt = 0
i = 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     = input()
num_s = input()
num   = [int(i) for i in num_s.split(" ")]

match_cnt = 0
for i in range(1,len(num)-1):
    nums = num[i-1:i+2]
    if nums[1] == sorted(nums)[1]:
        match_cnt += 1
print(match_cnt)

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

Solution (Python):
import fractions
from collections import deque
import numbers as np


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


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import numpy as np

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

cnt = 0

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

        cnt += 1

print(cnt)

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

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

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

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

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

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

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
p2 = p[0]
p1 = p[1]
pm2 = 1 if p1>p2 else -1
count = 0
for i in range(2,n):
  p2 = p[i-2]
  p1 = p[i-1]
  pm2 = (p2-p1)//abs(p2-p1)
  pm1 = (p1-p[i])//abs(p1-p[i])
  if pm1 == pm2:
    count += 1
print(count)

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

def max2(S):
    if S[0] < S[1] and S[1] < S[2]:
        return True
    elif S[0] > S[1] and S[1] > S[2]:
        return True
    else:
        return False


cnt = 0

for i in range(1, n - 1):
    sub = p[i - 1 : i + 2]
    if max2(sub):
       cnt += 1
       
print(cnt)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
counter = 0
for i in range(len(p)-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):
cnt = 0
N = int(input())
X = list(map(int,input().split()))
for n in range(1, N-1):
    if X[n-1] < X[n] < X[n+1] or X[n+1] < X[n] < X[n-1]:
        cnt+=1
print(cnt)

Solution (Python):
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
logging.disable(logging.CRITICAL)

N = int(input())
L = list(int(x) for x in input().split())

counter = 0

for i in range(1, N - 1):
    if L[i - 1] > L[i] and L[i] > L[i + 1]:
        counter += 1
    elif L[i - 1] < L[i] and L[i] < L[i + 1]:
        counter += 1

print(counter)

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

res = 0
for i in range(n-2):
    tmp_list = [p[i], p[i+1], p[i+2]]
    tmp_list_sorted = sorted(tmp_list)

    if tmp_list_sorted[1] == tmp_list[1]:
        res += 1

print(res)

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

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

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



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

Solution (Python):
N = int(input())
s = input().split()
p = []
for i in range(N):
    p.append(int(s[i]))
count = 0
for i in range(2,N):
    if p[i] > p[i-1] and p[i-1] > p[i-2]:
        count = count+1
    if p[i] < p[i-1] and p[i-1]< p[i-2]:
        count = 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] 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):
"""


 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())


 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  


a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 
"""

import math
import sys
import itertools
import queue
from fractions import gcd

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

mod = 1000000007

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    l = list(map(int, sys.stdin.readline().split()))

    cnt = 0
    for i in range(N - 2):
        p1 = l[i]
        p2 = l[i + 1]
        p3 = l[i + 2]

        if p2 != max(p1,p2,p3) and p2 != min(p1,p2,p3) :
            cnt += 1
    print(cnt)

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

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

for i in range(1, n-1):
	if (p[i] - p[i-1])*(p[i] - p[i+1]) < 0:
		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())
ps = [int(i) for i in input().split()]

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

counter = 0

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

    p1 = P[i-1]
    p2 = P[i]
    p3 = P[i+1]

    if p1 < p2 and p2 < p3:
        counter += 1
    elif p3 < p2 and p2 < p1:
        counter += 1
    
print(counter)

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

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

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

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

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

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

nc=0
for i in range(1,n-1):
    p1=P[i-1]
    p2=P[i]
    p3=P[i+1]
    if p1>p2>=p3 or p1<=p2<p3:
        nc+=1
print(nc)

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

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

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

Solution (Python):
import statistics

n = int(input())
p_ls = [int(i) for i in input().split()] 
c = 0
for i in range(n-2):
    ls = p_ls[i:i+3]
    med = statistics.median(ls)
    if ls[1] == med:
        c += 1
        
print(c)

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

print(ans)

Solution (Python):
def main():
    n = int(input())
    p = input().split()
    frag = 0
    for i in range(1, len(p)-1):
        a = []
        a.append(int(p[i-1]))
        a.append(int(p[i]))
        a.append(int(p[i+1]))
        if max(a) == a[1]:
            continue
        elif min(a) == a[1]:
            continue
        else:
            frag += 1
    print(frag)

if __name__ == "__main__":
    main()

Solution (Python):

n = int(input())
lis = list(map(int,input().split()))
ans = 0
for x,y,z in zip(lis,lis[1:],lis[2:]):
    if x < y < z or z < y < x:
        ans += 1
print(ans)

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

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

r4 = 0
for i3 in range(n1):
    if i3 == 0:
        if n2[0] > n2[1]:
            continue


    elif i3 == n1 - 1:
        if n2[n1 - 1] > n2[n1 - 2]:
            continue
    
    else:
        if (n2[i3 - 1] > n2[i3] and n2[i3] > n2[i3 + 1]) or (n2[i3 + 1] > n2[i3] and n2[i3] > n2[i3 - 1]):
            r4 += 1
print(r4)

Solution (Python):
import heapq

n=int(input())
pX = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
    h = []
    heapq.heappush(h,pX[i])
    heapq.heappush(h,pX[i+1])
    heapq.heappush(h,pX[i+2])
    heapq.heappop(h)
    tgt = heapq.heappop(h)
    if tgt == pX[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):
    ppp = [P[i-1], P[i], P[i+1]]
    ppp.sort()
    if ppp[1] == P[i] and ppp[1] != ppp[0]:
        cnt += 1

print(cnt)

Solution (Python):

N=int(input())
permu=list(map(lambda x:int(x),input().split()))
counter=0

for i in range(1,N-1):
    p=[]
    p.append(permu[i-1])
    p.append(permu[i])
    p.append(permu[i+1])
    p=sorted(p)
    if p[1]==permu[i]:
        counter+=1

print(counter)

Solution (Python):
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    pl = list(map(int, input().split()))

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

    print(count)

Solution (Python):
from sys import stdin

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

    ans = 0
    for i in range(1, N - 1):
        ans += all((min(P[i-1], P[i], P[i+1]) < P[i],
                    max(P[i-1], P[i], P[i+1]) > P[i]))
    print(ans)

input = lambda: stdin.readline()
main()