Problem:


Score : 200 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

3 \leq n \leq 20

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

Input

Input is given from Standard Input in the following format:

n
p_1 p_2 ... p_n

Output

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

Sample Input 1

5
1 3 5 4 2

Sample Output 1

2

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

Sample Input 2

9
9 6 3 2 5 8 7 4 1

Sample Output 2

5



Sample input:
5
1 3 5 4 2


Sample output:
2

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
p_li = list(map(int,input().split()))
cnt = 0
for i in range(n):
    if i == 0 :
        continue
    if i == n - 1 :
        break
    original = p_li[i]
    p_i_li = [p_li[i - 1], p_li[i], p_li[i + 1]]
    p_i_li.sort()
    if p_i_li[1] == original :
        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]:
        cnt += 1
    if p[i - 2] > p[i - 1] > p[i]:
        cnt += 1
print(cnt)

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])*(A[i+1]-A[i]) > 0:
    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:
def checker(i,s):
  if s[i] > s[i+1] and s[i+1] > s[i+2]:
    return True
  elif s[i] < s[i+1] and s[i+1] < s[i+2]:
    return True
  return False

n = int(input())
s = [int(i) for i in input().split()]
res = 0

for i in range(n-2):
  if checker(i,s):
    res += 1
print(res)

Submission status: Accepted

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

cnt = 0
l = len(p)

for i in range(l):
    if i == 0 or i == l - 1:
        continue

    if (p[i - 1] < p[i]) and (p[i] < p[i + 1]):
        cnt += 1
    elif (p[i - 1] > p[i]) and (p[i] > p[i + 1]):
        cnt += 1

print(cnt)

Submission status: Accepted

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

ans = 0

for i in range(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())
a=[int(i) for i in input().split()]
ans=0
for i in range(1,len(a)-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])):
        ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import io
