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



Sample input:
5
1 3 5 4 2


Sample output:
2

Submission status: Accepted

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


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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys

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

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

	

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

Submission status: Accepted

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

cnt = 0

len_min2 = len(n2) - 2

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

Submission status: Accepted

Solution code:
from sys import stdin


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

    p = [int(x) for x in stdin.readline().split()]
    count = 0

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

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

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

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

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

print(a)

Submission status: Accepted

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

Submission status: Accepted

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


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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def second_smallest(numbers):
    m1, m2 = float('inf'), float('inf')
    for x in numbers:
        if x <= m1:
            m1, m2 = x, m1
        elif x < m2:
            m2 = x
    return m2

for i in range(n-1):
  if i != 0:
    a = p[i-1:i+2]
    if a[0] != a[1] and a[1] != a[2] and a[0] != a[2]:
      if p[i] == second_smallest(a):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
p = input().split(' ')

cnt = 0
for i in range(n):
    tmp = list(map(int, p[i:i+3]))
    if len(tmp) == 3:
        if (tmp[0] < tmp[1] and tmp[1] < tmp[2]) or (tmp[1] < tmp[0] and tmp[2] < tmp[1]):
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
#{1, 2, ..., n} の順列 p = {p1,p2, ..., pn } があります。
#以下の条件を満たすような pi (1<i<n) がいくつあるかを出力してください。
#pi−1, pi, pi+1 の 3 つの数の中で、pi が 2 番目に小さい。

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

    else:
        ans==ans
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
input_list = [int(i) for i in input().split(' ')]

count = 0
past = None
past_diff = None
for i in input_list:
    if past:
        if past_diff is not None and (i - past) * past_diff > 0:
            count += 1
        past_diff = i - past
    past = i

print(count)

Submission status: Accepted

Solution code:
num_input = int(input())

arr = [int(s) for s in input().split(' ')]

meet_cond = 0
for i in range(0, num_input-3+1):
    x, y, z = arr[i], arr[i+1], arr[i+2]

    if min(x, y, z) == y or max(x, y, z) == y:
        pass
    else:
        meet_cond += 1

print(meet_cond)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))

cnt = 0

for num in range(0, n-2):
  if A[num+1] > A[num] and A[num+1] < A[num+2]:
    cnt += 1
  elif A[num+1] < A[num] and A[num+1] > A[num+2]:
    cnt +=1

print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
P=[int(i) for i in input().split()]
mes=0
for i in range(len(P)):

	if i!=0 and i!=N-1:
		if (P[i+1]<P[i] and P[i+1]<=P[i-1] and P[i]<=P[i-1])or(P[i-1]<P[i] and P[i-1]<=P[i+1] and P[i]<=P[i+1]):
			mes+=1
print(mes)

Submission status: Accepted

Solution code:
N = input()
D = map(int, raw_input().split())

cnt=0
lop=0

while lop<N-2:
  if max(D[lop],D[lop+1],D[lop+2])!=D[lop+1] and min(D[lop],D[lop+1],D[lop+2])!=D[lop+1]:
    cnt=cnt+1
  lop=lop+1
print (cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ns = input().split(" ")
for i in range(n):
    ns[i] = int(ns[i])

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
coin = 0
def check(Pn,a,coin):
    if Pn[a - 1] < Pn[a] < Pn[a + 1]:
        coin = coin + 1
    elif Pn[a + 1] < Pn[a] < Pn[a - 1]:
        coin = coin + 1
    else:
        coin = coin + 0
    return coin
n = int(input())
Pn = list(map(int,input().split()))
for a in range(1,n-1):
    coin = check(Pn,a,coin)
print(coin)

Submission status: Accepted

Solution code:


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

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

Submission status: Accepted

Solution code:
n=input()
s=input()
s=s.replace(" ",",")
s=str(s).split(",")
l=list(s)
a=0
for i in range(2,int(n)):
  if int(l[i-2])<int(l[i-1]) and int(l[i-1])<int(l[i]):
    a=a+1
  if int(l[i-2])>int(l[i-1]) and int(l[i-1])>int(l[i]):
    a=a+1
print(a)

Submission status: Accepted

Solution code:
cnt = int(input())
l = list(map(int, input().split()))
count = 0
 
for i in range(cnt-2):
  a,b, c = l[i], l[i+1], l[i+2]
  if (a < b and b < c) or( a>b and b> c):
    count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().split()))
