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

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

Submission status: Accepted

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

for i in range(1, n-1):
  li = [p[i-1],p[i],p[i+1]]
  if (not p[i] == max(li)) and (not p[i] == min(li)):
    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):
    a = p[i]
    b = p[i+1]
    c = p[i+2]
    if max(a,b,c) != b and min(a,b,c) != b:
        cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(1,n-1):
    args=[p[i-1],p[i],p[i+1]]
    if p[i]==sorted(args)[-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):
    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:
#B - Ordinary Number(ABC132)
n=int(input())
P=list(map(int, input().split()))
C=0
for i in range(n-2):
    A=[P[i],P[i+1],P[i+2]]
    if A[1]!=max(A) and A[1]!=min(A):
        C+=1
print(C)

Submission status: Accepted

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

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

print (cnt)

Submission status: Accepted

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

cnt = 0
for n in range(0, N-2, 1):
  p1 = P[n]
  p2 = P[n+1]
  p3 = P[n+2]
  min_p = min(p1,p2,p3)
  max_p = max(p1,p2,p3)
  if (min_p != p2) and (max_p != p2):
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline())
plist = [int(a) for a in sys.stdin.readline().split()]
ans = 0
for i in range(1, n-1):
  tmp_plist = sorted(plist[i-1:i+2])
  if tmp_plist[1] == plist[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):
    max_p = max(p[i - 1], p[i], p[i + 1])
    min_p = min(p[i - 1], p[i], p[i + 1])
    if max_p != p[i] and min_p != p[i]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
pn = [int(x) for x in input().split()]
res = 0
for i in range(n-2):
  if min(pn[i:i+3]) < pn[i:i+3][1] < max(pn[i:i+3]):
    res += 1
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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=[int(s) for s in input().split()]

c=p[1]
b=p[0]
count=0
for i in range(2,n):
    c,b,a=p[i],c,b
    if b!=max(a,b,c) and b!=min(a,b,c):
            count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
n = int(input())
li = [int(_) for _ in input().rstrip().split()]

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

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(raw_input())

array = map(int, raw_input().split())
num = 0

for i in range(1,N-1):
    if ((array[i] > array[i-1]) and (array[i] <= array[i+1]))or((array[i] <= array[i-1]) and (array[i] > array[i+1])) :
            num += 1

print num

Submission status: Accepted

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

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

print(ans)

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] 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() ]
print(sum((p[i-1]<p[i] and p[i]<p[i+1])or(p[i-1]>p[i] and p[i]>p[i+1]) for i in range(1,n-1)))

Submission status: Accepted

Solution code:
#5
#1 3 5 4 2
#2
N=int(input())
li=list(map(int,input().split()))
cnt=0
for i in range(N-2):
  if li[i]<li[i+1]<li[i+2] or li[i+2]<li[i+1]<li[i]:
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

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

n = I()
p = III()

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()))
cnt = 0
for i in range(2, n):
    a = [p[i], p[i-1], p[i-2]]
    a.sort()
    if p[i-1] == a[1]:
        cnt += 1
print(cnt)

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-1] == p_list[i] < p_list[i+1] or p_list[i] == p_list[i+1] < p_list[i-1]:
        cout += 1
    if p_list[i-1] < p_list[i] < p_list[i+1] or p_list[i+1] < p_list[i] < p_list[i-1]:
        count += 1

print(count)

Submission status: Accepted

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


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

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


# Generated by 1.1.4 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() )
S=input().split(" ")

for i in range ( N ) :
    S[i] = int(S[i])

A = []
num = 0
for i in range ( N - 2 ) :
    A.append ( ( S[i+2]-S[i+1] ) * ( S[i+1]-S[i] ) )
    if A[i] > 0:
        num = num + 1

print ( num )

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	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
		else:
			pass
	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] <= p[i+1] and p[i-1] <= p[i]:
        ans += 1
    elif p[i+1] <= p[i] and p[i] <= p[i-1]:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
inputb = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

listb = []
listb = [int(n) for n in inputb]

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

print(cnt)

Submission status: Accepted

Solution code:
n,*p=map(int,open(0).read().split())
cnt=0
for i in range(1,n-1):
  if sorted([p[i-1], p[i], p[i+1]])[1] == p[i]:
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n,*p=map(int,open(0).read().split())
cnt=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]):
    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 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()))
count=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]:
        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(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())
P1=input().split()
P2=[]
for i in range(n):
    P2.append(int(P1[i]))

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

Submission status: Accepted

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

