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:
# -*- coding: utf-8 -*-
n = int(input())
p = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
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]) or (p[i-1]>p[i] and p[i]>p[i+1]):
        count += 1
    else:
        continue
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    n = int(input())
    ps = list(map(int, input().split()))
    ans = 0
    for i in range(2,n):
        arr = ps[i-2:i+1]
        arr2 = sorted(arr)
        if arr[1] == arr2[1]: ans += 1

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import math

n = int(stdin.readline().rstrip())
p_lst = [int(x) for x in stdin.readline().rstrip().split()]
count = 0

for i in range(1, n-1):
  ma = max(p_lst[i-1], p_lst[i], p_lst[i+1])
  mi = min(p_lst[i-1], p_lst[i], p_lst[i+1])
  if p_lst[i] != ma and p_lst[i] != mi:
    count += 1
    
print(count)

Submission status: Accepted

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

count = 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] ):
    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()))
count=0
for i in range(1, n-1):
    sort_p = sorted(p[i-1:i+2])
    if sort_p[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())
a = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
    if a[i] < a[i+1] < a[i+2] or a[i+2] < a[i+1] < a[i]:
        cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = input().split()
c = 0
for i in range(n):
  if i == 0 or i == n-1:
    continue
  elif (int(x[i]) < int(x[i-1]) and int(x[i]) > int(x[i+1])) or (int(x[i]) < int(x[i+1]) and int(x[i]) > int(x[i-1])):
      c = c + 1
print(c)

Submission status: Accepted

Solution code:
n = int(input())
p = [int(i) for i in input().split()]
s = 0
for i in range(1,n-1):
  l1 = p[i-1:i+2]
  l2 = l1.copy()
  l2.sort()
  if l1[1] == l2[1]:
    s += 1
print(s)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
while True:
    try:
        n = int(input())
        P = list(map(int, input().split()))
        cnt = 0
        for i in range(1, n-1):
            if min(P[i-1:i+2]) < P[i] < max(P[i-1:i+2]):
                cnt += 1
        print(cnt)
    except:
        break

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:

n = int(input())
p = list(map(int,input().split()))
print(sum([max(p[i+1],p[i],p[i-1]) != p[i] and min(p[i+1],p[i],p[i-1]) != p[i] for i in range(1,n-1)]))

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

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

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

flag = 0
for i in range(1,n-1):
    A = p[i-1] < p[i] and p[i] < p[i+1]
    B = p[i+1] < p[i] and p[i] < p[i-1]
    if A or B:
        flag = flag + 1
print(flag)

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:
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


def main():
    S = int(input())
    nums = list(map(int, input().split()))

    ans = 0

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N = int(input())
lst = list(map(int,input().split()))

cnt = 0
le = len(lst)
for i, _ in enumerate(lst,1):
    if (i+1) == le:
        break
    
    if ( lst[i-1] < lst[i] < lst[i+1] ) or ( lst[i+1] < lst[i] < lst[i-1] ):
        cnt += 1

print ( cnt )

Submission status: Accepted

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

Submission status: Accepted

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

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()))
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

count = 0

for i in range(1, n-1):
	if lp[i+1] > lp[i] and lp[i] >= lp[i-1]:
		count += 1
	elif lp[i-1] > lp[i] and lp[i] >= lp[i+1]:
		count += 1


print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())
    P = list(map(int, input().split()))
    ans = 0
    for i in range(1, N - 1):
        a, b, c = P[i - 1], P[i], P[i + 1]
        ans += list(sorted([a, b, c]))[1] == b
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

num = n-2
ans = 0

for i in range(num):

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(N):
    l = sorted(L[i - 1 : i + 2])
    if len(l) != 3:
        continue

    if L[i] == l[1]:
        ans += 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

for p1, p2, p3 in zip(p, p[1:], p[2:]):
  l = sorted([p1, p2, p3])
  if p2 == l[1]:
    answer += 1
print(answer)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

print(output)

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

Submission status: Accepted

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

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

count = 0
for i in range(1,n-1):
    temp = sorted(p[i-1:i+2])
#    print(temp)
    if p[i] == temp[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):
  p = [P[i],P[i+1],P[i+2]]
  p = sorted(p)
  if p[1] == P[i+1]:
    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] > P[i + 1] > P[i + 2]:
        c += 1

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
lst = list(map(int, input().split()))
cnt = 0
for i in range(N-2):
    if lst[i] < lst[i+1] and lst[i+1] < lst[i+2]:
        cnt += 1
    elif lst[i] > lst[i+1] and lst[i+1] > lst[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):
    pc=[]
    pc=sorted(p[i-1:i+2])
    if p[i]==pc[1]:
        count+=1
print(count)

Submission status: Accepted

Solution code:
n=int(input())

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

ans= 0

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

Submission status: Accepted

Solution code:
import sys

indata = sys.stdin.read().strip().splitlines()[1]
numbers = list(map(int, indata.split(" ")))
ans = 0
for i in range(1, len(numbers)):
  p = i - 1
  n = i + 1
  if n >= len(numbers):
    break
  if numbers[p] < numbers[i] < numbers[n] or\
     numbers[n] < numbers[i] < numbers[p]:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy

def solve(string):
    n, *p = map(int, string.split())
    p = numpy.asarray(p)
    asc=(p[:-2] < p[1:-1]) & (p[1:-1] < p[2:])
    desc=(p[:-2] > p[1:-1]) & (p[1:-1] > p[2:])
    return str(sum(asc | desc))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
import numpy

def solve(string):
    n, *p = map(int, string.split())
    p = numpy.asarray(p)
    asc=(p[:-2]<p[1:-1]) & (p[1:-1]<p[2:])
    desc=(p[:-2]>p[1:-1]) & (p[1:-1]>p[2:])
    return str(sum(asc | desc))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

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

Submission status: Accepted

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

count=0
for i in range(0,len(a)-2):
    if a[i] < a[i+1] < a[i+2]:
        count+=1
    if a[i] > a[i+1] > a[i+2]:
        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(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())
L = list(map(int, input().split()))
lis = []
cou = 0
for i in range(N - 2):
    lis.append([L[i], L[i + 1], L[i + 2]])
for i in range(len(lis)):
    if lis[i][0] < lis[i][1] < lis[i][2] or lis[i][0] > lis[i][1] > lis[i][2]:
        cou += 1
print(cou)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = raw_input()
p = map(int, raw_input().split())
c =  0
for i in range(1, len(p)-1):
    if p[i] > p[i-1] and p[i] < p[i+1]:
        c += 1
    elif p[i] > p[i+1] and p[i] < p[i-1]:
        c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

print(counter)

Submission status: Accepted

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

n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
	a,b,c = l[i-1], l[i], l[i+1]
	if a < b < c:
		ans += 1
	elif c < b < a:
		ans += 1
print(ans)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
readints=lambda:map(int,input().split(' '))
n=int(input())
a=list(readints())
ans=0
for i in range(1,n-1):
  arr=[a[i-1],a[i],a[i+1]]
  arr.sort()
  if a[i]==arr[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:
def solve(l:list):
    cnt = 0
    for i in range(1, len(l)-1):
        if l[i+1]>l[i]>l[i-1] or l[i+1]<l[i]<l[i-1]:
            cnt += 1
    return cnt

def main():
    input()
    l = list(map(int, input().split(" ")))
    print(solve(l))

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

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

Submission status: Accepted

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


if __name__ == "__main__":
    test()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getlist():
	return list(map(int, input().split()))

n = int(input())
p = getlist()

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
	else:
		pass

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:
def main():
    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
    return count

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