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

Submission status: Accepted

Solution code:
n = int(input())
l = list(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]:
    ans += 1
  elif 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()))

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()))
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:
from enum import Enum

class Status(Enum):
    EQUAL =1
    BIG = 2
    SMALL = 3

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

count = 0

before_status = Status.EQUAL
before_value = P[0]
for p in P:
    if before_value == p:
        before_status = Status.EQUAL
    elif before_status == Status.BIG:
        if before_value < p:
            before_status = Status.BIG
            count += 1
        else:
            before_status = Status.SMALL
    elif before_status == Status.SMALL:
        if before_value > p:
            before_status = Status.SMALL
            count += 1
        else:
            before_status = Status.BIG
    else:
        if before_value < p:
            before_status = Status.BIG
        else:
            before_status = Status.SMALL
    before_value = p

print(count)

Submission status: Accepted

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

cnt=0
for i in range(n-2):
    tmp=[p[i],p[i+1],p[i+2]]
    if max(tmp)!=p[i+1] and min(tmp)!=p[i+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):
  p_i_minus = p_list[i-1]
  p_i = p_list[i]
  p_i_plus = p_list[i+1]
  
  if p_i_minus < p_i < p_i_plus or p_i_plus < p_i < p_i_minus:
    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]):
    ans += 1
  elif(p[i]>p[i+1])and(p[i]<p[i-1]):
    ans += 1
  else:
    None
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d = list(int(i) for i in input().split())
ans = 0

for i in range(n-2):
  if d[i] < d[i+1] and d[i+1] < d[i+2]:
      ans += 1
  elif d[i] > d[i+1] and d[i+1] > d[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, len(P)-1):
    if ((P[i] > P[i-1]) and (P[i] < P[i+1])) \
    or ((P[i] < P[i-1]) and (P[i] > P[i+1])):
        count += 1

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
_,p=open(0);p=p.split();print(sum(sorted(a,key=int)[1]==a[1]for a in zip(p,p[1:],p[2:])))

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

ps=ps.split()
ps=[int(k) for k in ps]

output=0

for m in range(int(n)-2): 
    if ps[m]<ps[m+1] and ps[m+1]<ps[m+2]:
        output=output+1
    elif ps[m]>ps[m+1] and ps[m+1]>ps[m+2]:
        output=output+1
    else:
        output=output+0

print(output)

Submission status: Accepted

Solution code:
import copy

N = int(input())

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

ans = 0
for i in range(1, N-1):
	t = copy.deepcopy(p[i])
	s = copy.deepcopy(p[i-1:i+2])
	
	if t == sorted(s)[1]:
		ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
input = sys.stdin.readline

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


result = 0
l = len(p)
for i in range(1, l-1):
    # i-1, i, i+1を取り出す
    li = p[i-1:i+2]
    # iを記憶してソートする
    c = li[1]
    li = sorted(li)
    # 2番目の要素が記憶した要素と一致しているならカウンタを進める
    if c == li[1]:
        result += 1
    
# カウンタの数値を出力する
print(result)

Submission status: Accepted

Solution code:
n = int(input())
P = [int(p) for p in input().split()]
ans = 0
for i in range(1, n-1):
  Q = P[i-1:i+2]
  R = sorted(Q)
  if P[i] == R[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):
    temp = [p[i-1],p[i],p[i+1]]
    if p[i] == sum(temp) - max(temp) - min(temp):
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(n-2):
    Max = max(p_list[i], p_list[i+1], p_list[i+2])
    Min = min(p_list[i], p_list[i+1], p_list[i+2])
    Middle = p_list[i] + p_list[i+1] + p_list[i+2] - Max - Min
    if(p_list[i+1] == Middle):
        ans += 1
print(ans)

Submission status: Accepted

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

n = int(input())
arrayP = [int(s) for s in input().split()]
 
cnt = 0
 
for i in range(0, n-2):
    threeNums = arrayP[i:i+3]
    threeNums.sort()
    if threeNums[1] == arrayP[i+1]:
        cnt += 1
 
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
for i in range(n-2):
    temp = sorted(t[i:i+3])
    if temp[1] == t[i:i+3][1]:
        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(n-2):
  if p[i+1] == max(p[i], p[i+1], p[i+2]) or p[i+1] == min(p[i], p[i+1], p[i+2]):
    ans += 0
  else:
    ans += 1
print(ans)

Submission status: Accepted

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

total = 0
for i in range(n-2):
    x3 = x[i:i+3]
    mid = x3[1]
    x3.sort()
    if mid == x3[1]:
        total += 1
print(total)

Submission status: Accepted

Solution code:
a = int(input())
x = list(map(int,input().split()))
s = 0
for i, j , k in zip(x,x[1:],x[2:]):
    if i < j < k or k < j < i:s+=1
