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:
#!/usr/bin/env python

def main(n, p):
    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
    return ans

if __name__ == '__main__':
    n = int(input())
    p = list(map(int, input().split()))
    print(main(n, p))

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))
ans = 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]:
        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):
    a = P[i-1]
    b = P[i]
    c = P[i+1]
    if a<b<c or a>b>c:
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
n = int(ss[0])
p = list(map(lambda x: int(x), ss[1].split()))
result = []
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]:
        result.append(1)
print(len(result))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
b=l[0]
c=l[1]
ans=0
for i in range(2,n):
  a=b
  b=c
  c=l[i]
  ab=b>a
  bc=c>b
  if (ab==True and bc==True) or (ab==False and bc==False):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())
A = list(map(int,input().split()))
ans=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]):
        ans +=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def count(ps):
    if len(ps) <= 2:
        return 0
    qs = sorted(ps[0:3])
    res = 1 if qs[1] == ps[1] else 0
    return res + count(ps[1:])

print(count(ps))

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

print(count)

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])*(l[i+1]-l[i]) < 0:
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(temp)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
kosuu = int(input())
hairetu = list(map(int, input().split()))
count = 0
step = kosuu - 2
for a in range(step):
    if hairetu[a] < hairetu[a + 1] < hairetu[a + 2]:
        count += 1
    if hairetu[a + 2] < hairetu[a+1] < hairetu[a]:
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def q35(n, p):
    count = 0
    for i in range(n-2):
        a = p[i:i+3]
        if min(a) != p[i+1] and max(a) != p[i+1]:
            count += 1
    return count

N = int(input())
p = [int(i) for i in input().split()]
print(q35(N, p))

Submission status: Accepted

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

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:
def bSort(a):
    for i in range(len(a)):
        for j in range(len(a)-1, i, -1):
            if a[j] > a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]

    return a



n = int(input())

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

d = [0]*3
c = [0]*3
count = 0

for i in range(n-2):
    for j in range(3):
        d[j] = p[i+j]
        c = d[:]
    d = bSort(d)
    
    if c[1] == d[1]:
        count += 1
print(count)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import  numpy   as      np

I_N             =       int(input())
S               =       input().split()
I_S             =       np.array(S).astype(type(I_N))
I_Counter       =       0

for i in range(1,I_N-1):

        if(I_S[i-1] < I_S[i] and I_S[i] < I_S[i+1]):
                I_Counter       +=      1
        elif(I_S[i-1] > I_S[i] and I_S[i] > I_S[i+1]):
                I_Counter       +=      1

print(I_Counter)

Submission status: Accepted

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

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

main()

Submission status: Accepted

Solution code:
#ABC132 B
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 p[i] == L[1]:
        C += 1
print(C)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
	n = int(input().strip())
	v = list(map(int, input().strip().split()))
	ans = 0
	for i in range(n-2):
		l = v[i:i+3]
		# print(l)
		t = l[1]
		if t == sorted(l)[1]:
			ans += 1
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

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

cnt=0
for i in range(1,N-1):
  temp_list = num_list[i-1:i+2]
  sort_list = sorted(temp_list)
  if temp_list[1] == sort_list[1]:
    cnt+=1
print(cnt)

Submission status: Accepted

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

# p = [9, 6, 3, 2, 5, 8, 7, 4, 1]
# n = len(p)

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
a = [int(a[i]) for i in range(n)]
b = 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])):
		b+=1
print(b)

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

Submission status: Accepted

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

Submission status: Accepted

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

# -*- coding: utf-8 -*-


from sys import stdin

#import time
#fd = open('b.txt')
#stdin = fd
#start=time.time()

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

# read data for n sequences.
temp = stdin.readline().split()
N = int(temp[0])

data = []
write = stdin.readline().split()
for i in range(N):
    data.append(int(write[i]))

count = 0
for i in range(N-2):
    array = sorted(data[i:i+3])
    if data[i+1]==array[1]:
        count += 1
        
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
p=list(map(int,input().split()))
#print(n)
#print(p)
i=1
l=[]
while i<n-1:
  if p[i-1]<p[i]<p[i+1] or p[i-1]>p[i]>p[i+1]:
    l.append(i)
  else:
    pass
  i+=1
print(len(l))

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())
seq_str = input().split(" ")
seq = [int(s) for s in seq_str]
counter = 0

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

