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

for i in range(1, n-1):
    temp = p[i]
    array = [p[i-1], p[i], p[i+1]]
    array.sort()

    if temp == array[1]:
        count += 1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
p = input().split(" ")
a = 0
for i in range(len(p)):
    try:
        pf = p[i]
        ps = p[i+1]
        pt = p[i+2]
        il = [int(pf),int(ps),int(pt)]
        max_p = max(il)
        il.remove(max_p)
        if int(ps) == max(il):
            a += 1
    except:
        pass
print(a)

Submission status: Accepted

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


main()

Submission status: Accepted

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


for i in range(n-2):
  p_3=p[i:i+3]
  if p_3[1]-p_3[0]>0:
    if p_3[2]-p_3[1]>0:
      count+=1
      
  elif p_3[1]-p_3[0]<0:
    if p_3[2]-p_3[1]<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):
    a1 = p[i-1]
    a2 = p[i]
    a3 = p[i+1]
    if (a1<=a2)and(a2<=a3):
        count += 1
    elif (a3<=a2)and(a2<=a1):
        count += 1
print(count)

Submission status: Accepted

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n= int(sys.stdin.readline())
    p_l= list(map(int, sys.stdin.readline().split()))
    c=0
    for i in range(1,n-1):
        if p_l[i-1]<p_l[i]<p_l[i+1] or p_l[i-1]>p_l[i]>p_l[i+1]:
            c+=1
    print(c)

Submission status: Accepted

Solution code:
n = int(input())

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

cnt = 0
for i in range(1,n-1):
    # インデックス参照で順番に見ていって、現在の数がそのとおりであればcnt += 1する
    num = p[i]
    pre_num = p[i-1]
    next_num = p[i+1]
    numbers = sorted([num, pre_num, next_num])

    if numbers[1] == num:
        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+1] != max(p[i:i+3]) and p[i+1] != min(p[i:i+3]):
        count += 1

print(count)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n-2):
  maximum=max(p[i],p[i+1],p[i+2])
  minimum=min(p[i],p[i+1],p[i+2])
  sumation=p[i]+p[i+1]+p[i+2]
  if p[i+1]==sumation-maximum-minimum:
    count=count+1
    
print(count)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

n = int(input().strip())
ps = list(map(int, input().strip().split(' ')))
count = 0
for i in range(n - 2):
    sub = ps[i: i + 3]
    sub.sort()
    if sub[1] == ps[i + 1]:
        count += 1
print(count)

Submission status: Accepted

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

count = 0
for i in range(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=input().split()
for i in range(n):
    p[i]=int(p[i])

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

print(a)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

a, b = P[:2]
count = 0
for c in P[2:]:
    if sorted([a, b, c])[1] == b:
        count += 1
    a, b = b, c

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

Submission status: Accepted

Solution code:
a=input()
a=int(a)
b=input().split()
b=[int(i) for i in b]
ans=0
of=0
for i in b:
  if of>=2:
    if b[of-2]>b[of-1]>i or b[of-2]<b[of-1]<i:
      ans+=1
  of+=1
print(ans)

Submission status: Accepted

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

for i in range(2, n):
    p1 = i - 2
    p2 = i - 1
    p3 = i
    if p[p1] <= p[p2] <= p[p3] or p[p1] >= p[p2] >= p[p3]:
        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):
    ans += 1 if p[i] == sorted([p[i-1],p[i],p[i+1]])[1] else 0

print(ans)

Submission status: Accepted

Solution code:
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
p = inl()
sum = 0
for i in range(n-2):
    a = p[i]
    b = p[i+1]
    c = p[i+2]
    if a<b and c>=b or c<b and a>=b:
        sum += 1
print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0
for idx in range(1,len(p)-1):
    if (p[idx]-p[idx-1])*(p[idx]-p[idx+1])<0:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

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

result = 0
for i in range(1, n-1):
    #print(lst[i -1], lst[i], lst[i + 1], " " ,end="")
    j = (lst[i - 1] < lst[i] and lst[i] < lst[i + 1]) or (lst[i - 1] > lst[i] and lst[i] > lst[i + 1]) 
    #print(j)
    if j:
        result += 1


print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


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

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

    print(c)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
p = list(map(int, input().split()))

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

    x = 0
    for i in range(1, N-1):
        a, b, c = P[i-1], P[i], P[i+1]
        if a < b and b < c or a > b and b > c:
            x += 1

    print(x)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

count = 0
for pm, pi, pp in zip(pn, pn[1:], pn[2:]):
    if pm < pi < pp or pm > pi > pp:
        count += 1

print(count)

Submission status: Accepted

Solution code:
# coding:utf-8


def main():
    N = int(input())
    # N, M = map(int, input().split())
    A = list(map(int, input().split()))
    # print(A)
    ans = 0

    for i in range(1, N-1):
        if A[i] > A[i-1] and A[i] < A[i+1]:
            # print(i)
            ans += 1
        elif A[i] < A[i-1] and A[i] > A[i+1]:
            # print(i)
            ans += 1
        elif A[i] == A[i-1] and A[i] < A[i+1]:
            # print(i)
            ans += 1
        elif A[i] == A[i+1] and A[i] < A[i-1]:
            # print(i)
            ans += 1
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
n = int(input())
pls = list(map(int,input().split()))
ans = 0
for r in range(1,n-1): 
    mls = [pls[r-1],pls[r],pls[r+1]]
    mls.sort()
    if mls[1] == pls[r]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import fractions

#inp = [int(i) for i in input().split()]
inp_ = int(input())

