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().strip().split()))

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

print(res)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
count=0
i=1
while i<len(a)-1:
    if (a[i]>a[i+1] and a[i]<a[i-1]) or (a[i]<a[i+1] and a[i]>a[i-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):
    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())
p = list(map(int, input().split()))

cnt = 0

for i in range(n-2):
  pl = [p[j] for j in range(i, i+3)]
  if pl[0] < pl[1] <pl[2] or pl[2] < pl[1] < pl[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] and p[i]>p[i-1]) or (p[i-1]>p[i] and p[i]>p[i+1]):
    ans=ans+1
print(ans)

Solution (Python):


n = int(input())
arr = list(map(int, input().split(" ")))
start = 0
end = 3
count = 0

while(end <= n):
    temp = arr[start:end]
    high = max(temp)
    low = min(temp)
    if(temp[1] != high and temp[1] != low):
        count += 1
    start += 1
    end += 1

print(count)

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

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

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

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

ans = 0
sanko = []
ssanko = []
for i in range(1, n-1):
    sanko = [p[i-1], p[i], p[i+1]]
    ssanko = sorted(sanko)
    if sanko[1] == ssanko[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]:
        ans+=1
    elif p[i+1]<p[i]<p[i-1]:
        ans+=1
print(ans)

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

for i in range(len(p)-2):
    q = sorted(p[i:i+3])

    if q[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):
  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()))

c=0
for i in range(n-2):
    P2 = sorted(P[i:i+3])
    if P2[1]==P[i+1] :
        c+=1

print(c)

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

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

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

    for i in range(1, n-1):
        p1 = p_lst[i-1]
        p2 = p_lst[i]
        p3 = p_lst[i+1]
        p123_lst = [p1, p2, p3]
        sorted_lst = sorted(p123_lst)

        if p2 == sorted_lst[1]:
            count += 1

    print(count)

if __name__ == '__main__':
    main()

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

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

print(c)

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

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

print(ans)

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

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n = I()
    p = LI()

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

if __name__ == '__main__':
    resolve()

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

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

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

Solution (Python):
n = int(input())
p = list(map(lambda x: int(x), 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()))

from collections import deque
temp = deque()
for i in range(3):
    temp.append(p[i])
counter = 0
temp1 = sorted(temp)
if temp[1] == temp1[1]:
    counter += 1
for i in range(n-3):
    temp.popleft()
    temp.append(p[i+3])
    temp1 = sorted(temp)
    if temp[1] == temp1[1]:
        counter += 1
print(counter)

Solution (Python):

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

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

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

Solution (Python):
n=int(input())
*p,=map(int,input().split())
c=0
for i in range(n-2):
    c+=sorted(p[i:i+3])[1]==p[i+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] 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())
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 = [int(n) for n 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()))
cnt = 0
for i in range(n - 2):
    l = p[i:i+3]
    L = sorted(l)
    if l[1] == L[1]:
        cnt += 1
        
print(cnt)

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

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

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

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

cnt = 0
for i in range(2, n):
  l = [p[i - 2], p[i - 1], p[i]]
  m = sorted(l)
  if l[1] == m[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] 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()))
num = 0
for i in range(0,n-2,1):
    i2 = i+1
    i3 = i+2
    if p[i]<p[i2]<p[i3] or p[i]>p[i2]>p[i3]:
        num += 1
print(num)

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()))
ret = 0
for i in range(n-2):
    if p[i] < p[i+1] < p[i+2]:
        ret += 1
    elif p[i+2] < p[i+1] < p[i]:
        ret += 1
print(ret)

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

Solution (Python):
N = int(input())
MM = input().split()
a = int(MM[0])
b = int(MM[1])
c = int(MM[2])
list1 = [a,b,c]
count = 0
for i in range(N-3):
  aaa =sorted(list1)
  if aaa[1] == b:
    count +=1
  
  a = b
  b = c
  c = int(MM[i+3])
  list1 =[a,b,c]
  
bbb = sorted(list1)
if bbb[1] == b:
  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):
import sys
from collections import defaultdict


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


def main():
    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
        if p[i-1]<p[i] and p[i] < p[i+1]:
            ans +=1

    print(ans)


if __name__ == "__main__":
    main()

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

print(ans)

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

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

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

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

for i in range(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());a=list(map(int,input().split()));count=0
for i in range(n-2): count+=a[i:i+3][1]==sorted(a[i:i+3])[1]
print(count)

Solution (Python):


def main():

    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

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

Solution (Python):











































global FLAG_LOG
FLAG_LOG = False


