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()))
cnt = 0
for i in range(n-2):
  q = p[i:i+3]
  if min(q) == q[1] or max(q)==q[1]:
    pass
  else:
    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, len(p)-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())
l = list(map(int, input().split()))
c = 0
for i in range(1, n - 1):
    if (not (min(l[i - 1], l[i], l[i+1]) == l[i])) and (not (max(l[i - 1], l[i], l[i+1]) == l[i])):
        c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#input : 整数の数 n と１から n までを並び替えた整数 p_1 から p_n まで
#output : ３つの並びを取り出したとき真ん中の数が二番目に小さい並びの個数

n = int(input())
P = list(map(int,input().split()))
N = 0

for i in range(n-2):
    s = []
    s.append(P[i])
    s.append(P[i+1])
    s.append(P[i+2])
    if s[1] != max(s) and s[1] != min(s):
        N += 1

print(N)

Submission status: Accepted

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

count=0
for i in range(1,n-1):
  if numbers[i-1]>numbers[i]>numbers[i+1] or numbers[i-1]<numbers[i]<numbers[i+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(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())
listP=list(map(int,input().split()))
counter =0
for i in range(1,n-1):
	if min(listP[i-1],listP[i],listP[i+1])==listP[i] or max(listP[i-1],listP[i],listP[i+1])==listP[i]:
		counter +=0
	else:
		counter +=1
print(counter)

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

Submission status: Accepted

Solution code:
import copy
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(1, n - 1):
    tre_p = [p[i - 1], p[i], p[i + 1]]
    tre_p_copyed = copy.copy(tre_p)
    tre_p.remove(min(tre_p))
    if tre_p_copyed[1] == min(tre_p):
        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):
    s=[p[i-1],p[i],p[i+1]]
    s.remove(min(s))
    s.remove(max(s))
    if s[0]==p[i]:
        count+=1
print(count)

Submission status: Accepted

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

#それぞれの3要素の比較において, 昇順または降順にソートしても変化が無ければ真ん中の要素が2番>目に大きいことになる
for i in range(1,n-1):
    p_3list = [p[i-1],p[i],p[i+1]]

    if p_3list == sorted(p_3list):
        count += 1
    elif p_3list == sorted(p_3list,reverse=True):
        count += 1

print(count)

Submission status: Accepted

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

count = 0
for i in range(1,n - 1):
    if lis_p[i - 1] < lis_p[i] < lis_p[i + 1] or lis_p[i - 1] > lis_p[i] > lis_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(1, len(p)-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 p_b():
    N = int(input())
    p = list(map(int, input().split()))
    ans = 0
    for i in range(N - 2):
        if max(p[i:i + 3]) != p[i + 1] and min(p[i:i + 3]) != p[i + 1]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    p_b()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(n: int, p: "List[int]"):
    result = 0
    for i in range(len(p) - 2):
        if p[i] < p[i + 1] and p[i + 1] < p[i + 2]:
            result += 1
        elif p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
            result += 1
    print(result)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, p)

if __name__ == '__main__':
    main()

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

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

co = 0

for i in range(1,len(li)-1):
  work = sorted([li[i-1],li[i],li[i+1]])

  if work.index(li[i]) == 1:
    co += 1
print(co)

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

cnt = 0
i = 1
while i < 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
    i += 1

print(cnt)

Submission status: Accepted

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

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

l = [int(i) for i in input().split()]
count = 0
for i in range(n - 2):
    tmp = []
    for j in range(i, i + 3):
        tmp.append(l[j])
    if tmp[1] == max(tmp) or tmp[1] == min(tmp):
        pass
    else:
        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):
  K=[p[i-1], p[i], p[i+1]]
  K.sort()
  if K[1]==p[i]:
    counter=counter+1
print(counter)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n, *p = map(int, open(0).read().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):
         pp = (p[i-1],p[i],p[i+1])
         pp = sorted(pp)
         if pp[1] == p[i]:
                  ans+= 1
