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

Submission status: Accepted

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

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())
a = list(map(int,input().split()))
ans = 0
s = 1
while s < n-1:
  if a[s-1] < a[s] < a[s+1] or a[s-1] > a[s] > a[s+1]:
    ans += 1  
  s += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

count=0
for i in range(1,N-1):
  if S[i-1]<S[i]<S[i+1] or S[i-1]>S[i]>S[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] > 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())
P = [int(p) for p in 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)

Submission status: Accepted

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

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
for i in range(n-2):
    T = P[i:i + 3]
    if T == sorted(T) or T == sorted(T,reverse=True):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
# B - Ordinary Number

n = int(input())
p = list(int(x) for x in 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()))
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=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
     
  if(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()))
cnt=0

for i in range(1, n-1):
    if p[i-1] <= p[i] and p[i+1] >= p[i]:
        cnt+=1
    elif p[i-1] >= p[i] and p[i+1] <= p[i]:
        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 pList[i-1] < pList[i] < pList[i+1] or pList[i-1] > pList[i] > pList[i+1]:
        ans += 1

print(ans)

Submission status: Accepted

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

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

print(cnt)

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

for i in range(n-2):
    PP = P[i:i+3]
    if PP[1] == sorted(PP)[1]:
        ans += 1
        
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def ll():
    return list(map(int,input().split()))
def l():
    return int(input())
n = l()
s = ll()
count=0
for i in range(len(s)-2):
    b = [s[i],s[i+1],s[i+2]]
    c = sorted(b)
    if b[1]==c[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(0,n-2):
    #print(i)
    p_list=[p[i],p[i+1],p[i+2]]
    #print(p_list)
    p_sorted=sorted(p_list)
    #print(p_sorted)
    if p_list[1]==p_sorted[1]:
        count+=1

print(count)

Submission status: Accepted

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

for i in range(0,len(A)-2):
    B=[A[i],A[i+1],A[i+2]]
    C=sorted(B)
    if B[1]==C[1]:
        count+=1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

cnt=0

for i in range(1,n-1):
  f=p[i-1]
  s=p[i]
  t=p[i+1]

  if f<s and s<t:
    cnt+=1
  elif t<s and s<f:
    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 - 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:
#B
n = int(input())
p = list(map(int,input().split()))

def middle(a,b,c,cnt):
    lst =[a,b,c]
    lst.sort()
    if lst[1] == b:
        cnt += 1
        
    return cnt
cnt = 0
for i in range(n-2):
    cnt = middle(p[i],p[i+1],p[i+2],cnt)
    
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 = [int(i) for i in 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()))
num = 0

for i in range(n-2):
    a,b,c = p[i],p[i+1],p[i+2]
    if a <= b<=c or a >= b >= c:
        num += 1
print(num)

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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())
li=list(map(int,input().split()))
a=0
for i in range(n-2):
  ln=[li[i],li[i+1],li[i+2]]
  ln.sort()
  if ln.index(li[i+1])==1:
    a+=1
print(a)

Submission status: Accepted

Solution code:
n = int(input())
p = tuple(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):
    dammy = sorted([p[i],p[i+1],p[i+2]])
    if dammy[1] == p[i+1]:
        count += 1
print(count)

Submission status: Accepted

Solution code:
# ABC 132: B – Ordinary Number
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:
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):
    p=P[i-1:i+2]
    p_s=sorted(p)
    if p[1]==p_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(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]:
        count+=1

print(count)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


N = int(input())
P = list(map(int, input().split()))
counter = 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]):
        counter += 1

print(counter)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()

N, A, B = map(int, input().split())

A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""
N = int(input())
P = list(map(int, input().split()))
counter = 0
for i in range(1, len(P) - 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]):
        counter += 1

print(counter)



# def main():

# if __name__ == '__main__':
#     main()

Submission status: Accepted

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

count = 0
for a in range(1, n-1):
    if p[a-1] > p[a] and p[a+1] < p[a]:
        #print(p[a-1], p[a], p[a+1])
        count += 1
    if p[a-1] < p[a] and p[a+1] > p[a]:
        #print(p[a-1], p[a], p[a+1])
        count += 1

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    b = list(set(s))
    a = len(list(set(s)))
    if a == 2 and s.count(b[0]) == s.count(b[1]) == 2:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    p = LI()
    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)
    return

#C
def C():
    n = II()
    d = LI()
    d.sort()
    ans = 0
    for i in range(10**5+1):
        if n // 2 == bisect_left(d, i):
            ans += 1
    print(ans)
    return


def combination_mod(n, k, mod):
    # power_funcを用いて(nCk) mod p を求める 
    # nCk = n!/((n-k)!k!)を使用

    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = factorial(n) % mod
    b = factorial(k) % mod
    c = factorial(n - k) % mod
    return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod
    
