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

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
b = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
count=0
list=[]
for i in range(1,len(a)-1):
    list.append(a[i-1])
    list.append(a[i])
    list.append(a[i+1])
    if not max(list) == a[i] and not min(list)==a[i]:
        count+=1
    list=[]
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in range(1,len(li) - 1):
    if li[i - 1] < li[i] < li[i + 1]:
        ans += 1
    if li[i + 1] < li[i] < li[i - 1]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
cnt = int(input())
in_str = [int(i) for i in input().split()]
submit = 0
for i in range(1,cnt-1):
  if in_str[i-1]<=in_str[i] and in_str[i]<=in_str[i+1]:
    submit += 1
  elif in_str[i-1]>=in_str[i] and in_str[i]>=in_str[i+1]:
    submit += 1
print(submit)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
P=list(map(int,input().split()))
x=0
for i in range(0,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)

Submission status: Accepted

Solution code:
import collections
def hit(t):
    sort_t = sorted(t)
    return sort_t[1] == t[1]

n = int(input())
ps = [int(x) for x in input().split()]
window_ps=[]
for i in range(len(ps)-2):
    window_ps.append((ps[i],ps[i+1],ps[i+2]))

res = [hit(t) for t in window_ps]
print(collections.Counter(res)[True])

Submission status: Accepted

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

    elif nums[i-1]>nums[i] and nums[i]>nums[i+1]:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
s=input()
t=list(map(int,input().split()))
i=0
j=0
l=int(s)
for i in range(l-2):
  list=[t[i],t[i+1],t[i+2]]
  if t[i+1]!=max(list) and t[i+1]!=min(list):
    j=j+1
print(j)

Submission status: Accepted

Solution code:
import numpy as np
n = input()
n = int(n)
data = input().split()
count = 0

for i in np.arange(1, n-1):
  a = int(data[i-1])
  b = int(data[i])
  c = int(data[i+1])
  arr = np.array([a, b, c])
  arr = np.sort(arr)
  if arr[1] == b:
    count += 1

print(count)

Submission status: Accepted

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

count = 0
for i in range(1,n-1):
  a = p[i-1]
  b = p[i]
  c = p[i+1]
  if (a<b and b<c) or (c<b and b<a):
    count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
lis=list(map(int,input().split()))
ans=0

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


print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=list(input().split())
for i in range(N):
    a[i]=int(a[i])
ans=0
for i in range(1,N-1):
    if (a[i-1]<a[i] and a[i]<a[i+1]) or  (a[i+1]<a[i] and a[i]<a[i-1]):
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
n_list = list(map(int,input().split()))
a = 0
for i in range(n - 2):
    num = n_list[i:(i + 3)]
    n1 = num[0]
    n2 = num[1]
    n3 = num[2]
    if ((n2 < n1 or n2 < n3) and (n2 > n1 or n2 > n3)):
        a += 1
print(a)

Submission status: Accepted

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

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

Submission status: Accepted

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

res_sum = 0

for i in range(n-2):
    res = True
    p, q, r = p_list[i], p_list[i+1], p_list[i+2]
    if q == min(p, q, r):
        res = False
    elif p == min(p, q, r) and r == min(p, q, r):
        res = False
    elif p == min(p, q, r):
        if q > r:
            res = False
    else:
        if q > p:
            res = False
    if res:
        res_sum += 1

print(res_sum)

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

Submission status: Accepted

Solution code:
N = int(input())
huga = input().split()
p = []
for i in range(N):
  p.append(int(huga[i]))
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)

Submission status: Accepted

Solution code:

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

count = 0

for i in range(n-2):
    num_id = i+1
    temp = [num_list[num_id-1], num_list[num_id], num_list[num_id+1]]
    list_sorted = sorted(temp, reverse=True)
    if list_sorted[1] == num_list[num_id]:
        count += 1


print(count)

Submission status: Accepted