Submission status: Accepted

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

cnt=0
for i in range(1,n-1):
  if p[i-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()))

ans = 0
for i in range(1, n-1):
  s = sorted(p[i-1:i+2], reverse=True)
  if s[0] != p[i] and s[1] == p[i]:
    ans += 1
print(ans)

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

print(an)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = [int(a) for a in input().split()]
ans=0
for i in range (1,n-1):
  mid =A[i]
  top =A[i-1]
  bot =A[i+1]
  B =[top,mid,bot]
  ma =(max(B))
  mi =(min(B))
  if mi != mid and ma != mid:
    ans +=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
p = [int(i) for i 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()))
counter = 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]):
        counter += 1
    
print(counter)

Submission status: Accepted

Solution code:
def main():
    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+2]<l[i+1]<l[i]:
            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 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:
X = int (input())
N =[int(i) for i in input().split()]

a=0
for i in range(X-2):
	if sorted(N[i:i+3])[1] == N[i:i+3][1]:
		a += 1
print(a)

Submission status: Accepted

Solution code:
#coding:utf-8
cnt = 0

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

for i in range(1,len(p)-1):
    L = [p[i-1],p[i],p[i+1]]
    L.sort()
    if L[1] == p[i]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
p = [int(line) for line in 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(' ')))
num = 0
for i in range(1,N-1):
  if min(P[i-1],P[i+1]) < P[i]  and P[i] <max(P[i-1],P[i+1]):
    num += 1
print(num)

Submission status: Accepted

Solution code:
N = int(input())
Pn=list(map(int,input().split()[:N]))

def judge(x,y,z):
    if x < y < z or z< y< x:
        return 1
    else:
        return 0

ret=0
for i in range(1,N-1):
    ret+=judge(Pn[i-1],Pn[i],Pn[i+1])
print(ret)

Submission status: Accepted

Solution code:
N = int(input())
P = list(map(int,input().split(' ')))
num = 0
for i in range(1,N-1):
  if min(P[i-1],P[i+1]) < P[i]  and P[i] <max(P[i-1],P[i+1]):
    num += 1
print(num)

Submission status: Accepted

Solution code:
n = int(input())

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

c = 0

for i in range(1, n-1):
    t = [arr[i-1], arr[i], arr[i+1]]
    t.sort()
    if arr[i] == t[1]:
        c+=1

print(c)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import copy
import numpy as np

S = input()

N = int(S)

S = input()

P = list(map(int, S.split()))

check = []

count = 0

for i in range(0, N-2, 1):

    check = P[i:i+3]
    check = np.array(check)
    check = check.argsort()
    if check[1] == 1:
        count = count + 1

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def OrdinaryNumber(n,p,flag=None):
    
    #リストの要素数が3未満なら０を返す（再帰終了）
    if n < 3:
        return 0
    
    #p[0]<p[1]の場合
    if flag == "LessThan":
        if p[1] < p[2]:
            count = OrdinaryNumber(n-1, p[1:], "LessThan")+1
        else:
            count = OrdinaryNumber(n-1, p[1:], "GreaterThan")
            
    #p[0]>p[1]の場合
    elif flag == "GreaterThan":
        if p[1] < p[2]:
            count = OrdinaryNumber(n-1, p[1:], "LessThan")
        else:
            count = OrdinaryNumber(n-1, p[1:], "GreaterThan")+1
    
    #最初のみ
    else:
        if p[1] < p[2]:
            count = OrdinaryNumber(n-1, p[1:], "LessThan")
            if p[0] < p[1]:
                count +=1
        else:
            count = OrdinaryNumber(n-1, p[1:], "GreaterThan")
            if p[0] > p[1]:
                count +=1
                
    return count

n = int(input())
print(OrdinaryNumber(n,list(map(int,input().split()))))

Submission status: Accepted

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

cnt = 0
for i in range(n - 2):
    permutation = [p[i], p[i + 1], p[i + 2]]
    permutation.pop(permutation.index(max(permutation)))
    if max(permutation) == p[i + 1]:
        cnt += 1

print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(N - 2):
    X = [P[i], P[i + 1], P[i + 2]]
    X.sort()
    if X[1] == P[i + 1]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
# 数列の長さを入力
n = int(input())

