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):
import sys
input = sys.stdin.readline

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

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

print(count)

Solution (Python):
from sys import stdin

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

point = 0
for i in range(1,n-1):
    lin = li[i-1:i+2]
    lin2 = sorted(lin)
    if lin[1] == lin2[1]:
       point += 1
print(point)

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

ans = 0

for i in range(N-2):
  if N_l[i] < N_l[i+1] and N_l[i+1] < N_l[i+2]:
    ans += 1
  elif N_l[i+2] < N_l[i+1] and N_l[i+1] < N_l[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=list(map(int,input().split()))
s=0
for i in range(1,n-1):
    if p[i-1]<=p[i]<=p[i+1]:
        s+=1
    elif p[i+1]<=p[i]<=p[i-1]:
        s+=1
    else:
        s+=0
print(s)

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

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

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

print(count)

Solution (Python):
from sys import stdin

input = stdin.readline

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

count = 0

for i in range(len(p)-2):
    if p[i+1] == sorted([p[i],p[i+1],p[i+2]])[1]:
        count += 1

print(count)

Solution (Python):
import statistics

n = int(input())

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

count = 0

for i in range(1, n) :
    pi = p[i]
    if statistics.median(p[i-1:i+2]) == p[i] :
        count += 1

print(count)

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

num=0
for i in range(1,len(p)-1):
  if p[i-1]<p[i]<p[i+1]:
    num+=1
  elif p[i-1]>p[i]>p[i+1]:
    num+=1
  else:
    pass
  
print(num)

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

print(count)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

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

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

counter = 0

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

print(counter)

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

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

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

ctn = 0
for i in range(0,len(x)):
    if i+2 <= len(x)-1:
        if min(x[i:i+3:2]) <= x[i+1] and x[i+1] <= max(x[i:i+3:2]):
            ctn +=1
print(ctn)

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

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

print(cnt)

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

res = 0
for a,b,c in zip(p[:n-1], p[1:n], p[2:]):
    if a > b > c or c > b > a:
        res += 1
print(res)

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

Solution (Python):

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



ans = 0

for i in range(1,N-1):
    
    if (p_list[i-1] < p_list[i] and p_list[i] < p_list[i+1]) or (p_list[i-1] > p_list[i] and p_list[i] > p_list[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,1):
    if min(p[i-1],p[i],p[i+1]) < p[i] < max(p[i-1],p[i],p[i+1]):
        count += 1
print(count)

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

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

Solution (Python):
n = int(input())
p = [int(i) for i in input().split()]
ans = 0
for i in range(1, n-1):
    if max(p[i-1], p[i], p[i+1]) != p[i] and min(p[i-1], p[i], p[i+1]) != p[i]:
        ans += 1

print(ans)

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

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

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


ans = 0
for i in range(n):
  if i == 0 or i == len(p) - 1:
    continue
  if sorted([p[i-1], p[i], p[i+1]])[1] == p[i]:
    ans += 1

print(ans)

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

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

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

score = 0
for i in range(1, n-1):
    list_p[i]

    if list_p[i] < list_p[i+1] and list_p[i] > list_p[i-1]:
        score += 1

    if list_p[i] > list_p[i+1] and list_p[i] < list_p[i-1]:
        score += 1

print(score)

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

print(ans)

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

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

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

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

print(ans)

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

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

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

Solution (Python):
n=int(input())
p=[int(i) for i in input().split()]
print(sum([p[i]<p[i+1]<p[i+2] for i in range(n-2)])+sum([p[i]>p[i+1]>p[i+2] for i in range(n-2)]))

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

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

print(ans)

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

print(res)

Solution (Python):
n = int(input())
p = [int(x) for x 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
  elif p[i-1]>p[i] and p[i]>p[i+1]:
    cnt +=1
print(cnt)

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


counter = 0
for val in range(n-2):
    _tmp = p_L[val:val+3]
    a = _tmp[1]
    b = sorted(_tmp)[1]
    if a==b:
        counter += 1
print(counter)

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
P = [int(_) for _ in stdin.readline().rstrip().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()))
ans = 0

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

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

flag=0

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

print(flag)

Solution (Python):
n = int(input())
lst = list(map(int,input().split()))
ans = 0
for i in range(len(lst)-2):
    a,b,c=lst[i:i+3]
    if a<b<c or c<b<a:ans+=1

print(ans)

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

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

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

Solution (Python):
import copy
import sys
from _operator import itemgetter
from collections import Counter
from math import log2, pi, ceil

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
p = na()
ct = 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]:
        ct += 1
print(ct)

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 - 1] < P[i] and P[i] < P[i + 1]:
        count += 1
    if P[i + 1] < P[i] and P[i] < P[i - 1]:
        count += 1