# dct = {}
# for i in range(n):
#     dct[i] = lst[i]

# ans = sorted(dct.items(), key = lambda x : x[1])
# if ans[1][0]==2:
   
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)

Submission status: Accepted

Solution code:
#B問題
n = int(input())
p = input().split()
p = [int(i) for i in p]
count = 0
for i in range(n-2):
    if p[i+1] <max(p[i:i+3]) and p[i+1]>min(p[i:i+3]):
      count +=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq

n = int(input())
a = list(map(int, input().split()))
    
count = 0
for i in range(1, n-1):
    # 小さい順で2番目の値が真ん中の値と一致しているかどうか
    sl = heapq.nsmallest(2, a[i-1:i+2])
    if sl[1] == a[i]:
        count += 1
    
print(count)

Submission status: Accepted

Solution code:
n = int(input())
P = map(int,input().split())
p = [i for i in P]
count =0
for i in range(len(p)-2):
    q = ()
    q = p[i:i+3]
    if len(q) == 3:
        a = q[1]
        q.sort()
        if a == q[1]:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import os, sys, re, math

N = int(input())
s = [int(n) for n in input().split(' ')]

cnt = 0
for i in range(1,N-1):
    temp = s[i-1:i+2]
    temp.sort()
    if temp[1] == s[i]:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
num =set()
for i in range(n-2):
    if a[i]<=a[i+1] and a[i+1]<=a[i+2]:
        num.add(a[i+1])
    elif a[i]>=a[i+1] and a[i+1]>=a[i+2]:
        num.add(a[i + 1])
print(len(num))

Submission status: Accepted

Solution code:
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]:
    count += 1
  elif l[i] > l[i+1] > l[i+2]:
    count += 1
  else:
    count += 0
print(count)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))
#n = 9
#p = [9, 6, 3, 2, 5, 8, 7, 4, 1]

collect = 0
for i in range(n - 2):
    p_small = p[i: i + 3]
    #print(p_small, (p_small[0] < p_small[1] and p_small[2] >= p_small[1]) or (p_small[2] < p_small[1] and p_small[0] >= p_small[1]))
    
    if (p_small[0] < p_small[1] and p_small[2] >= p_small[1]) or (p_small[2] < p_small[1] and p_small[0] >= p_small[1]):
        collect += 1
        
print(collect)

Submission status: Accepted

Solution code:
N = int(input())
pp = list(map(int, input().split(" ")))

count = 0

i = 1
while i < N - 1:
    if pp[i - 1] < pp[i] < pp[i + 1] or pp[i - 1] > pp[i] > pp[i + 1]:
        count += 1
    i += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import re
from collections import Counter

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

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

print(ans)

Submission status: Accepted

Solution code:
x=map(int, input())
a=map(int, input().split())
b=list(a)
c=len(b)

count=0
for i in range(1,c-1):
  tree= [b[i-1], b[i], b[i+1]]
  if (min(tree) != b[i]) and (max(tree) != b[i]):

  	count=count+1
  else:
  	next
    
print(count)

Submission status: Accepted

Solution code:
n=int(input())
t =list(map(int, input().split()))
s=0
counter=0
for i in t:
    if s==0:
        s+=1
        left=i
        continue
    if s==1:
        s+=1
        mid=i
        continue

    if left>mid:
        if mid>i:
            counter+=1
    if left<mid:
        if mid<i:
            counter+=1
    left=mid
    mid=i

print(counter)

Submission status: Accepted

Solution code:
#coding:utf-8
#coding:utf-8
N = int(input())
P = list(map(int,input().split()))
sm = 0
for i in range(len(P)-2):
    sm += int(sorted(P[i:i+3])[1]==P[i+1])
print (sm)

Submission status: Accepted

Solution code:
cnt = 0
n = int(input())
p_lis = []
p_lis = list(map(int,input().split()))
for i in range(1,len(p_lis)-1):
    if p_lis[i+1] > p_lis[i] > p_lis[i-1]:
        cnt += 1
    elif p_lis[i-1] > p_lis[i] > p_lis[i+1]:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


from sys import stdin

N = int(stdin.readline())
P = [int(x) for x in stdin.readline().rstrip().split()]

cnt = 0