print(s)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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):
    if li[i-1]<li[i]<li[i+1]:
        cnt+=1
    elif li[i-1]>li[i]>li[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(N-2):
  if L[i] < L[i+1] and  L[i+1] < L[i+2]:
    ans +=1 
  if L[i] > L[i+1] and  L[i+1] > L[i+2]:
    ans +=1 
  else:
    pass

print(ans)

Submission status: Accepted

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

for i in range(1,n-1):
    p = [P[i-1],P[i],P[i+1]]
    p.sort()
    if P[i] == p[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:
I = int(input())
L = list(map(int, input().split()))

cnt = 0

for i in range(len(L) - 2):
  if L[i+1] > L[i] and L[i+1] < L[i+2]:
    cnt += 1
  elif L[i+1] < L[i] and L[i+1] > L[i+2]:
    cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def check(a,b,c):
	if((a<b)and(b<c))or((a>b)and(b>c)):
		return 1
	return 0

import sys
n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

sum=0
for i in range(n-2):
	sum += check(hoge[i],hoge[i+1],hoge[i+2])

print(sum)

Submission status: Accepted

Solution code:
n = int(input())
c = 0
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]:
        c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,n-1):
  _ = [P[i-1],P[i],P[i+1]]
  _.sort()
  if P[i] == _[1]:
    count +=1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
  
  z = int(input())
  if 20 >= z and z >= 3:
    num_list = list(map(int, input().strip().split()))
    count = 0
    for i in range(z-2):
      hoge = num_list[i:i+3]
      hoge_sort = sorted(hoge)
      if hoge[1]==hoge_sort[1]:
        count += 1
    print(count)

Submission status: Accepted

Solution code:
input()
v = list(map(int, input().split()))
c = 0
for x, y, z in zip(v[:-2], v[1:-1], v[2:]):
    if x < y < z or x > y > z:
        c += 1
print(c)

Submission status: Accepted

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

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

print(retval)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
for n in range(1, len(p) - 1):

    if p[n - 1] > p[n + 1]:
        if p[n - 1] > p[n] and p[n] > p[n + 1]:
  
            cnt = cnt + 1
    elif p[n - 1] < p[n] and p[n] < p[n + 1]:
        cnt = cnt + 1

print(cnt)

Submission status: Accepted

Solution code:
# ABC132 B Ordinary-Number

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

#print(n,p)
count=0

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

print(count)

Submission status: Accepted

Solution code:
n = int(input().split()[0])
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())
nums = list(map(int, input().split()))

def mid(threeints):
	a, b, c = threeints[0], threeints[1], threeints[2]
	
	if ((a < b) and (b < c)) or ((a > b) and (b > c)):
		return True
	else:
		return False
		
def solve():
	count = 0
	for i in range(n - 2):
		threeints = nums[i:i+3]
		count += mid(threeints)
	return count
	
print(solve())

Submission status: Accepted

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

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

print(r)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    n = int(stdin.readline().rstrip())
    ps = [int(x) for x in stdin.readline().rstrip().split()]
    x = [(p1, p2, p3) for p1, p2, p3 in [ps[i: i + 3] for i in range(n - 2)] if p1 < p2 <= p3 or p3 < p2 <= p1]
    print(len(x))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
P=[int(i) for i in input().split()]
nanko=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] or P[i-1]==P[i+1]<P[i]):
        nanko+=1

print(nanko)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

index = 0
count = 0
while index < n - 2:
    mini_list = nums[index:index + 3]
    if mini_list[1] == sorted(mini_list)[1]:
        count += 1
    index += 1
print(count)

Submission status: Accepted

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

counter = 0

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

print(counter)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:

count=0

n=int(input())

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

for i in range(n):
    if i ==0:
        continue

    if i==n-1:
        break


    if max(p[i-1],p[i+1])>p[i] and min(p[i-1],p[i+1])<p[i]:
        count+=1




print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = int(input())
z = list(map(int,input().split()))
i = 1
num = 0
while i+1 < x:
    if z[i-1] < z[i] < z[i+1]:
        num += 1
    elif z[i+1] < z[i] < z[i-1]:
        num += 1
    i += 1
print(num)

Submission status: Accepted

Solution code:
n = int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())

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

A=0

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

print(A)

Submission status: Accepted

Solution code:
def checker(list_,index):
  mid = sorted(list_[index:index+3])[1]
  if mid == list_[index+1]:
    return True
  return False

n = int(input())
ps = [int(i) for i in input().split()]
res = 0
for i in range(n-2):
  if checker(ps,i):
    res += 1
print(res)

Submission status: Accepted

Solution code:
n=int(input())

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

A=0

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

print(A)

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]:
        count = count +1
    elif p[i+1] < p[i] < p[i-1]:
        count = count +1
    else:
        pass

print(count)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

ans = 0
for i in range(1,n-1):
    bubun = [jun[i-1], jun[i], jun[i+1]]
    bubun.sort()
    if bubun[1] == jun[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):
    if (p[i]>p[i-1] and p[i+1]>p[i]) or (p[i]<p[i-1] and p[i+1]<p[i]):
        count += 1