ans=0
for i in range(n-2):
  a=l[i]
  b=l[i+1]
  c=l[i+2]
  if (a<b<c) or (c<b<a):
    ans+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

sum=0
for i in range(1,N-1):
    if(min(H[i-1],H[i],H[i+1])!=H[i]):
        if(max(H[i-1],H[i],H[i+1])!=H[i]):
            sum+=1
print(sum)

Submission status: Accepted

Solution code:
N = int(input())
Plist = list(map(int,input().split()))
count = 0
for i in range(N-2):
    a1 = Plist[i]
    a2 = Plist[i+1]
    a3 = Plist[i+2]
    b1 =  (a1 < a2 and a2 < a3) 
    b2 =  (a3 < a2 and a2 < a1) 
    if b1 or b2:
        count += 1
print( count )

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

n = int(input())
I = input()
P = []

for i in range(n):
    P.append(int(I.split()[i]))
    

count = 0

for w in range(n-2):
    A = P[w]-P[w+1]
    B = P[w+1]-P[w+2]
    
    if A*B>0:
        count+=1
    
print(count)

Submission status: Accepted

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

    print(score)


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

Submission status: Accepted

Solution code:
#  Ordinary Number
N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(1, N-1):
    if A[i-1]< A[i]< A[i+1] or A[i+1] < A[i] < A[i-1]:
        count = count + 1
    else:
        pass

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve(n: int, p: "List[int]"):
    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)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    p = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, p)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt=0
#配列の最初と最後は無視する
for i in range(1, n-1):
    p_list = [p[i-1], p[i], p[i+1]]
    if not min(p_list) ==  p_list[1] and not max(p_list) == p_list[1]:
        cnt+=1

print (cnt)

Submission status: Accepted

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

count = 0
for i in range(1, N-1):
    m = sorted(Ps[(i-1):(i+2)])[1]
    if m == Ps[i]:
        count += 1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
p=[int(x) for x in input().split()]
count=0
b=2
while b<n:
    x=min(p[b],p[b-1],p[b-2])
    y=max(p[b],p[b-1],p[b-2])
    if p[b-1]!=x and p[b-1]!=y:
        count+=1
    b+=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):
  if max(p[i-1:i+2]) != p[i] and min(p[i-1:i+2]) != p[i]:
    count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
N = int(input())
P = list(map(int, input().split()))
p_list = []
cnt = 0
for i in range(1, N-1):
    p = [P[i-1], P[i], P[i+1]]
    if(max(p) != p[1] and min(p) != p[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(n-2):
    list_i = P[i:i+3]
    if list_i[1] == sorted(list_i)[-2]:
        num += 1
    else:
        num += 0

print(num)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  ps = list(map(int, input().split(' ')))
  ans = 0
  for i in range(0, n-2):
    t = ps[i+1]
    s = sorted(ps[i:i+3])
    ans += 1 if t == s[1] else 0
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

c=0
for i in range(n-2):
    tmp=p_list[i:i+3]
    if tmp[1]==sorted(tmp)[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,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 = 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):
    if (p[i] - p[i + 1]) * (p[i + 1] - p[i + 2]) > 0:
        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(1, n - 1):
    v = P[i]
    row = sorted(P[i-1:i+2])
    if row[1] == v:
        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):
#  print (i, p[i-1], p[i], p[i+1])
  if (p[i+1] - p[i]) * (p[i] - p[i-1]) > 0:
    cnt += 1

print (cnt)

Submission status: Accepted

Solution code:
from statistics import median

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding : utf-8　

import os
import sys

n = int(input())

p = list(map(lambda x: int(x), 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

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

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

print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

count = 0
for i in range(n-2):
    a = [ps[i], ps[i+1], ps[i+2]]
    b = ps[i+1]
    a.sort()
    if a[1] == b:
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

    P_temp = [P[i], P[i+1], P[i+2]]
    P_temp.sort()
    if P_temp[1] == P[i+1]:
        count = count + 1

print(count)

Submission status: Accepted

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

count = 0
for i, pi in enumerate(p):
    if i == 0 or i == n-1:
        pass
    else:
        if pi != max(p[i-1:i+2]) and pi != min(p[i-1:i+2]):
            count += 1
print(count)

Submission status: Accepted

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

for i in range(n-2):
    J = sorted([p[i], p[i+1],p[i+2]])
    if J[1] == 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,len(p)-1):
    small = 1
    if p[i]>p[i-1]:
        small+=1
    if p[i]>p[i+1]:
        small+=1
    if small==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):
    if min(p[i-1:i+2]) < 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()))

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)