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()))
count = 0
for i in range(n - 2):
    p_part = p[i:i+3]
    if p[i+1] != max(p_part) and p[i+1] != min(p_part):
        count += 1
print(count)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
#-------------------------------------
import collections

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

counter = 0
for i in range(1,n-1):
        tmp = [p[i-1], p[i], p[i+1]]
        tmp = collections.Counter(tmp)
        tmp = sorted(tmp)
        if len(tmp) > 1 and tmp[0] < tmp[1] and tmp[1] == p[i]:
                counter += 1
print(counter)

Submission status: Accepted

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

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

Submission status: Accepted

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

count=0
i=1
while i<n-1:
    a=p[i]-p[i+1]
    b=p[i]-p[i-1]
    if a*b<0:
        count+=1
    i+=1
print(count)

Submission status: Accepted

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

ans = 0
for i in range(1, n-1):
    if (p[i] > p[i-1]) and (p[i+1] > p[i]):
        ans += 1
    elif (p[i] < p[i-1]) and (p[i+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,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:
# -*- coding: utf-8 -*-

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

counter = 0
for i in range(1, int(n) - 1):
    numbers = [p[i-1], p[i], p[i+1]]
    if sorted(numbers)[1] == p[i]:
        counter += 1

print(counter)

Submission status: Accepted

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

Submission status: Accepted

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

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] > 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
    else:
        count += 0
print(count)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int,input().split()))
c = 0
k =0
L = n - 3
while(k <= L):
	if (p[k+1] - p[k])*(p[k+1] - p[k+2]) < 0:
		c += 1
	k +=1
print(c)

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
n = int(input())
ps = list(map(int, input().split(" ")))
res = 0
for i in range(1, n-1):
    p1 = ps[i-1]
    p2 = ps[i]
    p3 = ps[i+1]
    minimum = min(p1, p2, p3)
    maximum = max(p1, p2, p3)
    if p2 != minimum and p2 != maximum:
        res += 1
print(res)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
cnt = n-2
ans = 0
for i in range(cnt):
    a1 = li[i]
    a2 = li[i+1]
    a3 = li[i+2]
    if (a1 < a2) & (a2 < a3):
        ans += 1
    if (a3 < a2) & (a2 < a1):
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    p = [int(i) for i in input().split()]
    f = p[0]
    s = p[1]
    ans = 0
    for i in range(2, len(p)):
        if (f < s and s < p[i]) or (f > s and s > p[i]):
            ans += 1
        f = s
        s = p[i]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(n - 2):
    cnt += (p[i] < p[i + 1] < p[i + 2]) or (p[i] > p[i + 1] > p[i + 2])
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(0, N-2):
    a = p[i:i+3]
    b = p[i+1]
    a.sort()
    if a[1] == b:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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:
# -*- coding: utf-8 -*-
# abc132/abc132_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    n = i2n()
    p = i2nn()
    s = 0
    for i in range(1, n - 1):
        s += int(p[i - 1] < p[i]  < p[i + 1])
        s += int(p[i - 1] > p[i]  > p[i + 1])
    print(s)
    return

main()

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] or p[i] > p[i+1]) and not (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()))
counter=0

for i in range(1, n-1):
    if P[i-1]<P[i]<P[i+1] or P[i-1]>P[i]>P[i+1]:
        counter+=1

print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
P = list(map(int, input().split()))

count = 0
for i in range(N-2):
  if np.median(P[i:i+3])==P[i+1]:
    count+=1
print(count)

Submission status: Accepted

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

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


print(count)

Submission status: Accepted

Solution code:

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

count = 0
for index in range(1, n-1):
    tmp = p_list[index - 1:index + 2]

    max_index = tmp.index(max(tmp))
    min_index = tmp.index(min(tmp))

    if max_index != 1 and min_index != 1:
        count += 1

print(count)

Submission status: Accepted

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

def isCenter(l3):
  center = l3[1]
  l3.sort()
  return center == l3[1] and l3[0] != l3[1]

cnt = 0

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

print(cnt)

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

Submission status: Accepted

Solution code:
n = int(input())
l = [int(x) for x in input().split()]
result = 0
for n in range(1,n):
    if (l[n] < max(l[n-1:n+2])) & (l[n] > min(l[n-1:n+2])):
        result += 1
print(result)

Submission status: Accepted

Solution code:
def is_ok(a, b, c):
    if a == b and b == c:
        return False

    s = sorted([a,b,c])
    if s[0] == s[1] and s[2] == b:
        return True
    if s[1] == s[2] and (s[1] == b or s[2] == b):
        return True
    if s[1] == b:
        return True
    return False

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
#B
n = int(input())
p = list(map(int,input().split()))
cnt = 0
i = 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     = input()
num_s = input()
num   = [int(i) for i in num_s.split(" ")]

