Problem:


Score : 200 points

Problem Statement

We have a permutation p = {p_1,\ p_2,\ ...,\ p_n} of {1,\ 2,\ ...,\ n}.

Print the number of elements p_i (1 < i < n) that satisfy the following condition:

p_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}.

Constraints

All values in input are integers.

3 \leq n \leq 20

p is a permutation of {1,\ 2,\ ...,\ n}.

Input

Input is given from Standard Input in the following format:

n
p_1 p_2 ... p_n

Output

Print the number of elements p_i (1 < i < n) that satisfy the condition.

Sample Input 1

5
1 3 5 4 2

Sample Output 1

2

p_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.

Sample Input 2

9
9 6 3 2 5 8 7 4 1

Sample Output 2

5



Sample input:
5
1 3 5 4 2


Sample output:
2

Submission status: Accepted

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

Submission status: Accepted

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

# check
cnt = 0
for i in range(1, n - 1):
    if sorted(p[i - 1:i + 2])[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]:
        ans += 1
    elif 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()))
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
    else :
        ans+=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 - 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):
  b=p[i:i+3]
  if b[1]<max(b) and b[1]>min(b):
    ans+=1
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
a=[0]*n
a[:]=map(int,input().split())
r=0
import copy
for ii in range(n-2):
  b=copy.copy(a[ii:ii+3])
  c=copy.copy(b)
  b.sort()
  if b[1]==c[1]:
    r+=1
print(r)

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

Submission status: Accepted

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

for i in range(1,n-1):
  num.append([p[i-1],p[i],p[i+1]])

for i in num:
  a=i[1]
  i.sort()
  if i[1]==a:
    count+=1
    
print(count)

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
import copy

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

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

print(count)

Submission status: Accepted

Solution code:
def ordinary_number(n, pli):

    ans = 0

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

    return ans

def main():
    n = int(input())
    pli = list(map(int, input().split()))
    print(ordinary_number(n, pli))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

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

#############
# Main Code #
#############

n = inputI()
a = inputIL()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import bisect

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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())
p = list(map(int,input().split()))
count = 0
for i in range(n-2):
    l = p[i:i+3]
    ls = sorted(l)
    if l[1] == ls[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:
import sys
input = sys.stdin.readline
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(input().split())
p = [int(p[i]) for i in range(n)]
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):
    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())
ps=list(map(int,input().split()))
c=0
for i in range(1,n-1):
    p1=ps[i-1]
    p2=ps[i]
    p3=ps[i+1]
    if p1<p2<p3 or p3<p2<p1:
        c+=1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve(n: int, p: "List[int]"):
    ans = 0
    for i in range(1,n-1):
        if (p[i-1] > p[i]) ^ (p[i] < p[i+1]):
            ans +=1
    print(ans)
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0
for i in range(n-2):
    seq = p[i:i+3]
    
    a = seq[1]

    if sorted(seq)[1] == a:
        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:
def solve():
    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)


solve()

Submission status: Accepted

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

ans = []

def judge(l):
    if l[0]<l[1]<l[2]:
        return True
    elif l[0]>l[1]>l[2]:
        return True
    else:
        return False

for i in range(n-2):
    ans.append(judge(p[i:i+3]))

print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
P = LI()
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 = input()

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

ans = 0

for i in range(1,len(x)-1):
    t = [x[i-1],x[i],x[i+1]]
    t.sort()
    if t[1] == x[i]:
        ans += 1
        
print(ans)

Submission status: Accepted

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

for i in range(n-2):
  li2 = []
  li2.append(li[i])
  li2.append(li[i+1])
  li2.append(li[i+2])
  li2.sort()
  if li2[1] == li[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):
    term3 = p[i-1:i+2]
    if sum(term3) - min(term3) - max(term3) == p[i]:
        count += 1
print(count)

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
assert n <= 20 and n >= 3,"input error(3 <= n <= 20)"
p = list(map(int,input().split()))
res = 0
for i in range(1,n-1,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]):
        res +=1

print(res)

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

Submission status: Accepted