print(ans)

Submission status: Accepted

Solution code:
input()
p=[int(x) for x in input().split()]
q=[x-y for x,y in zip(p[1:],p[:])]
r=[1 for x,y in zip(q[1:],q[:]) if x*y>0]
print(len(r))

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(n: int, p: "List[int]"):

    count = 0
    for i in range(n - 2):
        partial = p[i : i + 2 + 1]
        if partial[0] < partial[1] and partial[1] < partial[2]:
            count += 1
        elif partial[0] > partial[1] and partial[1] > partial[2]:
            count += 1
        else:
            pass

    print(count)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, p)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(n: int, p: "List[int]"):

    count = 0
    for i in range(n - 2):
        partial = p[i : i + 2 + 1]
        if min(partial) != partial[1] and max(partial) != partial[1]:
            count += 1
        else:
            pass

    print(count)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, p)


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

Submission status: Accepted

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

for i in range(len(a)-2):
  if a[i] < a[i+1] and a[i+1] < a[i+2]:
      count += 1
  if a[i] > a[i+1] and a[i+1] > a[i+2]:
    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(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()))
cnt = 0
for i in range(n-2):
    flag1 = p[i] < p[i+1] and p[i+1] < p[i+2]
    flag2 = p[i+2] < p[i+1] and p[i+1] < p[i]
    if flag1 or flag2:
        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]) and (p[i+1] < p[i+2]):
    count += 1
  elif (p[i] > p[i+1]) and (p[i+1] > p[i+2]):
    count += 1
    
print(count)

Submission status: Accepted

Solution code:
n = int(input())
p = [int(a) for a in 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())
A = list(map(int, input().split()))

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

Submission status: Accepted

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

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

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

print(count)

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

point = 0
for i in range(1,n-1):
    lin = li[i-1:i+2]
    lin2 = sorted(lin)
    if lin[1] == lin2[1]:
       point += 1
print(point)

Submission status: Accepted

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

ans = 0

for i in range(N-2):
  if N_l[i] < N_l[i+1] and N_l[i+1] < N_l[i+2]:
    ans += 1
  elif N_l[i+2] < N_l[i+1] and N_l[i+1] < N_l[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()))
s=0
for i in range(1,n-1):
    if p[i-1]<=p[i]<=p[i+1]:
        s+=1
    elif p[i+1]<=p[i]<=p[i-1]:
        s+=1
    else:
        s+=0
print(s)

Submission status: Accepted

Solution code:
n = int(input());p = [int(_) for _ in 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
    else:
        continue
print(cnt)

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

print(count)

Submission status: Accepted

Solution code:
from sys import stdin

input = stdin.readline

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

count = 0

for i in range(len(p)-2):
    if p[i+1] == sorted([p[i],p[i+1],p[i+2]])[1]:
        count += 1

print(count)

Submission status: Accepted

Solution code:
import statistics

n = int(input())

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

count = 0

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

print(count)

Submission status: Accepted

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

num=0
for i in range(1,len(p)-1):
  if p[i-1]<p[i]<p[i+1]:
    num+=1
  elif p[i-1]>p[i]>p[i+1]:
    num+=1
  else:
    pass
  
print(num)

Submission status: Accepted

Solution code:
n = int(input())

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

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

print(count)

Submission status: Accepted

Solution code:
# ABC132b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

counter = 0

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

print(counter)

Submission status: Accepted

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

for i in range(n):
    if i == 0:
        count = 0
    elif i < n-1:
        if pl[i-1]<pl[i]<pl[i+1]:
            count = count + 1
        elif pl[i-1]>pl[i]>pl[i+1]:
            count = count + 1
            
print(count)

Submission status: Accepted

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

ctn = 0
for i in range(0,len(x)):
    if i+2 <= len(x)-1:
        if min(x[i:i+3:2]) <= x[i+1] and x[i+1] <= max(x[i:i+3:2]):
            ctn +=1
print(ctn)

Submission status: Accepted

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

for i in range(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]):
        cnt+=1