Solution code:
N = int(input())
p = list(map(int, 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
  if((p[i] > p[i + 1]) and (p[i + 1] > p[i + 2])):
    res += 1
  if((p[i] == p[i + 1]) and (p[i] > p[i + 2])):
    res += 1
  if((p[i] == p[i + 2]) 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] != max(p[i-1:i+2]) and p[i] != min(p[i-1:i+2]):
    count += 1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
n = input()
p = list(map(int,input().split()))
res = 0
for i, num in enumerate(p):
	if(1 <= i and i <= (len(p) - 2)):
		li = [p[i-1],p[i],p[i + 1]]
		li.sort()
		if((p[i-1] != p[i + 1]) and (p[i-1] != p[i]) and (p[i] != p[i + 1]) and (li[1] == p[i])):
			res = res + 1
print(res)

Submission status: Accepted

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

c = 0
for i in range(1, len(p)-1):
  #print(p[i-1], p[i] ,p[i+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]):
    c += 1
print(c)

Submission status: Accepted

Solution code:
# ordinary number
n = int(input())
list = [int(i) for i in input().split(' ')]
# print(n,list)
ans = 0
for i in range(1,n-1):
	tmp = list[i-1:i+2]
	tmp.sort()
	# print(tmp)
	if tmp[0] != list[i] and  tmp[1] == list[i]:
		ans = ans + 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(1, n-1):
  temp = p[i-1:i+2]

  if temp[1] == sorted(temp)[1]:
    counter+=1
    
print(counter)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int,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())
p = list(map(int,input().split()))
ans = 0

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

print(ans)

Submission status: Accepted

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

answer = 0
for i in range(1,N-1):
  a,b,c = P[i-1:i+2]
  if b != min(a,b,c) and b != max(a,b,c):
    answer += 1

print(answer)

Submission status: Accepted

Solution code:
# B - Ordinary Number

def main():
	n = int(input())
	p = list(map(int,input().split()))
	count = 0
	for i in range(1, n-1):
		if check(p, i):
			count += 1
	print(count)

def check(p, i):
	if ((p[i -1] < p[i]) and (p[i] < p[i + 1])) or ((p[i -1] > p[i]) and (p[i] > p[i + 1])):
		return True
	else:
		return False

main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(len(p) - 2):
    q = [p[i], p[i + 1], p[i + 2]]
    if not q[1] == max(q) and not q[1] == min(q):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
line = list(map(int,input().split()))
#print(str(line) + "■")

c = 0
for i in range(n-2):
    alist = []
    alist.append(line[i])
    alist.append(line[i+1])
    alist.append(line[i+1+1])
    if alist[0] == max(alist) and alist[2] == min(alist):
        c += 1
    elif  alist[0] == min(alist) and alist[2] == max(alist):
        c += 1
    else:
        pass
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def con(n, lists):
  cnt = 0
  for i in range(1, n-1):
    if lists[i-1] > lists[i] > lists[i+1] or lists[i+1] > lists[i] > lists[i-1]:
      cnt += 1
  return cnt

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

Submission status: Accepted

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

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:
import collections

n = int(input())
p = list(map(int, input().split()))
count2 = []
for i in range(1, n-1):
    count = []
    count.append(p[i-1])
    count.append(p[i])
    count.append(p[i+1])
    count.sort()
    if(count[1] == p[i]):
        count2.append(count[1])
ans = collections.Counter(count2)
print(len(ans))

Submission status: Accepted

Solution code:
import numpy as np

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

cnt = 0
for i in range(1,len(l)-1):
    l_tmp = [l[i-1], l[i], l[i+1]]
    l_tmp.sort()
    arr_tmp = np.array(l_tmp)
    if len(arr_tmp[arr_tmp>l[i]])==1:
        cnt += 1
        
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
p = [int(i) for i in input().split()]
cnt = 0
for i in range(1, n-1):
    #print('{0},{1},{2}'.format(p[i-1], p[i], p[i+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)

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

Submission status: Accepted

Solution code:
N = int(input())
l = [int(i) for i in input().split()]
count = 0
for i in range(len(l) - 2):
    ll = l[i:i + 3]
    ll.sort()
    if ll[1] == l[i+1]:
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
num_list = list(int(i) for i in input().split())
ans = 0
for i in range (N-2):
	if num_list[i+1] > num_list[i]:
		if num_list[i+2] > num_list[i+1]:
			ans +=1
	else:
		if num_list[i+1] > num_list[i+2]:
			ans +=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans=0
for ii in range(1,n-1):
    p_order = sorted(list([p[ii-1],p[ii],p[ii+1]]))
    if p_order.index(p[ii]) == 1 and p_order[0] != p_order[1]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
p_i = list(map(int, input().split()))
count = 0

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

Submission status: Accepted

Solution code:
s=0
x=int(input())
y=list(map(int,input().split()))
for i in range(x-2):
  if y[i] < y[i+1] < y[i+2] or y[i+2] < y[i+1] < y[i]:
    s+=1;
print(s)

Submission status: Accepted

Solution code:
n = int(input())
p = [int(x) for x in input().split()]
print(sum([1 if min(p[i:i+3]) < p[i+1] < max(p[i:i+3]) else 0 for i in range(n-2)]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
P = [int(el) for el in input().split(" ")]

count = 0
for i in range(len(P)-2):
    p1 = P[i]
    p2 = P[i+1]
    p3 = P[i+2]
    
    if p1 < p2 < p3 or p3 < p2 < p1:
        count += 1

print(count)

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int, input().split()))
c = 0
for j in range(0,N-2):
    if l[j]<l[j+1]<l[j+2] or l[j+2]<l[j+1]<l[j] or (l[j]==l[j+2] and l[j]<l[j+1]) or (l[j]==l[j+2] and l[j]<l[j+1]) or (l[j]==l[j+1] and l[j+2]<l[j+1]) or (l[j+1]==l[j+2] and l[j]<l[j+1]):
        c+=1
print(c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
P=[int(x) for x in input().split()]
count=0
for i in range(n-2):
  p1=P[i]
  p2=P[i+1]
  p3=P[i+2]
  if p2>p1 and p2<p3:
    count+=1
    
  if p2>p3 and p2<p1:
    count+=1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# B - Ordinary Number

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

Submission status: Accepted

Solution code:
n = int(input())
p_list = list(map(int, input().split()))
count = 0

for i in range(n-2):
    aim = p_list[i+1]
    tmp_list = [p_list[i], p_list[i + 1], p_list[i + 2]]
    tmp_list.sort()
    if tmp_list[1] == aim:
        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] > 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)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
