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:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
P = np.array(lr())

P_diff = np.diff(P)
P_diff = P_diff > 0
series = P_diff[:-1] == P_diff[1:]
answer = series.sum()
print(answer)
# 23

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, defaultdict, deque, namedtuple
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

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

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    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):
    p_0 = P[i-1]
    p_1 = P[i]
    p_2 = P[i+1]
    
    bool_1 = p_1>p_0 and p_1<p_2
    bool_2 = p_1<p_0 and p_1>p_2
    
    if bool_1 or bool_2:
        count+=1
print(count)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def check(i):
	return 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]
for i in range(n-2):
	if check(i):ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

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


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math

'''a,b= map(int,input().split())'''
#a, b, c = [list(map(int, input().split())) for _ in range(3)]
#li0= [int(x) for x in input().split()]
#n= map(int, input().split())
#x = [list(map(int, input().split())) for _ in range(n)] 
N=int(input())
li0= [int(x) for x in input().split()]
count=0
for i in range(N-2):
  if (li0[i+1]>li0[i] and li0[i+1]<li0[i+2]):
    count+=1
  if(li0[i+1]<li0[i] and li0[i+1]>li0[i+2]):
    count+=1
print(count)

Submission status: Accepted

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

count = 0
for i in range(n-1) :
  if i == 0: continue
  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()))
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())
p = list(map(int, input().split()))

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

print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(1, n-1):
    if 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:
from sys import stdin

n = int(stdin.readline().rstrip())
p = [int(x) for x in stdin.readline().rstrip().split()]

p_con = [p[i] for i in range(
    1, n-1) if (p[i] != min(p[i-1], p[i], p[i+1])) and (p[i] != max(p[i-1], p[i], p[i+1]))]

print(len(p_con))

Submission status: Accepted

Solution code:
#132_B
n=int(input())
p=list(map(int,input().split()))
s=sum([p[i]<p[i+1]<p[i+2] or p[i]>p[i+1]>p[i+2] for i in range(n-2)])
print(s)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

p_list = [int(s) for s in input().split()]

cnt = 0

for i in range(1,N-1):
  if p_list[i-1] < p_list[i] and p_list[i] < p_list[i+1]:
  	cnt += 1

  if p_list[i+1] < p_list[i] and p_list[i] < p_list[i-1]:
  	cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os, sys, re, math

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

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

print(count)

Submission status: Accepted

Solution code:
n = int(input())
P = [int(s) for s in input().split(' ')]
count = 0
for p0, p1, p2 in zip(P, P[1:], P[2:]):
    if p0 < p1 < p2 or p2 < p1 < p0:
        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, len(l)-1):
    ans += (l[i] != max(l[i-1:i+2]) and l[i] != min(l[i-1:i+2]))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))
i = 1
cnt = 0
while i < len(p) - 1:
  l = sorted([p[i - 1], p[i], p[i + 1]])
  if l[1] == p[i]:
    cnt += 1
  i += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools


def triple(iterable):
    a, b, c = itertools.tee(iterable, 3)
    next(b, None), next(c, None), next(c, None)
    return zip(a, b, c)


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

ans = 0
for x, y, z in triple(P):
    sorted_tuple = sorted([x, y, z])
    if sorted_tuple[1] == y:
        ans += 1
print(ans)

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

Submission status: Accepted

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

ans = 0
for i in range(1, len(P)-1):
    l = sorted([P[i-1], P[i], P[i+1]])
    if l[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):
    arr = [p[i-1], p[i], p[i+1]]
    if p[i] != max(arr) and p[i] != min(arr):
        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] 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())
p = list(map(int, input().split()))
import numpy as np
p = np.array(p)
cnt = 0
for i in range(1, n-1):
    pi = np.array(p[i-1:i+2])
    #print(pi)
    if np.argsort(pi)[1] == 1:
        cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

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

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

    count = 0
    p1 = P[0]
    p2 = P[1]
    for i in range(2, n):
        p3 = P[i]
        if p1 < p2 < p3 or p1 > p2 > p3:
            count += 1
        p1 = p2
        p2 = p3

    print(count)