def log(value):
    
    
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    
    N = int(lines[0])
    
    values = list(map(int, lines[1].split()))
    
    
    
    
    
    
    

    result = 0

    for i in range(N-2):
        tmp = values[i:i+3]
        tmp.sort()
        log(f'i=[{i}]')
        if tmp[1] == values[i+1]:
            result += 1

    return [result]



def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines



def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['5', '1 3 5 4 2']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['9', '9 6 3 2 5 8 7 4 1']
        lines_export = [5]
    return lines_input, lines_export



def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode



def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    
    
    
    
    
    
    
    
    
    
    



if __name__ == '__main__':
    main()

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

Solution (Python):
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
import heapq as hq
gcd = math.gcd
n = ni()
P = list(ma())
cnt = 0
for i in range(1,n-1):
    if P[i] >min(P[i-1],P[i+1]) and P[i] <max(P[i-1],P[i+1]):
        cnt+=1
print(cnt)

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

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

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

cnt = 0

for i in range(1, n-1):
    if sorted(p[i-1:i+2])[1] == 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())
List = list(map(int, input().split()))
res = 0
for i in range(N-2):
  if List[i] < List[i+1] and List[i+1] < List[i+2]:
    res += 1
  elif List[i] > List[i+1] and List[i+1] > List[i+2]:
    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-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()))
count = 0
for i in range(1,n-1):
  if min(a[i-1],a[i+1]) < a[i] and max(a[i-1],a[i+1]) > a[i]:
    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):
def main():
    n = int(input())
    p = list(map(int, input().split()))
    loop = n - 3 + 1
    count = 0
    for i in range(loop):
        if p[i] < p[i + 1] < p[i + 2] or p[i + 2] < p[i + 1] < p[i]:
            count += 1
    print(count)
main()

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

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

p_cut =[]
cnt = 0

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

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

Solution (Python):


import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    p = na()
    ans = 0
    for i in range(1, n-1):
        a = p[i-1:i+2]
        if p[i] != max(a) and p[i] != min(a):
            ans += 1
    print(ans)
    
if __name__ == "__main__":
    main()

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

def checkP(int1, int2, int3):
  l = [int1, int2, int3]
  l.sort()
  if l[1] == int2:
    return True
  else:
    return False

ans = 0

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

print(ans)

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] < l[i+2] or l[i+2] < l[i+1] < l[i]:
        count += 1

print(count)

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

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

count = 0
for i in range(1, len(p)-1):
    p_min = max(p[i-1], p[i], p[i+1])
    p_max = min(p[i-1], p[i], p[i+1])
    if p_min != p[i] and p_max != p[i]:
        count += 1
print(count)

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

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

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

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

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

Solution (Python):
import sys
n = int(input())
array = list(map(int,input().split()))

if not ( 3 <= n <= 20 ): sys.exit()

count = 0
for I in range(n-2):
    if array[I] < array[I+1] < array[I+2]: count += 1
    if array[I] > array[I+1] > array[I+2]: count += 1
print(count)

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

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

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

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

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

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

Solution (Python):
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N = ri()
P = rl()

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

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):
  if n == i + 2:
    break
  else:
    
    p_com = p[i:i+3]
    sp_com= sorted(p_com)
    if sp_com[1] == p_com[1]:
      ans += 1
      
print(ans)

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

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    P = il()

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


if __name__ == '__main__':
    main()

Solution (Python):

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

n=int(input())
p=input_array()

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

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




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

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

print(count)

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

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
pl = LI()
ans = 0
for i in range(2, N):
    p1 = pl[i-2]
    p2 = pl[i-1]
    p3 = pl[i]
    temp = list()
    temp.append(p1)
    temp.append(p2)
    temp.append(p3)
    temp.sort()
    if temp[1] == p2:
        ans += 1
print(ans)

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

for i in range(1, len(ps)-1):
    s1 = ps[i-1] < ps[i] and ps[i+1] > ps[i]
    s2 = ps[i-1] > ps[i] and ps[i+1] < ps[i]
    if s1 or s2:
        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

print(cnt)

Solution (Python):



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

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

print(answer)

Solution (Python):
def main():
    n = int(input())
    P = list(map(int, input().split()))
    ans = 0
    for idx in range(1, n-1):
        if P[idx] == sorted([P[idx-1], P[idx], P[idx+1]])[1]:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

n = k()
p = l()
for i in range(1,n-1):
    a = []
    a.append(p[i-1])
    a.append(p[i])
    a.append(p[i+1])
    a.sort()
    if a.index(p[i]) == 1:
        count += 1

print(count)