start = 0
end = 3
counter = 0
for i in range(N-2):
    ls = a[start:end]
    if ls[0] < ls[1] and ls[2] < ls[1]:
        counter = counter
        start = start + 1
        end = end + 1
    elif ls[1] < ls[0] and ls[1] < ls[2]:
        counter = counter
        start = start + 1
        end = end + 1
    else:
        counter = counter + 1
        start = start + 1
        end = end +1
print(counter)

Submission status: Accepted

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

S = 0

for i in range(N-2):
	if P[i] <= P[i+1]:
		if P[i+1] < P[i+2]:
			S += 1
			continue
	if P[i+2] <= P[i+1]:
		if P[i+1] < P[i]:
			S += 1
			continue
	if (P[i+2] == P[i]) & (P[i+1] > P[i]):
		S += 1
print(S)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy

N = int(input())
p = numpy.asarray(list(map(int,input().split())))

p_diff = numpy.diff(p)

# p_diff = p_diff[p_diff != 0]
p_diff = numpy.where(p_diff > 0, 1, -1)

p_diff2 = numpy.diff(p_diff)

print(len(p_diff2[p_diff2 == 0]))

Submission status: Accepted

Solution code:
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n-2):
  lst=[p[i],p[i+1],p[i+2]]
  m=min(lst)
  P=p[i+1]
  del lst[lst.index(m)]
  if min(lst)==P:
    cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

count = 0

for i in range(1, len(list)-1):
    num = list[i]
    if (num > list[i-1] and num < list[i+1]) or (num < list[i-1] and num > list[i+1]):
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    input()
    a = list(map(int, input().split()))
    count = 0
    for i in range(0, len(a) - 2):
        old = a[i:i + 3]
        new = sorted(old)
        if old[1] == new[1]:
            count += 1
    print(count)

Submission status: Accepted

Solution code:
N = input()
P = list(input().split())
count = 0

for i in range(len(P)-2) :
	judge_list = list() 
	midle = int(P[i+1])
	judge_list.extend([int(P[i]),int(P[i+1]),int(P[i+2])])
	judge_list.sort()

	if midle == judge_list[1]:
		count+=1
print(count)

Submission status: Accepted

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