main()

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  Ps = list(map(int, input().strip().split()))
  print(sum([Ps[i] < Ps[i+1] < Ps[i+2] or Ps[i] > Ps[i+1] > Ps[i+2] for i in range(n-2)]))

if __name__=='__main__':
  main()

Submission status: Accepted

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

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

  if y[1] == p[i]:
    ans +=1
    
print(ans)

Submission status: Accepted

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

for i in range(1, N - 1):
    p = P[i]
    p_s = sorted(P[i - 1 : i + 2])
    if (p == p_s[1]):
        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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]:
        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()))
cnt = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
p = [int(x) for x in input().split()]

ans = 0

for i in range(1,N-1) :
    if p[i-1] > p[i] 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:
# coding: utf-8
# Your code here!

n = int(input())

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

cnt = 0
for i in range(len(P)-2) : 
    if P[i] == min(P[i], P[i+1], P[i+2]) and P[i+2] == max(P[i], P[i+1], P[i+2]) : 
        cnt += 1
    elif P[i] == max(P[i], P[i+1], P[i+2]) and P[i+2] == min(P[i], P[i+1], P[i+2]) : 
        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for i in range(1, n - 1):
    if 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,b=map(int,input().split())
pl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(1,n-1):
    templ=pl[i-1:i+2]
    templ.sort()
    if templ[1]==pl[i]:
        ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

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

count = 0

for i in range(n-2):
    A = t[i:i+3]
    #print(A)
    y = A[1]
    A.sort()

    if y == A[1]:
        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):
  A=L[i:i+3]
  t=A[1]
  A.sort()
  
  ans+=1 if t==A[1] else 0
print(ans)

Submission status: Accepted

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


mi = 0
ma = 0
count = 0

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

print(count)

Submission status: Accepted

Solution code:
import math
#import numpy


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


n = int(input())
p = readints()
#print(p)
sum = 0
for i in range(n-2):
    #print(p[i], end="")
    #print(p[i+1], end="")
    #print(p[i+2], end="")
    if p[i] < p[i+1] < p[i+2] or p[i] > p[i+1] > p[i+2]:
        sum += 1
print(sum)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
p = LIST()

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 = input().split()
ans = 0
for i in range(n-2):
    if int(p[i]) < int(p[i+1]) and int(p[i+1]) < int(p[i+2]):
        ans += 1 
    else:
        if int(p[i]) > int(p[i+1]) and int(p[i+1]) > int(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):
    l = [p[i+j] for j in range(3)]
    s = sorted(l)
    if s[1] == l[1]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc132/tasks/abc132_b

n = int(input())
p = [int(x) for x 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:
import sys

n, *p = map(int, sys.stdin.read().split())

def main():
    cnt = 0
    big = p[1] > p[0]
    for i in range(1, n-1):
        if big:
            cnt += 1 & (p[i] < p[i+1])
        else:
            cnt += 1 & (p[i] > p[i+1])
            
        big = p[i+1] > p[i]

    return cnt

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

	
 
if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
_,p=open(0)
*p,=map(int,p.split())
print(sum(a<b<c or c<b<a for a,b,c in zip(p,p[1:],p[2:])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(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:
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-


def main():
    N = int(input())
    P = list(map(int, input().split()))
    result = 0
    for i in range(N - 2):
        tmp = sorted(P[i:i + 3])
        if tmp[0] < tmp[1] < tmp[2] and tmp[1] == P[i + 1]:
            result += 1
    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from itertools import permutations

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

ans = 0
for j, k in enumerate(p[:-2]):
    a, b, c = k, p[j+1], p[j+2]
    if a < b < c or c < b < a:
        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+2] < 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):
    min_p = min(p[i - 1],p[i],p[i + 1])
    max_p = max(p[i - 1],p[i],p[i + 1])
    if p[i] != min_p and p[i] != max_p:
        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):
    num = [p[i-1],p[i],p[i+1]]
    if p[i] != min(num) and p[i] !=max(num):
        count += 1
print(count)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

num_l = []
for i in range(n-2):
    if pl[i] < pl[i+1] < pl[i+2] or pl[i] > pl[i+1] > pl[i+2]:
        num_l.append(pl[i+1])

print(len(set(num_l)))

Submission status: Accepted

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

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.append(p[i+1])
print(len(set(ans)))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0

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