print(count)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(n):
    r = p[i:i+3]
    if len(r) == 3:
        if max(r) > r[1] and r[1] > min(r):
            count += 1
print(str(count))

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

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

count=0
for i in range(N):
    p=m[i:i+3]
    if len(p) == 3:
        if max(p) > p[1] and min(p) < p[1]:
            count +=1
            
            
print(count)

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

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

Solution (Python):
import numpy as  np


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

res =  0

for i in range(1, n-1):
    p_part = p[i-1:i+2]
    p_sorted = np.sort(p_part)
    if  p_part[1] == p_sorted[1]:
        res += 1

print(res)

Solution (Python):
n = int(input())
P = list(map(int, input().split()))
cnt = 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]):
        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] > p[i - 1] and p[i] < p[i + 1]) or (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(' ')))
ans = 0

for i in range(1, len(p) - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i - 1] > p[i] > p[i + 1]:
        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]>p[i-1] and p[i]<p[i+1]:
        ans+=1
    elif p[i]<p[i-1] and p[i]>p[i+1]:
        ans+=1
print(ans)

Solution (Python):

import math

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

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

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(len(l)-2):
    t = []
    t.append(l[i])
    t.append(l[i+1])
    t.append(l[i+2])
    if (max(t) != t[1] and min(t) != t[1]):
        ans += 1

print(ans)

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

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

count = 0 

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

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

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

    print(count)

if __name__ == "__main__":
    main()

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

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

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

print(cnt)

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] and l[i] < l[i+1]:
        c = c+1
    elif l[i] < l[i-1] and l[i] > l[i+1]:
        c = c+1
    else:
        continue

print(c)

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())
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
    else:
        continue
print(count)

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

Solution (Python):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    n = int(input())
    ps = list(map(int, input().split()))
    ans = 0
    for i in range(2,n):
        arr = ps[i-2:i+1]
        arr2 = sorted(arr)
        if arr[1] == arr2[1]: ans += 1

    print(ans)

if __name__ == '__main__':
    main()

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

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

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

print(ans)

Solution (Python):
from sys import stdin
import math

n = int(stdin.readline().rstrip())
p_lst = [int(x) for x in stdin.readline().rstrip().split()]
count = 0

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

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

count = 0
for i in range(n-2):
  if (a[i] > a[i+1] and a[i+1]>a[i+2] ) or (a[i] < a[i+1] and a[i+1]<a[i+2] ):
    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]<P[i+1] or P[i+1]<=P[i]<P[i-1]:
        cnt += 1
print(cnt)

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

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

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

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

Solution (Python):
n = int(input())
x = input().split()
c = 0
for i in range(n):
  if i == 0 or i == n-1:
    continue
  elif (int(x[i]) < int(x[i-1]) and int(x[i]) > int(x[i+1])) or (int(x[i]) < int(x[i+1]) and int(x[i]) > int(x[i-1])):
      c = c + 1
print(c)

Solution (Python):
n = int(input())
p = [int(i) for i in input().split()]
s = 0
for i in range(1,n-1):
  l1 = p[i-1:i+2]
  l2 = l1.copy()
  l2.sort()
  if l1[1] == l2[1]:
    s += 1
print(s)

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(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):
while True:
    try:
        n = int(input())
        P = list(map(int, input().split()))
        cnt = 0
        for i in range(1, n-1):
            if min(P[i-1:i+2]) < P[i] < max(P[i-1:i+2]):
                cnt += 1
        print(cnt)
    except:
        break

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

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

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

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

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

ans = 0

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

print(ans)

Solution (Python):