for i in range(N-2):
    tmp_list = P[i:i+3]
    tmp_list_unique = list(set(tmp_list))
    tmp_list_unique.sort()
    if tmp_list_unique[1] == tmp_list[1]:
        cnt += 1


print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
p = [int(i) for i in 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] or (p[i] == p[i+2] and p[i+1] < p[i]):
        count += 1

print(count)

Submission status: Accepted

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

a = []
for i in range (N-1):
    a.append(P[i+1] - P[i])

ans = 0
for i in range (N-2):
    if a[i+1]/a[i] > 0:
        ans = ans + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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] > p[i+1] > p[i+2]:
    count += 1
  else:
    pass
  
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
str=input()
p_str=str.split(" ")
p=[int(tmp) for tmp in p_str]
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)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int, input().split()))

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

print(l)

Submission status: Accepted

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

    print(len([i for i in range(1, n - 1) if sorted([p[i - 1], p[i], p[i + 1]]).index(p[i]) == 1]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
d_a = input().split()

d = []
for i in range(n):
    d.append(int(d_a[i]))

ans = 0
for i in range(1,n-1):
    a = []
    a.append(d[i-1])
    a.append(d[i])
    a.append(d[i+1])
    
    asd = sorted(a)
    if asd[1] == d[i]:
        ans += 1
        

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

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

for i, pi in enumerate(p):
    if i == 0:
        continue
    elif i == n-1:
        break
    tmplist = sorted([pi, p[i-1], p[i+1]])
    if pi == tmplist[1]:
        count = count + 1

print(count)

Submission status: Accepted

Solution code:
N = [int(i) for i in input().split()][0]
P = [int(i) for i in input().split()]

count=0
for i in range(0,N-2):
  tmp = [P[i],P[i+1],P[i+2]]
  tmp.sort()
  if P[i+1]==tmp[1]:
    count+=1
  elif tmp[0]==tmp[1] or tmp[0]==tmp[2]:
    count+=1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
c = list(map(int, input().split()))
count=0
for i in range(1, n-1):
  temp = []
  temp.append(c[i-1])
  temp.append(c[i])
  temp.append(c[i+1])
  temp.sort()
  if c[i] == temp[1]:
    count += 1
    
print(count)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from operator import itemgetter, attrgetter
n=0
 
n = input()
d_list= list(map(int, input().split()))
cnt=0
for i in range(1,len(d_list)-1):
    b=d_list[i-1]
    m=d_list[i]
    a=d_list[i+1]
    if (b< m <a) or (a< m< b):
        cnt+=1
        
    
print(cnt)

Submission status: Accepted

Solution code:
n = input()
numbers = [int(n) for n in input().split()]

result = 0

number_list = []

for i in numbers:
	number_list.append(i)
	if len(number_list) < 3:
		continue
	elif len(number_list) > 3:
		number_list.pop(0)

	sorted_list = sorted(number_list)
	# print(sorted_list, number_list)
	if sorted_list[1] == number_list[1]:
		result += 1

print(result)

Submission status: Accepted

Solution code:
n = int(input())
P = [int(i) for i in input().split()]
count = 0
for i in range(1, n-1):
    if min(P[i-1:i+2]) != P[i] and max(P[i-1:i+2]) != P[i]: count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
pa = list(map(int, input().split()))

c = 0
for i in range(1, len(pa) - 1):
    ll = pa[i-1:i+2]
    ls = sorted(ll)
    if ll[1] == ls[1]:
        c += 1
print(c)

Submission status: Accepted

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

cnt = 0
l_ext = []

for i in range(n-2):
  l_ext.clear()
  l_ext.append(l[i])
  l_ext.append(l[i+1])
  l_ext.append(l[i+2])
  if sorted(l_ext)[-2] == l_ext[1]:
    cnt += 1
  i += 1

print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin
from heapq import nsmallest

n = int(stdin.readline())
p = [int(x) for x in stdin.readline().rstrip().split()]

# [heapq — Heap queue algorithm — Python 3\.7\.4rc1 documentation](https://docs.python.org/3/library/heapq.html#heapq.nsmallest)

cnt = 0

for i in range(n):
    if i == 0 or i == n - 1 :
        continue
    if nsmallest(2, p[i-1:i+2])[-1] == p[i]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = [int(x) for x in input().split()]
count=0
for i in range(1,N-1):
  l=[S[i-1],S[i],S[i+1]]
  l.sort()
  if l[1]==S[i]:
    count+=1
    
print(count)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n = input()
a = [int(i)for i in input().split(" ")]
ans = 0
for i in range(int(n)-2):
	if a[i+1] != max(a[i:i+3]) and a[i+1] != min(a[i:i+3]):
		ans += 1
print(ans)

Submission status: Accepted

Solution code:
a = [input().split() for i in range(2)]
li = a[-1]
lis = [int(i) for i in li]
lis
n = int(a[0][0])
cnt = 0
for i in range(0,n-2):
    l = [lis[i],lis[i+1],lis[i+2]]
    l_sort = sorted(l)
    if(l[1] == l_sort[1]):
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
p = list(map(int, input().split()))
count = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def logic():
  n = int(input())
  b = list(map(int, input().split()))
  count = 0
  i = 1
  while i < n - 1:
    if b[i] < b[i - 1]:
      if b[i] > b[i + 1]:
        count += 1
    elif b[i] < b[i + 1]:
      if b[i] > b[i - 1]:
        count += 1
    i += 1
  print(count)



if __name__ == '__main__':
    logic()

Submission status: Accepted

Solution code:
k = 0
a = input()

lista = input().split()

for c in range(1, len(lista)-1):

    if int(lista[c-1]) > int(lista[c]) > int(lista[c+1]) or int(lista[c-1]) < int(lista[c]) < int(lista[c+1]):
        k += 1

print(k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
p = [int(i) for i in input().split()]
a = 0
for i in range(n - 2 ):
    if (p[i] - p[i+1]) > 0  and p[i+2] - p[i+1] < 0:
        a += 1
    elif (p[i] - p[i+1]) < 0  and p[i+2] - p[i+1] > 0:
        a += 1

print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = 0
a = input()

lista = input().split()

for c in range(1, len(lista)-1):

    if int(lista[c-1]) > int(lista[c]) > int(lista[c + 1]) or int(lista[c - 1]) < int(lista[c]) < int(lista[c + 1]):
        k += 1

print(k)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
oc = 0
c = 0

for i in l[1:n-1]:
    nl = sorted(l[oc:oc+3])
    if i == nl[1]:
        c += 1
    oc += 1

print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def min_count(nums):
    c = 0
    for i in range(len(nums)-2):
        if nums[i]<nums[i+1]<nums[i+2]:
            c = c + 1
        elif nums[i+2]<nums[i+1]<nums[i]:
            c = c + 1
    return c
a = input()
b = map(int,input().split())
c =[]
for x in b:
	c.append(x)
print(min_count(c))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

Submission status: Accepted

Solution code:
n = int(input())
ppp = list(map(int,input().split()))
cnt = 0
mini = 0
maxx = 0
p = [0]*3

for i in range(n-2):
    p[0] = ppp[i]
    p[1] = ppp[i+1]
    p[2] = ppp[i+2]
    
    mini = min(p)
    maxx = max(p)
    
    if mini != p[1]:
        if maxx != p[1]:
            cnt += 1
        
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split())) 
count = 0

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

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
n = int(input())
p = map(int, input().split())
p = list(p)
n = len(p)
n = n - 1

c = 0
for i in range(1, n):
    i0 = i -1
    i1 = i + 1
    if (p[i] > p[i0]) & (p[i] < p[i1]):
        c += 1
    elif (p[i] < p[i0]) & (p[i] > p[i1]):
        c += 1
    else:
        c += 0    
print(c)

Submission status: Accepted

Solution code:
a=int(input())
b=list(input().split( ))
c=list(map(int, b))
count = 0

for  j  in range(a-2):
    d = []
    d.append(c[j])
    d.append(c[j+1])
    d.append(c[j+2])
    d.sort()
    if d[1]==c[j+1]:
          count += 1

print(count)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
Data = list(map(int, input().split()))

counter = 0

for i in range(n-2):
  min_list = []
  min_list.append(Data[i])
  min_list.append(Data[i+1])
  min_list.append(Data[i+2])
  if min_list[1] != min(min_list) and min_list[1] != max(min_list):
    counter += 1

print(counter)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))
i = 2
m = 0
while(i<n):
    x = p[i-2]
    y = p[i-1]
    z = p[i]
    if(x<y<z or x>y>z):
        m += 1
    i += 1
print(m)

Submission status: Accepted

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

print(count)