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

Submission status: Accepted

Solution code:
import sys


def main():
    input = sys.stdin.buffer.readline
    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]:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 0
for i in range(1, n - 1):
    is_asc = p[i - 1] < p[i] < p[i + 1]
    is_desc = p[i - 1] > p[i] > p[i + 1]
    if is_asc or is_desc:
        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):
    if(i == 0):
        pass
    elif (i == n - 1):
        pass
    else:
        a = p[i - 1]
        b = p[i]
        c = p[i + 1]
        lst = [a, b ,c]
        lst.sort()
        if (lst[1] == b):
            ans = ans + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
P=str(input())

def ans132(n:int, P:str):
    P=list(map(int,P.split()))
    jugde_count=0
    for i in range(1,n-1):
        n_list=sorted([P[i-1],P[i],P[i+1]])
        if n_list[1]==P[i]:
            jugde_count+=1
    return jugde_count

print(ans132(n,P))

Submission status: Accepted

Solution code:
a = input()
n = int(a)
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 = 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):
  p1, p2, p3 = p[i-1], p[i], p[i+1]
  if p1 < p2 < p3 or p3 < p2 < p1:
    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] < 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())
plist = list(map(int, input().split()))

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

print(cnt)

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())
L = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
  s = L[i:i+3][1]
  A = sorted(L[i:i+3])
  t = A[1]
  if s == t:
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

pn = list(map(int,input().split()))
count = 0
for x in range(1,n-1):
  if pn[x+1] > pn[x] > pn[x-1] or pn[x-1] > pn[x] > pn[x+1]:
    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):
  s = [p[i-1], p[i], p[i+1]]
  if p[i] != min(s) and p[i] != max(s):
    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] > 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(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(1, n-1):
  M = max(p[i-1], p[i], p[i+1])
  m = min(p[i-1], p[i], p[i+1])
  if p[i] != M and p[i] != m: ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
for i in range(1,n-1):
    second = p[i]
    scope = sorted([ p[i-1], p[i], p[i+1] ])
    if scope[0] < second and second < scope[2]:
        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input());
arr = list(map(int, input().split()));
count = 0;
for i, num in enumerate(arr):
  if(i == 0 or i == (n - 1)): 
    continue;
  
  target_arr = [arr[i-1], arr[i], arr[i+1]]
  if(sorted(target_arr)[1] == arr[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 sorted([P[i-1],P[i],P[i+1]]).index(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] != min(p[i-1], p[i], p[i+1]) 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(2, n):
  if P[i-2] < P[i-1] < P[i] 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()))
a = 0
for i in range(len(p) - 2):
    if p[i] < p[i + 1] < p[i + 2] or p[i + 2] < p[i + 1] < p[i]:
        a += 1
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int,input().split()))
i = 0
ans = 0
while i < len(p) - 3 + 1:
    m = p[i:i+3]
    l = sorted(m)
    if l[1] == m[1]:
        ans += 1
    i += 1
print(ans)

Submission status: Accepted

Solution code:
import statistics

n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n-2):

    l2=[l[i],l[i+1],l[i+2]]
    if statistics.median(l2)==l[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(0,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:
a = int(input())
b = list(map(int,input().split()))
c = 0
for i in range(1,a-1):
  if b[i-1]<b[i] and b[i]<b[i+1]:
    c += 1
  elif b[i-1]>b[i] and b[i]>b[i+1]:
    c += 1
print(c)

Submission status: Accepted

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

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

Submission status: Accepted

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

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):
    a=p[i-1]
    b=p[i]
    c=p[i+1]
    p_list=[a,b,c]
    #print(p_list)
    p_list.sort()
    
    if p[i]==p_list[1]:
        count+=1
        #print(p_list)
        
print(count)

Submission status: Accepted

Solution code:
#ネットのやつ　自分で考える
#from math import ceil
#n, h = map(int, input().split( ))
n = int(input())
A = list(map(int, input().split( )))
ans = 0
for i in range(n-2):
  if min(A[i], A[i+2]) <= A[i+1] and A[i+1] <= max(A[i], A[i+2]):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
d=[int(s) for s in input().split()]
ans=0
for i in range(N-2):
    if d[i]<d[i+1]<d[i+2] or d[i+2]<d[i+1]<d[i]:
        ans+=1
print(ans)

Submission status: Accepted

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


print(ct)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

for i in range(n-2):
    P = p[i:i+3]
    if P[0] < P[1] < P[2]:
        cnt += 1
    elif P[2] < P[1] < P[0]:
        cnt += 1
        
print(cnt)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# Ordinary Number
n = int(input())
p = list(map(int, input().split()))
ct= 0
C = []
for i in range(1,n-1):
    C.append(p[i])
    C.append(p[i-1])
    C.append(p[i+1])
    C.sort()
    if C[1] == p[i]:
        ct +=1
        C = []
    else:
        C = []
print(ct)

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,*p=map(int,open(0).read().split())
c=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]:
        c+=1