match_cnt = 0
for i in range(1,len(num)-1):
    nums = num[i-1:i+2]
    if nums[1] == sorted(nums)[1]:
        match_cnt += 1
print(match_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]  :
        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()))
count = 0
for i in range(2,n):
  if p[i-2] < p[i-1] and p[i-1] < p[i]:
    count += 1
  elif  p[i-2] > p[i-1] and p[i-1] > p[i]:
    count += 1
print(count)

Submission status: Accepted

Solution code:
import fractions
from collections import deque
import numbers as np


def main():
    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__":
    main()

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

cnt = 0

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

        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

p = [int(x) for x in input().split()]

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

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int,input().split()))
p2 = p[0]
p1 = p[1]
pm2 = 1 if p1>p2 else -1
count = 0
for i in range(2,n):
  p2 = p[i-2]
  p1 = p[i-1]
  pm2 = (p2-p1)//abs(p2-p1)
  pm1 = (p1-p[i])//abs(p1-p[i])
  if pm1 == pm2:
    count += 1
print(count)

Submission status: Accepted

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

def max2(S):
    if S[0] < S[1] and S[1] < S[2]:
        return True
    elif S[0] > S[1] and S[1] > S[2]:
        return True
    else:
        return False


cnt = 0

for i in range(1, n - 1):
    sub = p[i - 1 : i + 2]
    if max2(sub):
       cnt += 1
       
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
logging.disable(logging.CRITICAL)

N = int(input())
L = list(int(x) for x in input().split())

counter = 0

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

print(counter)

Submission status: Accepted

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

res = 0
for i in range(n-2):
    tmp_list = [p[i], p[i+1], p[i+2]]
    tmp_list_sorted = sorted(tmp_list)

    if tmp_list_sorted[1] == tmp_list[1]:
        res += 1

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
s = input().split()
p = []
for i in range(N):
    p.append(int(s[i]))
count = 0
for i in range(2,N):
    if p[i] > p[i-1] and p[i-1] > p[i-2]:
        count = count+1
    if p[i] < p[i-1] and p[i-1]< p[i-2]:
        count = 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:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    l = list(map(int, sys.stdin.readline().split()))

    cnt = 0
    for i in range(N - 2):
        p1 = l[i]
        p2 = l[i + 1]
        p3 = l[i + 2]

        if p2 != max(p1,p2,p3) and p2 != min(p1,p2,p3) :
            cnt += 1
    print(cnt)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

cnt = 0
for i in range(len(ps) - 2):
    if ps[i] < ps[i+1] <= ps[i+2] or ps[i] >= ps[i+1] > ps[i+2]:
        cnt += 1

print(cnt)

Submission status: Accepted

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

counter = 0

for i in range(1,N-1):
#    print(i)
    p1 = P[i-1]
    p2 = P[i]
    p3 = P[i+1]

    if p1 < p2 and p2 < p3:
        counter += 1
    elif p3 < p2 and p2 < p1:
        counter += 1
    
print(counter)

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

Submission status: Accepted

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

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

nc=0
for i in range(1,n-1):
    p1=P[i-1]
    p2=P[i]
    p3=P[i+1]
    if p1>p2>=p3 or p1<=p2<p3:
        nc+=1
print(nc)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import statistics

n = int(input())
p_ls = [int(i) for i in input().split()] 
c = 0
for i in range(n-2):
    ls = p_ls[i:i+3]
    med = statistics.median(ls)
    if ls[1] == med:
        c += 1
        
print(c)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    p = input().split()
    frag = 0
    for i in range(1, len(p)-1):
        a = []
        a.append(int(p[i-1]))
        a.append(int(p[i]))
        a.append(int(p[i+1]))
        if max(a) == a[1]:
            continue
        elif min(a) == a[1]:
            continue
        else:
            frag += 1
    print(frag)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#b.py
n = int(input())
lis = list(map(int,input().split()))
ans = 0
for x,y,z in zip(lis,lis[1:],lis[2:]):
    if x < y < z or z < y < x:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n1 = int(input())

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

r4 = 0
for i3 in range(n1):
    if i3 == 0:
        if n2[0] > n2[1]:
            continue


    elif i3 == n1 - 1:
        if n2[n1 - 1] > n2[n1 - 2]:
            continue
    
    else:
        if (n2[i3 - 1] > n2[i3] and n2[i3] > n2[i3 + 1]) or (n2[i3 + 1] > n2[i3] and n2[i3] > n2[i3 - 1]):
            r4 += 1