n = int(input())
p = list(map(int,input().split()))
print(sum([max(p[i+1],p[i],p[i-1]) != p[i] and min(p[i+1],p[i],p[i-1]) != p[i] for i in range(1,n-1)]))

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

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

count = 0
for i in range(1, n-1):
	if min(arr[i-1], arr[i+1]) < arr[i] < max(arr[i-1], arr[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] 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())
l=list(map(int,input().split()))
z=0
for i in range(1,n-1,1):
  if l[i-1]<l[i]<l[i+1]:
    z+=1
  elif l[i+1]<l[i]<l[i-1]:
    z+=1
  else:
    z+=0
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 = list(map(int,input().split()))
count = 0
for i in range(1,n-1):
    if (p_list[i] < p_list[i+1] and p_list[i] > p_list[i-1]) or (p_list[i] > p_list[i+1] and p_list[i] < p_list[i-1]):
        count += 1
print(count)

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

Solution (Python):
n = int(input())
p_list = list(map(int, input().split()))
ans = 0
for i in range(1, n-1):
    mini_list = p_list[i-1:i+2]
    sorted_mini_list = sorted(mini_list)
    if mini_list[1] == sorted_mini_list[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):
    part = p[i-1:i+2]
    if p[i] != max(part) and p[i] != min(part):
        count += 1

print(count)

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

flag = 0
for i in range(1,n-1):
    A = p[i-1] < p[i] and p[i] < p[i+1]
    B = p[i+1] < p[i] and p[i] < p[i-1]
    if A or B:
        flag = flag + 1
print(flag)

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

Solution (Python):
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


def main():
    S = int(input())
    nums = list(map(int, input().split()))

    ans = 0

    for i in range(1, S-1):
        if nums[i-1] < nums[i] < nums[i+1] or nums[i-1] > nums[i] > nums[i+1]:
            ans += 1

    print(ans)


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

Solution (Python):

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

cnt = 0
le = len(lst)
for i, _ in enumerate(lst,1):
    if (i+1) == le:
        break
    
    if ( lst[i-1] < lst[i] < lst[i+1] ) or ( lst[i+1] < lst[i] < lst[i-1] ):
        cnt += 1

print ( cnt )

Solution (Python):

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

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
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())
m = list(map(int,input().split()))
c=0
for i in range(1,n-1):
    if max(m[i-1],m[i+1]) > m[i] and min(m[i-1],m[i+1]) < m[i]:
        c += 1
    else:
        c=c
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] 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()))
ans = 0

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

print(ans)

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

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

count = 0

for i in range(1, n-1):
	if lp[i+1] > lp[i] and lp[i] >= lp[i-1]:
		count += 1
	elif lp[i-1] > lp[i] and lp[i] >= lp[i+1]:
		count += 1


print(count)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


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


def ceil(a, b):
    return (a + b - 1) // b



def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2



def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)



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


def main():
    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]
        ans += list(sorted([a, b, c]))[1] == b
    print(ans)

if __name__ == '__main__':
    main()

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

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

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

num = n-2
ans = 0

for i in range(num):

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

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

Solution (Python):
n = int(input())
A = list(map(int, input().strip().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
  else:
    count += 0
print(count)

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

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

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

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

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

print(res)

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

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

ans = 0
for i in range(N):
    l = sorted(L[i - 1 : i + 2])
    if len(l) != 3:
        continue

    if L[i] == l[1]:
        ans += 1

print(ans)

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

count=0
for i in range(2,n):
  if (r[i-2]-r[i-1])*(r[i-1]-r[i])>0:count+=1
print(count)

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

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

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

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

for p1, p2, p3 in zip(p, p[1:], p[2:]):
  l = sorted([p1, p2, p3])
  if p2 == l[1]:
    answer += 1
print(answer)

Solution (Python):
n = int(input())
p = list(map(int,input().split()))
cnt = 0
for i in range(1,n-1):
	lst = [p[i-1], p[i], p[i+1]]
	lst.pop(lst.index(max(lst)))
	lst.pop(lst.index(min(lst)))
	if lst[0] == p[i]:
		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())
nums = list(map(int, input().split()))

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

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