Solution code:
# B - Ordinary Number

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

cnt = 0
for i in range(1, N - 1):
    if P[i - 1] < P[i] < P[i + 1] or P[i + 1] < P[i] < P[i - 1]:
        cnt += 1

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

Submission status: Accepted

Solution code:
a=int(input())
b=list(map(int,input().split()))
count=0
for i in range(1,a-1):
    c=sorted([b[i-1],b[i],b[i+1]])
    if c[1]==b[i]:
      count+=1
    else:
        continue
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import argv

debug = "a" in argv
n = int(input())
a = tuple(map(int, input().split()))
ans = 0
for x in range(n - 2):
    if debug:
        print(x, a[x], a[x + 1], a[x + 2])
    if sorted([a[x], a[x + 1], a[x + 2]])[1] == a[x + 1]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
# region header
import sys
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos, pi, e
from operator import itemgetter
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
N = ri()
p = ri_()
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:
# region header
import sys
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos, pi, e
from operator import itemgetter
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
N = ri()
p = ri_()
ans = 0
for i in range(1, N - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i + 1] < p[i] < p[i - 1]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = [int(u) for u in input().split()]
res = 0
for i in range(1,n-1):
    if sorted(l[i-1:i+2])[1] == l[i]:
        res += 1
print(res)

Submission status: Accepted

Solution code:
n=int(input())
numeros=[int (x) for x in input().split()]
cont=0
for x in range(0,n-2):
    if (numeros[x+1]>numeros[x] and numeros[x+1]<numeros[x+2]) or (numeros[x+1]<numeros[x] and numeros[x+1]>numeros[x+2]):
        if x==n-2:
            break
        cont+=1
print(cont)

Submission status: Accepted

Solution code:
a=int(input())
seqS=input().split(" ")
num=[]
for q in seqS:
    num.append(int(q))
contador=0

#primeiro
#if num[0] > num[1]:
    #contador+=1

for i in range(1,len(num)-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]:
        contador+=1

#ultimo
#if num[-1] > num[-2]:
    #contador+=1
print(contador)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

c = 0

for i in range(1, len(p)-1):
  f = p[i-1]
  s = p[i]
  t = p[i+1]
  ma = max(f,t)
  mi = min(f,t)
  if s > mi and s < ma:
    c += 1

print(c)

Submission status: Accepted

Solution code:
def main():
    n = input()
    p = [int(x) for x in input().split()]
    c = 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]:
            c += 1
    print(c)

main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    P = list(map(int, input().split()))
    ans = 0

    for i in range(1, N - 1):
        tmp = [P[i - 1], P[i], P[i + 1]]
        tmp.sort()

        if tmp[1] == P[i]:
            ans += 1

    print(ans)


resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
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]]
    A.sort()
    if A[1]==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]) 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):
    a,b,c = p[i-1:i+2]
    if b != min(a,b,c,) and b != max(a,b,c):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int, input().split()))
    cnt=0
    for i in range(1,n-1):
        if l[i-1]<l[i]<l[i+1] or l[i+1]<l[i]<l[i-1]:
            cnt+=1
    print(cnt)
resolve()

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
cnt = 0 
s = list(map(int,input().split()))
for i in range(n-2):
	
	t=[]
	t.append(s[i])
	t.append(s[i+1])
	t.append(s[i+2])

	t.sort()
	#print(t)
	if t[1] == s[i+1]:
		cnt += 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#ABC 132 B
n = int(input())
p= [int(j) for j in input().split()]
ans =0
for i in range(0,n-3+1):
    if p[i:i+3][1] ==sorted(p[i:i+3])[1]:
        ans+=1
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter
import itertools
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

n = int(input())
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)

Submission status: Accepted

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

def main():
    n = int(input())
    *p, = 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)


main()

Submission status: Accepted

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

ans = 0

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

print(ans)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, N-1):
  t = [P[i -1], P[i], P[i + 1]]
  t.sort()
  if t[1] == P[i]:
    cnt += 1
print(cnt)

Submission status: Accepted

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