print(r4)

Submission status: Accepted

Solution code:
import heapq

n=int(input())
pX = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
    h = []
    heapq.heappush(h,pX[i])
    heapq.heappush(h,pX[i+1])
    heapq.heappush(h,pX[i+2])
    heapq.heappop(h)
    tgt = heapq.heappop(h)
    if tgt == pX[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):
    ppp = [P[i-1], P[i], P[i+1]]
    ppp.sort()
    if ppp[1] == P[i] and ppp[1] != ppp[0]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:

N=int(input())
permu=list(map(lambda x:int(x),input().split()))
counter=0

for i in range(1,N-1):
    p=[]
    p.append(permu[i-1])
    p.append(permu[i])
    p.append(permu[i+1])
    p=sorted(p)
    if p[1]==permu[i]:
        counter+=1

print(counter)

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    pl = list(map(int, input().split()))

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

    print(count)

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    N = int(input())
    P = list(map(int, input().split()))

    ans = 0
    for i in range(1, N - 1):
        ans += all((min(P[i-1], P[i], P[i+1]) < P[i],
                    max(P[i-1], P[i], P[i+1]) > P[i]))
    print(ans)

input = lambda: stdin.readline()
main()

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

print(counter)

Submission status: Accepted

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(1000000)
 
n = int(input())
p = list(map(int,input().split()))


ans = 0

for i in range(n-2):
    if p[i] < p[i+1] and p[i+2] > p[i+1]:
        ans += 1
    elif p[i] > p[i+1] and p[i+2] < 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(n-2):
  a = p[i]
  b = p[i+1]
  c = p[i+2]
  if b > a and b < c:
    count+=1
  elif b > c and b < a:
    count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
for i in range(N - 2):
    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]):
        res += 1
print(res)

Submission status: Accepted

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

cnt = 0
for i in range(n-2):
    i += 1
    L = [P[i-1], P[i], P[i+1]]
    L = sorted(L)
    if L[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(1,n-1):
  if p[i]>p[i-1] and p[i]>p[i+1]:
      continue
  elif p[i]<p[i-1] and p[i]<p[i+1]:
      continue
  else:
      cnt +=1
print(cnt)

Submission status: Accepted

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

c = 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]:
        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):
  p_ = sorted(p[i:i+3])
  p_i = p[i+1]
  if p_[1] == p_i:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import collections

def main():
	#A, B, Q = map(int, input().split(" "))
	n = int(input())
	p = list(input().split(" "))
	
	ans = 0
	for i, val in enumerate(p):
		if i == 0:
			continue
		if i+1 > n-1:
			continue
		fst = int(p[i-1])
		snd = int(p[i])
		srd = int(p[i+1])
		if snd != max(fst,snd,srd) and snd != min(fst,snd,srd):
			ans += 1
	
	
	print(ans)	
	
	
if __name__ == "__main__":
	main()

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

print(cnt)

Submission status: Accepted

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

# 前後の数値と比較して、真ん中が２番目（＝中位）ならカウントアップ
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:
n = int(input())
p = list(map(int, input().split(' ')))

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

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

counter = 0

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

  else:
    if p[i+1] >= p[i]:
      counter += 1

print(counter)

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0

for i in range(1, N - 1) :
    #print(p[i], max(p[i-1:i+2]), min(p[i-1:i+2]))
    if p[i] != max(p[i-1:i+2]) and p[i] != min(p[i-1: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(n-2):
    p1, p2, p3 = p[i], p[i+1], p[i+2]
    aaa = [p1,p2,p3]
    aaa.sort()
    if aaa[1] == p2:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

left = [False] * n
right = [False] * n

for i in range(1, n):
    if p[i-1] < p[i]:
        left[i] = True

for i in range(n-1, 1, -1):
    if p[i] < p[i-1]:
        right[i-1] = True

count = 0
for i in range(1,n-1):
    if not(left[i] and right[i]):
        if left[i] or right[i]:
            count += 1

print(count)

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
num = int(input())
numbers = str(input())

numbers = numbers.split(' ')
numbers = [int(n) for n in numbers]

cnt = 0
for i in range(1, num - 1):
    li = sorted([numbers[i - 1], numbers[i], numbers[i + 1]])
    if 1 == li.index(numbers[i]):
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

n = int(input())
li = list(map(int,input().split()))
cntr = 0

for i in range(n - 2):
    li_tmp = li[i : (i + 3)]
    if li_tmp[1] != max(li_tmp) and li_tmp[1] != min(li_tmp):
        cntr += 1
print(cntr)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

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

Submission status: Accepted

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

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