print(c)

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:
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n = int(input())
    a = Input()
    count = 0
    for i in range(1, n-1):
        if a[i] == sorted((a[i-1], a[i], a[i+1]))[1]:
            count += 1

    print(count)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

def main():
    lines = input()
    n = int(lines[0].strip())
    a = list(map(int, lines[1].split()))

    cnt = 0

    for i in range(2, n):
        b = a[i-2:i+1]
        b = sorted(b)
        if a[i-1] == b[1]:
            cnt += 1

    print(cnt)

main()

Submission status: Accepted

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

Submission status: Accepted

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

count = 0

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

Submission status: Accepted

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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:
# AtCoder Beginner Contest 132
# B - Ordinary Number

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

ans=0

for i in range (n-2):
    a=pls[i]
    b=pls[i+1]
    c=pls[i+2]
    if a<b<c or c<b<a:
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
A=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(A-2):
   tmp=l[i:i+3]
   tmp.sort()
   if tmp[1] == l[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(1, N-1):
  if (P[i-1] - P[i]) * (P[i + 1] - P[i]) < 0:
    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 min(p[i],p[i+1],p[i+2]) != p[i+1]:
        if max(p[i],p[i+1],p[i+2]) != p[i+1]:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def f(a,b,c):
    mx = max(a,b,c)
    mn = min(a,b,c)
    if mx == b or mn == b:
        return False
    else:
        return True

n = int(input())
p = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
    if f(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()))

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

Submission status: Accepted

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

tmp_list = []
cnt = 0
for i in range(0, n-2, 1):
    tmp = num_list[i:i+3]
    if tmp[0] < tmp[1] and tmp[1] < tmp[2]:
        cnt += 1
    elif tmp[2] < tmp[1] and tmp[1] < tmp[0]:
        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] > p[i+1] > p[i+2]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))
def check(a, b, c):
  l = [a, b, c]
  l.sort()
  if l[1] == b:
    return True
  else:
    return False
cnt = 0
for i in range(n-2):
  if check(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()))
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:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline())
P = list(map(int, sys.stdin.readline().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):
    a = p[i:i+3]
    x = a[1]
    a.sort()
    if a[1] == x:
        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(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())

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

ans = 0

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ps = list(mapint())
ans = 0

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

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
pl = list(map(int, input().split()))
ans = 0
for p1,p2,p3 in zip(pl[:-2],pl[1:-1],pl[2:]):
    if p1 < p2 and p2 < p3 or p1 > p2 and p2 > p3:
        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):
    a = P[i-1:i+2]
    a.sort()
    if P[i]==a[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(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]):
    cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc126/tasks/abc132_b

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

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

print(res)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
count=0
i=1
while i<len(a)-1:
    if (a[i]>a[i+1] and a[i]<a[i-1]) or (a[i]<a[i+1] and a[i]>a[i-1]):
        count+=1
    i+=1
print(count)

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

cnt = 0

for i in range(n-2):
  pl = [p[j] for j in range(i, i+3)]
  if pl[0] < pl[1] <pl[2] or pl[2] < pl[1] < pl[0]:
    cnt += 1
  
print(cnt)

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

Submission status: Accepted

Solution code:
# Written by Shagoto

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

    print(count)

if __name__ == '__main__':
    main()

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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