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: Runtime Error

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

n = int(input())
s = [int(c) for c in input()]

count = 0

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

print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
arr = [int(i) for i in input().split(" ")]
l = len(arr)
count = 1
for i in range(0, l-3):
    if arr[i] < arr[i+1] and arr[i*1] < arr[i*2]:
        count += 1
    elif arr[i+2] < arr[i+1] and arr[i*1] < arr[i2]:
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
#b.py
n = int(input())
lis = list(map(int,input()))
ans = 0
for x,y,z in zip(lis,lis[1:],lis[2:]):
    if x < y < z:
        ans += 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
arr = [int(i) for i in input().split(" ")]
l = len(arr)
count = 1
for i in range(0, l-3):
    if arr[i] < arr[i+1] and arr[i*1] < arr[i*2]:
        count += 1

print(count)

Submission status: Runtime Error

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

def check_order(p, q, r):
    if p < q < r or p > q > r:
        return True
    return Flase

counter = 0 
for i in range(1, len(p_lst)-1):
    if check_order(p_lst[i-1], p_lst[i], p_lst[i+1]):
        counter += 1

print(counter)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
p = input().split(" ")
a = 0
for i in range(len(n)):
    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
print(a)

Submission status: Runtime Error

Solution code:
n = int(input())
p = input().split(" ")
a = 0
for i in range(len(n)):
    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
print(a)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
na = int(input())
count = 0

n = map(int, input().split(" "))

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
res = 0
p = [*map(int, input().split())]
res = sum(1 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])
print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
struct revran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { --i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr revran(const i64 e) noexcept: b(0), e(e) {}
  constexpr revran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(e - 1); }
  constexpr iter end() const noexcept { return iter(b - 1); }
};

struct ran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { ++i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr ran(const i64 e) noexcept: b(0), e(e) {}
  constexpr ran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(b); }
  constexpr iter end() const noexcept { return iter(e); }
  constexpr revran rev() const noexcept { return revran(b, e); }
};

constexpr ran rin(const i64 e) noexcept { return ran(1, e + 1); }
constexpr ran rin(const i64 b, const i64 e) noexcept { return ran(b, e + 1); }

int main() {
  i64 n;
  cin >> n;
  vector<i64> p(n);
  for(int i = 0;i < n;i++) cin >> p[i];
  i64 cnt = 0;
  for(int i = 1;i < n - 1;i++) {
    if(p[i - 1] < p[i] && p[i] < p[i + 1]) {
      cnt++;
    }
    if(p[i - 1] > p[i] && p[i] > p[i + 1]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}