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

ans = 0
for i in range(1, n-1):
  if p[i-1] > p[i+1]:
    m = p[i+1]
    M = p[i-1]
  else:
    m = p[i-1]
    M = p[i+1]
  
  if m < p[i] < M:
    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] < p[i+2] or p[i+2] < p[i+1] < p[i]:
		cnt+=1
		
print(cnt)

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

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=list(map(int,input().split()))
s=0
for i in range(1,n-1):
    if (l[i]>l[i-1] and l[i]<l[i+1]) or (l[i]<l[i-1] and l[i]>l[i+1]):
        s+=1
print(s)

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

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
p=list(map(int, input().split()))
count=0
for i in range(n-2):
    box = p[i:i+3]
    boxed = sorted(box)
    if box[1]==boxed[1]:
        count+=1
    else:
        pass
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:
n = int(input())
ps = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
    if ps[i] < ps[i+1] and ps[i+1] <= ps[i+2]:
        cnt+=1
    elif ps[i+2] < ps[i+1] and ps[i+1] <= ps[i]:
        cnt+=1
    else:
        continue
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):
  a=P[i-1]
  b=P[i]
  c=P[i+1]
  if max([a,b,c])!=b and min([a,b,c])!=b:
    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-1]>A[i] and A[i]>A[i+1]:
		count += 1
	elif A[i-1]<A[i] and A[i]<A[i+1]:
		count += 1
print(count)

Submission status: Accepted

Solution code:
N, *L,  = [list(map(int, s.split())) for s in open(0)]
A = L[0]

cnt = 0
for i in range(len(A) - 2):
    ma = max(A[i], A[i+1], A[i+2])
    mi = min(A[i], A[i+1], A[i+2])
    if A[i+1] not in [ma, mi]:
        cnt += 1
print(cnt)

Submission status: Accepted

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

ans = 0
data = []
for p in P:
   if len(data) == 2:
      data.append(p)
      if data[0] < data[1] and data[1] < data[2]:
          ans += 1
      elif data[2] < data[1] and data[1] < data[0]:
          ans += 1
      data.pop(0)
   else:
      data.append(p)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(1, len(p)-1): ans += sorted([p[i-1], p[i], p[i+1]])[1] == p[i]
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]<p[i+2] or p[i]>p[i+1]>p[i+2]:
    cnt+=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] != max([p[i-1], p[i], p[i+1]]) and p[i] != min([p[i-1], p[i], p[i+1]]):
        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):
    q=sorted(p[i:i+3])
    if q[1]==p[i+1]:
        count+=1

print(count)

Submission status: Accepted

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

new_numbers = []

cnt = 0
for i in range(1, len(numbers)-1):
    numberset = [numbers[i-1], numbers[i], numbers[i+1]]
    numberset.sort()
    if numberset.index(numbers[i]) == 1:
        cnt += 1
        
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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 -1] < A[i] < A[i+1]) or (A[i-1] > A[i] > A[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(1,N-1):
  if min([P[i-1],P[i],P[i+1]]) != P[i] and P[i] != max([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()))
ans = 0
for i in range(1, n - 1):
    x = [p[i - 1], p[i], p[i + 1]]
    x.sort()
    if x[1] == p[i]:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
P = list(map(int, input().split()))
print(sum(p0 < p1 < p2 or p0 > p1 > p2 for p0, p1, p2 in zip(P, P[1:], P[2:])))

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

Submission status: Accepted

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

ans = 0
for i in range(N - 2):
    a = [L[i], L[i + 1], L[i + 2]]
    a = sorted(a)
    if a[1] == L[i + 1]:
       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
    else:
        continue

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

Submission status: Accepted

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

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

res = 0
for i in range(N-2):
	p = P[i:i+3]

	if p[1] == sorted(p)[1]:
		res+=1

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

#+2まで考慮してるから、nの数を-2にして調整しろ
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 = ans + 1

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

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

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

Submission status: Accepted

Solution code:
N = int(input())
P = [int(x) for x 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:
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)

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

Submission status: Accepted

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

cnt = 0
for i in range(1, n-1):
  if p_list[i] != max(p_list[i-1], p_list[i], p_list[i+1]) and p_list[i] != min(p_list[i-1], p_list[i], p_list[i+1]) :
    cnt += 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

number = 0
for i in range(1, len(list_p)-1):
    if (list_p[i-1] < list_p[i] and list_p[i] < list_p[i+1]) or (list_p[i-1] > list_p[i] and list_p[i] > list_p[i+1]):
        number += 1

print(number)

Submission status: Accepted

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

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

count = 0
for i in range(len(ps) - 2):
    if (ps[i] < ps[i + 1] < ps[i + 2]) or (ps[i] > ps[i+1] > ps[i+2]):
        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())
p=[int(i) for i in input().split()]
ans=0
for i in range(n-2):
    a,b,c=p[i:i+3]
    if a<b<c or a>b>c:
        ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
cnt=0
length=len(l)
for i in range(1,length-1):
  if (l[i]>l[i-1] and l[i]<l[i+1]):
    cnt+=1
  elif(l[i]<l[i-1] and l[i]>l[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(1,n-1):
    if sorted(P[i-1:i+2])[1]==P[i]: #終点のindexに注意.
        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 = 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)

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

Submission status: Accepted

Solution code:

N = int(raw_input())
P = map(int, raw_input().split())

ans = 0
for i in xrange(1, N-1):
    if P[i] > P[i-1] and P[i] < P[i+1]:
        ans += 1
    elif P[i] < P[i-1] and P[i] > P[i+1]:
        ans += 1

print ans

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    ppp = list(map(int, input().split()))
    ans = 0
    for i in range(1,n-1):
        c = 0
        if ppp[i] > ppp[i-1]:
            c += 1
        if ppp[i] > ppp[i+1]:
            c += 1
        if c == 1:
            ans += 1
    print(ans)
resolve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math
input = sys.stdin.readline

MOD = 10 ** 9 + 7


def main():
    N = int(input())
    p = list(map(int, input().split()))
    ans = 0

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
length = int(input())
num_list = list(map(int,input().split(' ')))
count = 0
for i in range(1,length-1,1):
  if (num_list[i-1] < num_list[i]) and (num_list[i] < num_list[i+1]):
    count += 1
  if (num_list[i-1] > num_list[i]) and (num_list[i] > num_list[i+1]):
    count += 1
    
print(count)

Submission status: Accepted

Solution code:
n = int(input())
p = list(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(n-2)))

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n=int(input())
P=list(map(int,input().split()))
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())
p = [num for num in 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)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(m)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

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