cnt = 0

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
p_list = list(map(int, input().split()))
counter = 0
for i in range(n-2):
    if p_list[i] < p_list[i+1] and p_list[i+1] < p_list[i+2]:
        counter += 1
    elif p_list[i] > p_list[i+1] and p_list[i+1] > p_list[i+2]:
        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] and p[i + 1] < p[i + 2]:
        s += 1
    elif p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
        s += 1
print(s)

Submission status: Accepted

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

count=0
for i in range(n-2):
  ext=[]
  for k in range(3):
    ext.append(li[i+k])
    
  ext.sort()
  if ext[1]==li[i+1]:
    count+=1
    
print(count)

Submission status: Accepted

Solution code:
# a = 9
# b = '9 6 3 2 5 8 7 4 1'

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

l = n - 2

r = 0

for i in range(l):
    l2 = p[i:3+i]
    if l2[0] < l2[1]:
        if l2[1] < l2[2]:
            r += 1
    else:
        if l2[1] > l2[2]:
            r += 1

print(r)

Submission status: Accepted

Solution code:
N = int(input())
lst = list(map(int, input().split()))
score = 0
for i in range(N-2):
	if (lst[i]-lst[i+1])*(lst[i+2]-lst[i+1]) < 0:
		score += 1
	else:
		pass
print(score)

Submission status: Accepted

Solution code:
import numpy as np

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

cnt=0
for i in range(1, n-1):
    tmp = np.array([p[i-1], p[i], p[i+1]])
    if np.argsort(tmp)[1] == 1:
        cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
def ordinary_number(N: int, p: list)->int:
    return sum(
        (p[i-1] < p[i] and p[i] < p[i+1]) or (p[i-1] > p[i] and p[i] > p[i+1])
        for i in range(1, N-1))


if __name__ == "__main__":
    N = int(input())
    P = [int(s) for s in input().split()]

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

print(count)

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

answer=0
for i in range(len(lists)-2):
    tmp = lists[i:i+3]
    if(max(tmp)==tmp[1] or min(tmp)==tmp[1]):
        continue
    answer+=1

print(answer)

Submission status: Accepted

Solution code:
# B
if __name__=='__main__':
    n = int(input())
    p = [int(x) for x in input().split()]
    q = [1 if p[i]<p[i+1] else -1 for i in range(n-1)]
    r = [q[i]*q[i+1] for i in range(n-2)]
    print(r.count(1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for atcorder program
###

import sys
import math
import array

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def main():
    
    N = int(input())
    P = None
    A = []
    P = [int(w) for w in input().split()]

    for i in range(N-2):
        if P[i] < P[i+1] < P[i+2]:
            A.append(P[i+1])
        elif P[i] > P[i+1] > P[i+2]:
            A.append(P[i+1])

    print(len(A))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
n = list(map(int,input().split()))
S = []
count=0
for i in range(1,len(n)-1):
    S = []
    S.extend(n[i-1:i+2])
    S.sort()
    if S[1]==n[i]:
        count+=1
    del S    
print(count)

Submission status: Accepted

Solution code:
import re
import numpy as np


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

flag=0
for i in range(N-2):
  p0=ps[i]
  p1=ps[i+1]
  p2=ps[i+2]
  
  if np.sort(np.array([p0,p1,p2]))[1]==p1:
    flag+=1
print(flag)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
inputs = sys.stdin.readlines()
n = int(inputs[0])
p = [int(x) for x in inputs[1].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)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ls = list(map(int,input().split(" ")))
ans = 0

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
p = [int(i) for i in 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)

Submission status: Accepted

Solution code:
str = input()
n = int(str.split()[0])

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

print(a)

Submission status: Accepted

Solution code:
from collections import deque
n=int(input())
p=list(map(int, input().split()))

Q=deque(maxlen=3)
Q.append(p[0])
Q.append(p[1])

count = 0
for i in range(2,n):
    Q.append(p[i])
    #print(Q)
    if Q[0] <= Q[1] <= Q[2] or Q[2] <= Q[1] <= Q[0]:
        count += 1
print(count)

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#n=int(input())
#import fractions
#import itertools
#import math
#lis=list(input().split())
#lis=list(map(float,input().split()))
#S=input()

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

print(ans)