print(cnt)

Submission status: Accepted

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

res = 0
for a,b,c in zip(p[:n-1], p[1:n], p[2:]):
    if a > b > c or c > b > a:
        res += 1
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#132b
N = int(input())
p_list = list(map(int, input().split()))

#pi−1, pi, pi+1の 3 つの数の中で、pi が 2 番目に小さい。
#pi (1<i<n) がいくつあるかを出力してください。
ans = 0

for i in range(1,N-1):
    #print(p_list[i-1],p_list[i],p_list[i+1])
    if (p_list[i-1] < p_list[i] and p_list[i] < p_list[i+1]) or (p_list[i-1] > p_list[i] and p_list[i] > p_list[i+1]):
        ans+=1

print(ans)

Submission status: Accepted

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

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

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


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

Submission status: Accepted

Solution code:
n = int(input())

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

score = 0
for i in range(1, n-1):
    list_p[i]

    if list_p[i] < list_p[i+1] and list_p[i] > list_p[i-1]:
        score += 1

    if list_p[i] > list_p[i+1] and list_p[i] < list_p[i-1]:
        score += 1

print(score)

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
L=list(map(int,input().split()))
ans=0
for i in range(N-2):
    l=sorted(L[i:i+3])
    if l[1] == L[i+1]:
        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] and a[i+1] > a[i+2]:
    ans += 1
  if a[i] < a[i+1] and a[i+1] < a[i+2]:
    ans += 1

print(ans)

Submission status: Accepted

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

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]:
    cnt += 1
  elif P[i]>P[i+1] and P[i]<P[i-1]:
    cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(1,n-1):
    tmp = []
    tmp.append(p[i-1])
    tmp.append(p[i])
    tmp.append(p[i+1])
    tmp.sort()
    
    if tmp[1] == p[i]:
        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,n-1):
    if p[i-1]<p[i]<p[i+1] or p[i+1]<p[i]<p[i-1]:
        res += 1

print(res)

Submission status: Accepted

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

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


counter = 0
for val in range(n-2):
    _tmp = p_L[val:val+3]
    a = _tmp[1]
    b = sorted(_tmp)[1]
    if a==b:
        counter += 1
print(counter)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
P = [int(_) for _ in stdin.readline().rstrip().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

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

Submission status: Accepted

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

flag=0

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

print(flag)

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int,input().split()))
ans = 0
for i in range(len(lst)-2):
    a,b,c=lst[i:i+3]
    if a<b<c or c<b<a:ans+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
import sys
from _operator import itemgetter
from collections import Counter
from math import log2, pi, ceil

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
p = na()
ct = 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]:
        ct += 1
print(ct)

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

Submission status: Accepted

Solution code:
N=int(input())

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

count=0
for i in range(N):
    p=m[i:i+3]
    if len(p) == 3:
        if max(p) > p[1] and min(p) < p[1]:
            count +=1
            
            
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as  np


n = int(input())
p = np.array(input().split(), np.int32)

res =  0

for i in range(1, n-1):
    p_part = p[i-1:i+2]
    p_sorted = np.sort(p_part)
    if  p_part[1] == p_sorted[1]:
        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] != min(P[i-1:i+2]) and P[i] != max(P[i-1: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] > p[i - 1] and p[i] < p[i + 1]) or (p[i] < p[i - 1] and 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(1, len(p) - 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]>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:
# -*- coding:utf8 -*-
import math

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0 

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main(): 

    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)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
pi = list(map(int, input().split()))
count =0
for i in range(len(pi)-2):
    if((pi[i+1]>pi[i] and pi[i+1]<pi[i+2]) or(pi[i+1]<pi[i] and pi[i+1]>pi[i+2])):
        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):
    temp = [p[i-1], p[i], p[i+1]]
    temp.sort()
    if p[i] == temp[1]:
        cnt += 1

print(cnt)

Submission status: Accepted

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

print(c)