# 数列の要素を入力
p = list(map(int, input().split()))

# カウント用変数を0で初期化
count = 0

# 条件を満たすケースをカウント
for i in range(n - 2):
    
    if sorted(p[i:i + 3])[1] == p[i:i + 3][1]:
    
        count = count + 1
        
print("{}".format(count))

Submission status: Accepted

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

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

 else:
    a=a

print(a)

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

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

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

print(count)

Submission status: Accepted

Solution code:
#整数Nを得る
N = int(input())
#list  Pを得る
P = list(map(int,input().split()))

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

print(c)

Submission status: Accepted

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


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

print(ans)

Submission status: Accepted

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

count = 0
for i in range(n-2) :
    l = p[i:i+3]
    if (min(l) != l[1] and max(l) != l[1]) :
        count += 1

print(count)

Submission status: Accepted

Solution code:
def B_OrdinaryNumber():
    n = int(input())
    pn = list(map(int, input().split()))
    ans = 0
    for i in range(n - 2):
        if ((pn[i] < pn[i + 1]) and (pn[i+1] < pn[i+2])) or ((pn[i] > pn[i + 1]) and (pn[i+1] > pn[i+2])):
            ans += 1
    print(ans)
    
if __name__ == "__main__":
    B_OrdinaryNumber()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l=[];cnt=0;a1=0;a2=0;a3=0
l= list(map(int,input().strip().split()))[:n]
for i in range(n-2):
    mid=0
    a1=l[i]
    a2=l[i+1]
    a3=l[i+2]
    if a2 is not max(a1,a2,a3) and a2 is not min(a1,a2,a3):
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
P= [int(x) for x in input().split()]

answer=0
for i in range(1,N-1):
  a,b,c=P[i-1:i+2]
  if b != max(a,b,c) and b!= min(a,b,c):
    answer+=1

print(answer)

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

print(cnt)

Submission status: Accepted

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

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

print(len([a for a,b,c in zip(nums, nums[1:], nums[2:]) if sorted([a,b,c])[1]==b]))

Submission status: Accepted

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

cnt = 0
for i in range(1, len(P)-1):
    sub = [P[i-1], P[i], P[i+1]] 
    sub.sort()
    if P[i] == sub[1]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))  # 入力のときに N を使う必要はありません

count = 0

for i in range(N-2):
    first = A[i]
    second = A[i+1]
    third = A[i+2]
    if first < second:
        if second < third:
            count += 1
        else:
            count += 0
    else:
        if second > third:
            count += 1


print(count)

Submission status: Accepted

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

count=0

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

print(count)

Submission status: Accepted

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


def solve(n: int, p: "List[int]"):
    counter = 0
    for i in range(1, n-1):
        if (p[i-1] - p[i]) * (p[i] - p[i+1]) > 0:
            counter += 1
    print(counter)
    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())
p = list(map(int, input().split()))
ans = sum(1 for i in range(n-2) if p[i] < p[i+1] < p[i+2] or p[i] > p[i+1] > p[i+2])
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):
    buff = []
    buff = P[i-1:i+2]
    buff.sort()
    if P[i] == buff[1]:
        counter += 1


print(counter)

Submission status: Accepted

Solution code:
def main():
    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
        if p[i-1] > p[i] and p[i] > p[i+1]:
            count += 1
    print(count)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

def main():
    n = int(input())
    order_list = list(map(int, input().split(" ")))
    count = 0
    for i in range(n-2):
        dif1 = order_list[i+1]-order_list[i]
        dif2 = order_list[i+2]-order_list[i+1]
        if dif1*dif2 > 0:
            count = count + 1
        else:
            pass

    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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 main05():
    num = int(input())
    data = input().split()
    zyun = []
    for i in data:
        zyun.append(int(i))
    result = 0
    for i in range(num-2):
        if zyun[i] < zyun[i+1]:
            if zyun[i+1] < zyun[i+2]:
                result = result + 1
        else:
            if zyun[i+1] > zyun[i+2]:
                result = result + 1
    print(result)

if __name__ == "__main__":
    main05()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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

print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
L=list(input().split())
t=1
Q=0
while t<n-1:
  if int(L[t-1])<int(L[t])<int(L[t+1]) or int(L[t+1])<int(L[t])<int(L[t-1]):
    Q+=1
  t+=1
print(Q)

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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