import sys


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
5
1 3 5 4 2
'''


def MAIN():
  # T_IN()
  A()


def A():
  s = IN_I()
  l = IN_L_I()

  r = [0] * s

  p = l[0]
  pc = 0
  m = l[0]
  mc = 0

  for num in l[1:]:
    if num < p:
      pc += 1
    else:
      r[pc] += 1
      pc = 0

    if num > m:
      mc += 1
    else:
      r[mc] += 1
      mc = 0

    p = num
    m = num

  r[pc] += 1
  r[mc] += 1

  ret = 0
  for i, count in enumerate(r[2:]):
    ret += (i + 1) * count

  print(ret)

def B():
  return None


def C():
  return None


MAIN()

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

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0
for i in range(len(X) - 2):
  if (X[i] > X[i+1] > X[i+2]) or (X[i] < X[i+1] < X[i+2]):
  	ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A = int(input())
B = list(map(int, input().split()))
ans = 0

for i in range(1, A-1):
  if B[i-1] > B[i] > B[i+1]:
    ans += 1
  elif B[i-1] < B[i] < B[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(1,n-1):
    if p[i]>p[i-1]:
        if p[i+1]>p[i]:
            count=count+1
    elif p[i]>p[i+1]:
        if p[i-1]>p[i]:
            count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
t=list(map(int,input().split()))
ans=0
a=[]
for i in range(n-2):
    a.append(t[i])
    a.append(t[i+1])
    a.append(t[i+2])
    total=sum(a)
    total=total-min(a)-max(a)
    if total==a[1]:
        ans+=1
    del a[:]
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_comp = [P[i-1],P[i],P[i+1]]
    P_comp.sort()
    if P_comp[1] == P[i]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#132
#入力（1次元）
n = int(input())
p = list(map(int, input().split()))

count = 0

#判定
for i in range(0,n - 2):
    if(p[i] < p[i + 1] and p[i + 1] < p[i + 2]):
        count = count + 1 
    elif(p[i] > p[i + 1] and p[i + 1] > p[i + 2]):
        count = count + 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
num = input()
x =  [int(s) for s in input().split()]
sum = 0
for i in range(len(x)-2):
    center = x[i+1]
    three = [x[i], x[i+1], x[i+2]]
    if(x[i+1] == int(sorted(three)[1])):
        sum += 1
        
print(sum)

Submission status: Accepted

Solution code:
n=input()
p=input()

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

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

Submission status: Accepted

Solution code:
#x = input().split()
#print (x)
#n = int(x[0])
n = int(input())

#print(n)

#p = list(map(int,x[1:]))
p = list(map(int,input().split()))

#print(p)

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

print(count)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

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

print(total)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
#coding: utf-8
n = int(input())
l = list(map(int,input().split()))
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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):
    count = count + (1 if (float(p[i]-p[i+1])+0.1) * (float(p[i]-p[i-1])+0.1) < 0 else 0 )
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
import math
def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    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]:
            ans += 1
        if a[i+2] <= a[i+1] < a[i]:
            ans += 1
    print(ans)
        
main()

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

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

count = 0
for i, p_i in enumerate(p):
  if i == 0 or i == n-1:
    continue
  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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def count_ordinary_num(n, arr):
    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
    return cnt


def main():
    n = int(input())
    p_arr = list(map(int, input().split()))

    ans = count_ordinary_num(n, p_arr)
    print(ans)


main()

Submission status: Accepted

Solution code:
n=int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())

p = list(int(i) for i in input().split())


ans = 0
for i in range(1, n - 1):
    l = [p[i - 1], p[i], p[i + 1]]
    l.sort()
    if (l[1] == p[i]):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

c = 0
for i,j,k in zip(pList[0:], pList[1:], pList[2:]):
    x = [i,j,k]
    x.sort()
    if x[1] == j:
        c += 1
print(c)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
k = 0
for i in range(1,n-1):
  p_1 = l[i-1]
  p_2 = l[i]
  p_3 = l[i+1]
  _ = [p_1,p_2,p_3]
  if (min(_)==p_1 and max(_)==p_3) or (min(_)==p_3 and max(_)==p_1):
    k +=1
print(k)

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  p = list(map(int,input().split()))
  ans = 0 
  up = 1 # state of up or down if up, p[i] < p[i+1]
  for i in range(n-2):
    """if p[i+1] > p[i+2]:
      up = 0"""
    if (p[i]-p[i+1])*(p[i+1]-p[i+2]) > 0 :
      ans += 1
  print(ans)
main()

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

count = 0

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

print(count)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(lambda x: int(x), input().split(" ")))
c = 0
for i in range(1, n-1):
    a = max(p[i-1:i+2])
    b = min(p[i-1:i+2])
    if a is not p[i] and b is not p[i]:
        c = c + 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    n = int(input())
    p = list(map(int, input().split()))
    count = 0

    for i in range(1, n - 1):
        value_max = max(p[i - 1], p[i], p[i + 1])
        value_min = min(p[i - 1], p[i], p[i + 1])

        if p[i] != value_max and p[i] != value_min:
            count += 1

    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(1, n-1):
    #print("p[{}], p[{}], p[{}] = {}, {}, {}".format(i-1, i, i+1, p[i-1], p[i], p[i+1]))
    if min([p[i-1], p[i], p[i+1]]) < p[i] < max([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()))
l=0
a=0

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

print(a)

Submission status: Accepted

Solution code:
# stdin
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
n = int(ss[0])
p = [int(i) for i in ss[1].split()]
result = 0
print(len(
    [1 for i in
        [{"pm": sorted([p[i-1], p[i], p[i+1]])[1], "p": p[i]} for i in range(1, n-1)]
        if i["pm"] == i["p"]]
        ))

Submission status: Accepted

Solution code:
# stdin
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
n = int(ss[0])
p = [int(i) for i in ss[1].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()))
l=[[p[i],p[i+1],p[i+2]] for i in range(n-2)]
c=0
for item in l:
  if (item[1]>item[0] and item[1]<item[2]) or (item[1]<item[0] and item[1]>item[2]):
    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] and p[i+1]<p[i]:
    ans+=1
  if p[i-1]<p[i] and p[i+1]>p[i]:
    ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
data = list(map(int, input().split()))
pn = [x for x in range(1, N-1)]

cnt = 0
for p in pn:
    p_t = np.sort([data[p - 1], data[p], data[p + 1]])
    cnt = cnt + 1 if p_t[1] == data[p] else cnt
    
print(cnt)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
# B - Ordinary Number

N = int(input())
data = list(map(int, input().split()))
ans = 0
for i in range(N-2):
    if (data[i+1] > data[i] and data[i+1] < data[i+2]) or (data[i+1] < data[i] and data[i+1] > data[i+2]):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

cnt = 0
for i in np.arange(1,n-1):
    tmp_l = [P[i-1],P[i],P[i+1]]
    tmp_l.sort()
    if tmp_l[1] == P[i]:
        cnt+=1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
P = list(map(int, input().split()))
ans = 0
for i in range(n):
    if i == 0 or i == n-1:
        ans += 0
    elif (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 = input()
n = map(int, raw_input().split())

ans = 0

for i in range(1, len(n) - 1):
  if n[i] < n[i - 1] and n[i] > n[i + 1]:
    ans += 1
  if n[i] > n[i - 1] and n[i] < n[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] and p[i]<p[i+1]:
        cnt += 1
    elif p[i-1]>p[i] and p[i]>p[i+1]:
        cnt += 1
    else:
        cnt = cnt
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
p = [int(i) for i in input().split()]
sum = 0
for i in range(n-2):
    if ((p[i+2] < p[i+1]) & (p[i+1] < p[i])) | ((p[i] < p[i+1]) & (p[i+1] < p[i+2])):
        sum = sum+1
print(sum)

Submission status: Accepted

Solution code:
def myInput():
  n = input()
  s = input()
  return (n, [int(i) for i in s.split()])

def func():
  n, lst1 = myInput()
  cnt = 0
  for i in range(1, int(n)-1):
    if min(lst1[i+1],max(lst1[i], lst1[i-1])) == lst1[i]:
      cnt+=1
    elif min(lst1[i-1],max(lst1[i],lst1[i+1])) == lst1[i]:
      cnt += 1
  return cnt
print(func())

Submission status: Accepted

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

K=0

for i in range(N-2):
    if list1[i]>list1[i+2]:
        if list1[i]>list1[i+1] and list1[i+1]>list1[i+2]:
            K+=1
            
    else:
        if list1[i]<list1[i+1] and list1[i+1]<list1[i+2]:
            K+=1

print(K)

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

Submission status: Accepted

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

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

ans = 0
for i in range(N - 2):
    pool = [p[i], p[i + 1], p[i + 2]]
    if min(pool) == p[i + 1]:
        continue
    if max(pool) == p[i + 1]:
        continue
    #
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
b=list(map(int,input().split()))
c=0
d=0
while c<=n-3 :
    if (b[c+1]>b[c] and b[c+1]<b[c+2]) or (b[c+1]<b[c] and b[c+1]>b[c+2]):
        d +=1
        c +=1
    else:
        c+=1

print(d)

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

print(count)

Submission status: Accepted

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


def compare(p, i):
    if p[i-1] < p[i] & p[i] < p[i+1]:
        return True
    if p[i-1] > p[i] & p[i] > p[i + 1]:
        return True
    return False
dic = {}
p = []

for i in range(n):
    p.append( int(p_[i]))

count=0
for i in range(1,n-1):
  res = compare(p,i)
  if res:
    count+=1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
p_list = input().split(' ')

p_i_0 = int(p_list[0])
p_i_1 = int(p_list[1])
p_i_2 = int(p_list[2])

counter = 0

for i in range(n - 3):
    if ((p_i_0 - p_i_1) * (p_i_2 - p_i_1) <= 0):
        counter += 1
    p_i_0 = p_i_1
    p_i_1 = p_i_2
    p_i_2 = int(p_list[i + 3])

if ((p_i_0 - p_i_1) * (p_i_2 - p_i_1) <= 0):
    counter += 1
print(counter)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    nums = string_to_int(inputs[0])
    count = 0
    for i in range(0, len(nums)-2):
        if nums[i+1] >= nums[i] and nums[i+1] <= nums[i+2]:
            count += 1
        elif nums[i+1] <= nums[i] and nums[i+1] >= nums[i+2]:
            count += 1
    return count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

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

ls = list(map(int, input().split()))
 
count = 0

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

print(str(count))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(str(count))

Submission status: Accepted

Solution code:
import statistics as stat

def calc(p):
  count = 0
  for i in range(1, len(p) - 1):
    if p[i] == stat.median(p[i - 1:i + 2]):
      count += 1
  return count

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

print(calc(p))

Submission status: Accepted

Solution code:
A = int(input())
C = list(map(int, input().split()))
cnt = 0
for i in range(A-2):
    q = 0
    w = 0
    e = 0
    q = C[i]
    w = C[i + 1]
    e = C[i + 2]
    if q < w < e or e < w < q:
        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+1]:
        a = True if p[i] > p[i-1] and p[i] < p[i+1] else False
    elif p[i-1] > p[i+1]:
        a = True if p[i] < p[i-1] and p[i] > p[i+1] else False
    if a:
        cnt += 1
print(cnt)

Submission status: Accepted

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


print(count)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0

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

print(count)

Submission status: Accepted

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

for i in range(n-2): 
    if s[i] < s[i+1] and s[i+1] < s[i+2]:
        num = num+1 
    elif s[i] > s[i+1] and s[i+1] > s[i+2]:
        num = num + 1
    else: 
        pass

print(num)

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

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

ans = 0

for i in range(n-2):
    a = []
    for j in range(3):
        a.append(p[i + j])
    a.sort()
    if a[1] == p[i + 1]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int, input().split()))
C = 0
for i in range(1, N - 1):
    C += 1 if sorted(L[i - 1:i + 2])[1] == L[i] else 0
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().strip())
listP = list(map(int, input().split()))
count = 0


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

print(count)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
counter = 0
for i in range(len(l)-2):
    h = l[i:i+3]
    if {max(h), min(h)} == {h[0], h[2]}:
        counter += 1
print(counter)