def power_func(a, b, mod):
    # a^b mod p を求める
    # bを2進数分解して高速累乗

    if b == 0: return 1
    if b % 2 == 0:
        d = power_func(a, b // 2, mod)
        return d * d % mod
    if b % 2 == 1:
        return (a * power_func(a, b - 1, mod)) % mod

#D
def D():
    n, k = LI()
    ans = 0
    for i in range(1,k+1):
        a = combination_mod(n - k + 1, i, mod)
        b = combination_mod(k - 1, i - 1, mod)
        print((a*b)%mod)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
p = LIST()
cnt = 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]):
		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 - 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()))

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-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:
icase=0
if icase==0:
    n=int(input())
    p=list(map(int,input().split()))
    icnt=0
    pi=[0]*3
    for i in range(1,n-1):
        pi=[p[i+1],p[i],p[i-1]]
        if p[i]==sum(pi)-min(pi)-max(pi):
            icnt+=1
    print(icnt)

Submission status: Accepted

Solution code:
import sys
n = int(input())
p = list(map(int, sys.stdin.readline().rstrip().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(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()))
count = 0

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

print(count)

Submission status: Accepted

Solution code:
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(readline())
  P = list(map(int, readline().split()))
  ans = 0
  for i in range(N-2):
    p1 = P[i]
    p2 = P[i+1]
    p3 = P[i+2]
    if (p1<p2<p3) or (p1>p2>p3):
      ans += 1
  
  print(ans)
  
  
  
  
      
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    p = [int(a) for a in input().split()]
    count = 0
    for i in range(1, len(p) - 1):
        p_ = p[i - 1 : i + 2]
        p_.sort()
        if p[i] == p_[1]:
            count += 1
    print(count)
main()

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(n-2):
  if min(l[i],min(l[i+1],l[i+2])) != l[i+1] and max(l[i],max(l[i+1],l[i+2])) != l[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] != 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:
# coding: utf-8
# Your code here!

def MI():return map(int,input().split())
def LI():return list(MI())

n,*p=map(int,open(0).read().split())

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

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0
for i in range(n-2):
    if pl[i] < pl[i+1] < pl[i+2] or pl[i] > pl[i+1] > pl[i+2]:
        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):
    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()]
count = 0
for i in range(1,n-1):
    mn = min(p[i-1],p[i],p[i+1])
    mx = max(p[i-1],p[i],p[i+1])
    if mn!=p[i] and  mx != 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]) 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()))
count = 0
for i in range(len(p)-1):
    if i == 0:
        continue
    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, n - 1):
    now = P[i]
    tmp = [P[i - 1], P[i], P[i + 1]]
    tmp.sort()
    if now == tmp[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 + 2] <= p[i + 1] < p[i]:
        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 sorted([p[i-1],p[i],p[i+1]])[1]==p[i]:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
  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)
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    P = [int(p) for p 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)

    return 0

if __name__ == "__main__":
    solve()

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 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):
    k = p[i-1:i+2]
    l = k.copy()
    l.sort()
    if l[1] == k[1]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
def solve():
    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)
if __name__=='__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    p = LI()
    a = [0]*(n+1)
    a[p[0]] += 1
    a[p[1]] += 1
    a[p[2]] += 1
    ans = 0
    if sum(a[:p[1]]) == 1:
        ans += 1
    for i in range(2,n-1):
        a[p[i-2]] -= 1
        a[p[i+1]] += 1
        if sum(a[:p[i]]) == 1:
            ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

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()))
ans = 0
for a,b,c in zip(P,P[1:],P[2:]):
    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(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())
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:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
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())

n = inp()
p = inpl()
cnt = 0
for i in range(1, n+1):
    if i <= n-2:
        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()))
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(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()))
count = 0
for i in range(1,n-1):
    p_1 = p[i-1]
    p_2 = p[i]
    p_3 = p[i+1]
    if p_1 < p_2 < p_3 or p_1 > p_2 > p_3:
        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)):
    
    if P[i]!=max(P[i-1:i+2]) and P[i]!=min(P[i-1:i+2]):
        count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int,input().split()))
ans = 0
for i in range(n-2):
    a,b,c = s[i:i+3]
    if a<b<c or c<b<a:  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:i + 2]) and p[i] != max(p[i - 1:i + 2]):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
nums = [int(i) for i in input().split()] # 配列で数字

ans = 0
for i in range(1, n - 1):
    a = nums[i - 1]
    b = nums[i]
    c = nums[i + 1]
    p = [a, b, c]
    p.sort()
    if p[1] == b:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int,input().split()))
seconds = []
for a in range(0,n-2):
    num = [p[a],p[a+1],p[a+2]]
    if (num[0]<num[1]<num[2])or(num[2]<num[1]<num[0]):
        seconds.append(p[a+1])
    else : pass

print(len(set(seconds)))