print(buf)

Submission status: Accepted

Solution code:
n = int(input())

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

count=0

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

count_pn = 0
for i in range(1,N-1):
    if ( Pn[i-1] < Pn[i] < Pn[i+1] ) or ( Pn[i+1] < Pn[i] < Pn[i-1] ):
        count_pn += 1
print(count_pn)

Submission status: Accepted

Solution code:
# ABC 132: B – Ordinary Number
n = int(input())
p = [int(s) for s in input().split()]

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

print(the_number)

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]) or (p[i]>p[i+1] 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 i in range(1,len(P)-1):
    lst = [P[i-1],P[i],P[i+1]]
    lst.sort()
    if lst[1] == P[i]:
        count+=1
print(count)

Submission status: Accepted

Solution code:
N = int(input())
P = [int(x) for x in input().split()]
count = 0
for i in range(1,N-1):
  if P[i]!=min(P[i-1],P[i],P[i+1]) and P[i]!=max(P[i-1],P[i],P[i+1]):
    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):
	ans += (p[i] < p[i + 1] < p[i + 2] or p[i + 2] < p[i + 1] < p[i])
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def print_ans(n,pr):
    """Test Case
    >>> print_ans(5, [1, 3, 5, 4, 2])
    2
    >>> print_ans(9, [9, 6, 3, 2, 5, 8, 7, 4, 1])
    5
    """
    ans = 0
    for i in range(1, n-1):
        tmp_arr = sorted([pr[i-1],pr[i],pr[i+1]])
        if  tmp_arr[1] == pr[i]:
            ans +=1
    print(ans)

if __name__ == '__main__':
    n = int(input().rstrip())
    pr = list(map(int, input().rstrip().split()))
    print_ans(n,pr)

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

print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
ans = 0
n = inp()
p = inpl()

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

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))
l = [0]*3
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
# 2019-11-15 00:35:39(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, *p = [int(x) for x in sys.stdin.read().split()]

    compare = []
    for i in range(n-1):
        if p[i] < p[i+1]:
            compare.append('<')
        else:
            compare.append('>')

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

    print(count)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n-2):
    if li[i+1] < max(li[i],li[i+2]) and li[i+1] > min(li[i],li[i+2]):
        count += 1

print(count)

Submission status: Accepted

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

def is_mid(v):
  return int(min(v)<v[1] and v[1]<max(v))
res=0
for i in range(1,N-1):
  res+=is_mid(P[(i-1):(i+2)])
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

meet_condition = 0

for i in range(n-2):
    X =[]
    for j in range(3):
        X.append(p[i+j])
    if p[i+1] != max(X) and  p[i+1] != min(X):
        meet_condition += 1
        
print(meet_condition)

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+2]<p[i+1]<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(1,n-1):
  maxi = max(p[i-1],p[i],p[i+1])
  mini = min(p[i-1],p[i],p[i+1])
  if p[i] != maxi and p[i] != mini:
    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().strip())
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())
p = list(map(int,input().split()))
ans = 0
for i in range(1,n - 1):
  target = p[i]
  sort_list = [p[i - 1],p[i],p[i + 1]]
  sort_list = sorted(sort_list)
  if sort_list[-2] == target:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    l = [int(x) for x in input().split()]

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

    print(cnt)
    
# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc132","b",main)

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

Submission status: Accepted

Solution code:
def c(x,s):
    return [x[i:i+s]for i in range(len(x)-s+1)]
input()
print([sorted(i)[1]==i[1]for i in c(list(map(int,input().split())),3)].count(True))