print(count)

Submission status: Accepted

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

ct = 0
for i in range(n-2):
    a = int(p[i])
    b = int(p[i+1])
    c = int(p[i+2])
    if a < b and b < c:
        ct += 1
    if c < b and b < a:
        ct += 1
print(ct)

Submission status: Accepted

Solution code:
input()
s=map(int,input().split(' '))
s=list(s)
c=0
for i in range(1,len(s)-1):
  ss=s[i-1:i+2]
  ss=sorted(ss)
  if ss[1]==s[i]:
    c+=1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for i in range(len(li)-2):
  if min(li[i], li[i+1], li[i+2]) != li[i+1] and max(li[i], li[i+1], li[i+2]) != li[i+1]:
    count += 1
  elif max(li[i], li[i+1], li[i+2]) == li[i+1] and (li[i] != li[i+2] and li[i] == max(li[i], li[i+1], li[i+2]) or li[i+2] == max(li[i], li[i+1], li[i+2])):
    count += 1  
    
print(count)

Submission status: Accepted

Solution code:
def main():
    n = int(raw_input())

    num = map(int,raw_input().split())
    cnt = 0
    for i in range(n - 2):
        if num[i] < num[i+1] and num[i+1] < num[i+2]:
            cnt += 1
        if num[i] > num[i+1] and num[i+1] > num[i+2]:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

x=int(input())
t=list(intinput())
ans=0
for i in range(x-2):
    if t[i]<t[i+1]<t[i+2] or t[i]>t[i+1]>t[i+2]:
        ans+=1
print(ans)

Submission status: Accepted

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

for i in range(1,n-1):
  num = []
  num.append(p[i-1])
  num.append(p[i])
  num.append(p[i+1])
  num.sort()
  
  if p[i]==num[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(len(p_list)-2):
    target = p_list[i:i+3]
    if (target[0] < target[1] < target[2]) or (target[2] < target[1] < target[0]):
        count += 1


print(count)

Submission status: Accepted

Solution code:
n = int(input())
li_p = list()

li_p = list(map(int, input().split()))
answer = 0
for i in range(1, n - 1):
    li_w = li_p[i - 1:i + 2]
    if sorted(li_w).index(li_p[i]) == 1:
        answer += 1

print(answer)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

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

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(string):
    n, *p = map(int, string.split())
    ans = 0
    for i, j, k in zip(p, p[1:], p[2:]):
        ans += 1 if i <= j <= k or i >= j >= k else 0
    return str(ans)


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def ordinary(n, numbers):
    i = 0
    ret = 0
    while i + 3 <= n:
        cmp = numbers[i+1]
        if sorted(numbers[i:i+3])[1] == cmp: ret += 1
        i += 1
    return ret
  
n = int(input())
numbers = [ int(i) for i in input().split(' ') ]
print(ordinary(n, numbers))

Submission status: Accepted

Solution code:
n = int(input())
p = input().split()
i = 1
result = 0
while p:
  if (i+1)<n:
    if sorted([int(p[i-1]),int(p[i]),int(p[i+1])])[1] == int(p[i]):
      result+=1
    i+=1
  else:
    break
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#B

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

#n, *p = [int(x) for x in Input.split()]

a = ["#",p[0],p[1]]
count = 0

for i in range(2,n):
    a.pop(0)
    a.append(p[i])
    
    if (a[1]<a[0] and a[1]>a[2])or(a[1]>a[0] and a[1]<a[2]):
        count+=1
    
    #print(a)

print(count)

Submission status: Accepted

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


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

print(ans)

Submission status: Accepted

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

print(sum([1 for n in range(1, n-1) if min(P[n-1], P[n+1]) < P[n] < max(P[n-1], P[n+1])]))

Submission status: Accepted

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

count = 0

for i in range(n-2):
    pn = [P[i], P[i+1], P[i+2]]
    pn.sort()
    if pn[1] == P[i+1]:
        count += 1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, len(l)-1):
    sub = sorted([l[i-1], l[i], l[i+1]])
    
    if sub[1] == l[i]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
def func():
    len_num_seq = int(input())
    count = 0
    a_n = input().rstrip().split(' ')
    for j in range(len_num_seq-2):
        if ((int(a_n[j]) < int(a_n[j+1]) and int(a_n[j+1]) < int(a_n[j+2])) or
           (int(a_n[j]) > int(a_n[j+1]) and int(a_n[j+1]) > int(a_n[j+2]))):
            count += 1
    print(count)

if __name__ == "__main__":
    func()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, len(p)-1):
    a = [p[i-1], p[i], p[i+1]]
    if sorted(a)[1] == a[1]:
        count += 1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
num_array = input().split(" ")

point = 0
for i in range(n-2):
    if int(num_array[i]) < int(num_array[i+1]) < int(num_array[i+2]):
        point += 1
    if int(num_array[i]) > int(num_array[i+1]) > int(num_array[i+2]):
        point += 1

print(point)