co =0
inp = [int(i) for i in input().split()]

for i in range(len(inp)-2):
    d = []
    d.append(inp[i])
    d.append(inp[i+1])
    d.append(inp[i+2])

    d.sort()

    n = d.index(inp[i+1])

    if n == 1:
        co += 1



print(co)

Submission status: Accepted

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

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

if __name__ == '__main__':
    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-1] < P[i] and P[i] < P[i+1]:
        c += 1
    if 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()))
c = 0
for i in range(n-2):
    if (p[i+1] < p[i]) and (p[i+1] > p[i+2]):
        c += 1
    elif (p[i+1] > p[i]) and (p[i+1] < p[i+2]):
        c += 1

print(c)

Submission status: Accepted

Solution code:
import sys
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
    elif p[i] > p[i+1] and p[i+1] > p[i+2]:
        count += 1

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
n = int(input())
P = list(map(int, input().split()))

cnt = 0
for i, p in enumerate(P[:n-2]):
    if P[i+1] == sorted([p, P[i+1], P[i+2]])[1]:
        cnt += 1

print(cnt)

Submission status: Accepted

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
raw_input()
s = map(int, raw_input().split())

c = 0
for i in range(1, len(s) - 1):
    if s[i-1] <= s[i] <= s[i+1] or s[i+1] <= s[i] <= s[i-1]:
        c += 1

print c

Submission status: Accepted

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

ans = 0
for i in range(1, n-1):
    a = P[i-1]
    b = P[i]
    c = P[i+1]
    if a < b < c:
        ans += 1
    elif a > b > c:
        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]:
        ans=ans+1
    elif p[i+1]<p[i]<p[i-1]:
        ans=ans+1

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())						# 5
p =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

ans=0
for i in range(n-2):
	a = p[i]
	b = p[i+1]
	c = p[i+2]
	
	if (a<b)and(b<c): ans+=1
	if (a>b)and(b>c): 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] or p[i] < p[i-1] and p[i] > p[i+1]:
        ans += 1
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

cnt = 0
for i in range(1,n-1):
    if (xs[i-1] < xs[i]) ^ (xs[i] > xs[i+1]):
        cnt += 1

print(cnt)

Submission status: Accepted

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

count=0
for i in range(len(A)-2):
    tmp=sorted(A[i:i+3])
    if tmp[1]==A[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):
    b = [p[i],p[i+1],p[i+2]]
    if p[i+1]!=max(b) and p[i+1]!=min(b):
        ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

c = 0

for i in range(n-2):
    if sorted(l[i:i+3])[-2] == l[i+1]:
        c += 1

print(c)

Submission status: Accepted

Solution code:

#N,X= map(int,input().split())

N = int(input())
p_list = list(map(int,input().split()))
cnt = 0
for i in range(1,N-1):
    p = p_list[i-1:i+2]
    p_s =p_list[i-1:i+2]
    p_s.sort()
    if p[1] == p_s[1]:
        cnt += 1
print(cnt)
#print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n - 2):
    s = sorted([(p[i + j], j) for j in range(3)])
    ans += (s[1][1] == 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):
    tmp = [A[i-1], A[i], A[i+1]]
    if min(tmp) != A[i] and max(tmp) != A[i]:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0

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

print(count)

Submission status: Accepted

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

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8



def main():
    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)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(1, N-1):
    if p[i-1] > p[i] 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:
def solve():
  N = int(input())
  P = [int(i) for i in input().split()]
  ans = 0
  for i in range(N - 2):
    maxP = max(P[i], P[i + 2])
    minP = min(P[i], P[i + 2])
    if minP < P[i + 1] and P[i + 1] < maxP: ans += 1
  return ans

print(solve())

Submission status: Accepted

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

cnt = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())  
p = np.array(input().split(), dtype=np.int64)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = int(input())
l = list(int(x) for x in input().split())
count = 0
for i in range(1,s-1):
  if (l[i-1] < l[i] and l[i] < l[i+1]) or (l[i-1] > l[i] and l[i] > l[i+1]):
    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] 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())) 

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

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
P=LIST()

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

Submission status: Accepted

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

c = 0
for i in range(1, n-1):
  if sorted([ns[i-1], ns[i], ns[i+1]])[1] == ns[i]:
    c += 1
    
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

n_satisfy_cond = 0
for i in range(1, n - 1):
    p_im1 = ppp[i - 1]
    p_i = ppp[i]
    p_ip1 = ppp[i + 1]
    if p_im1 < p_i < p_ip1:
        n_satisfy_cond += 1
    elif p_ip1 < p_i < p_im1:
        n_satisfy_cond += 1

print(n_satisfy_cond)

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:
from sys import stdin
n = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
for i in range(0,n-2):
    #print(data[i:i+3])
    if sorted(data[i:i+3])[1] == data[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):
  ps = [p[i-1],p[i],p[i+1]]
  if sorted(ps)[1] == p[i]:
    c += 1
print(c)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(n-2):
  target = p[i:i+3]
  target_s = sorted(target)
  if  target_s[1]== target[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):
    t = p[i: i + 3]
    t.sort()
    if t.index(p[i + 1]) == 1:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ps = LI()
    ans = 0
    for i in range(n-2):
        sr = sorted(ps[i:i+3])
        if sr[1] == ps[i+1]:
            ans += 1
    print(ans)




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):
    if i == 0:
        continue
    if i == n - 1:
        break
    if p[i-1] <= p[i] and p[i] <= p[i+1] or p[i+1] <= p[i] and p[i] <= p[i-1]:
        cnt+=1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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