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())
S = list(map(int,input().split()))
cnt = 0
for i in range(1,n-1,1):
    temp = [S[i-1],S[i],S[i+1]]
    temp.sort()
    #print(temp)
    if temp[1] == S[i]:
        cnt += 1
print(cnt)

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

Submission status: Accepted

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

ans = 0
for i in range(n-2):
    Lbc = L[i:i+3]
    Lbs = sorted(Lbc)
    if Lbc[1] == Lbs[1]:
        ans += 1
    else:
        pass
print(ans)

Submission status: Accepted

Solution code:
import sys

def main():
    n = int(sys.stdin.readline().strip())
    p = [int(i) for i in sys.stdin.readline().strip().split()]
    ret = 0
    for i in range(n - 2):
        s = p[i:i+3]
        ss = sorted(s)
        if ss[1] == s[1]:
            ret += 1
    return ret
    
print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# INF = float('inf')
# N = int(input())
# A = [int(x) for x in input().split()]
# A = [int(input()) for _ in range(N)]
# dp = [[0] * 100 for _ in range(100)]
# dp = defaultdict(lambda: float('inf'))
# print('hoge', file=sys.stderr)


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

cnt = 0
for i in range(n - 2):
    L = [p[i], p[i + 1], p[i + 2]]
    L.sort()
    # print("{},{}".format(i,i + 2))
    if p[i + 1] == L[1]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
from statistics import median

n = int(input())
p =  [int(i) for i in input().split(" ")]
count = 0

for i in range(1, n-1) :
    if p[i] == median([p[i-1], p[i], p[i+1]]) :
        count+=1
print(count)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-2):
    if max(p[i], p[i+1], p[i+2]) != p[i+1] and min(p[i], p[i+1], p[i+2]) != 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):
    pi, pj, pk = p[i], p[i+1], p[i+2]
    pmax = max(pi, pj, pk)
    pmin = min(pi, pj, pk)
    if pj != pmax and pj != pmin:
        ans += 1

print(ans)

Submission status: Accepted

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

cnt = 0

for i in range(n-2):
    if ps[i] < ps[i+1] and ps[i+2] < ps[i+1]:
        continue
    if ps[i] > ps[i+1] and ps[i+2] > ps[i+1]:
        continue
    cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

    cnt = 0

    for i in range(1, n-1):

        if li_p[i-1] < li_p[i] & li_p[i] < li_p[i+1]:
            cnt += 1

        elif li_p[i-1] > li_p[i] & li_p[i] > li_p[i+1]:
            cnt += 1

    print(cnt)
    
resolve()

Submission status: Accepted

Solution code:
def main():
	import sys
	input = sys.stdin.readline
	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+1] <= p[i+2])) | ((p[i] >= p[i+1]) & (p[i+1] >= p[i+2])):
			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(n - 2):
    a = []
    a.append(p[i])
    a.append(p[i + 1])
    a.append(p[i + 2])
    a.sort()
    if p[i + 1] == a[1]:
        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(n-2):
    a,b,c = p[i],p[i+1],p[i+2]
    if (a > b and b > c) or (a < b and b < c):
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
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())
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()))
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:
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


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

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

    print(count)


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):
    a, b, c = p[i], p[i + 1], p[i + 2]
    s = sorted([a, b, c])
    if s[1] == 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(len(p)-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:
N = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(N-3+1):
    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:
n = int(input())
dat = list(map(int, input().split()))

cnt = 0

for i in range(1, n-1):
  sub = dat[i-1:i+2]
  # print(sub, max(sub), min(sub))
  if max(sub) != sub[1] and min(sub) != sub[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):
  tmp = [p[i-1], p[i], p[i+1]]
  if min(tmp) != p[i] and max(tmp) != p[i]:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

count = 0
for i in range(1, n-1):
    if sorted([ps[i-1], ps[i], ps[i+1]])[1] == ps[i]:
        count +=1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(n: int, p: "List[int]"):
    count = 0
    for i in range(n - 2):
        arr = sorted([p[i], p[i+1], p[i+2]])
        if arr[1] == p[i+1]:
            count += 1
    return count


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    p = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    print(solve(n, p))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def read_input():
    n = int(input())
    plist = list(map(int, input().split()))

    return plist


def submit():
    plist = read_input()

    count = 0
    for p1, p2, p3 in zip(plist, plist[1:], plist[2:]):
        if p1 < p2 < p3:
            count += 1
        elif p3 < p2 < p1:
            count += 1

    print(count)
    return


if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(1, n - 1):
    if p[i] < max(p[i - 1], p[i + 1]) and p[i] >= min(p[i - 1], p[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(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 = [int(_) for _ in 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 c > b > a:
        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 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())

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

cnt = 0
for i in range(1, n - 1):
    sub_i = p[i-1:i+2]
    if sorted(sub_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, n-1):
    pp = p[i-1: i+2]
    #print(pp)
    pp.sort()
    if p[i] == pp[1]:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n - 2):
    if min(P[i], P[i + 2]) <= P[i + 1] <= max(P[i], P[i + 2]):
        ans += 1

print(ans)

Submission status: Accepted

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

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

c = 0
for a in range(n-2) :
    if plist[a] < plist[a+1] < plist[a+2] :
        c+=1
    elif plist[a] > plist[a+1] > plist[a+2] :
        c+=1
print(c)

Submission status: Accepted

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

def seccheck(i):
    if p[i-1]<p[i]<p[i+1] or p[i-1]>p[i]>p[i+1]:
        return True
    else:
        return False

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

print(count)

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int,input().split()))
c = 0

for i in range(a-2):
  if b[i]<b[i+1]<b[i+2] or b[i+2]<b[i+1]<b[i]:
    c+=1
else:
  print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ps = [int(elem) for elem in input().split()]

cnt = 0
for a, b, c in zip(ps[:-2], ps[1:-1], ps[2:]):
    lst = sorted([a, b, c])
    if lst[1] == b:
        cnt += 1
    else:
        pass
print(cnt)

Submission status: Accepted

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

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

cnt = 0
for i in range(1, n-1):
    if (P[i-1] - P[i]) * (P[i+1] - P[i]) < 0:
        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 collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n = II()
p = LI()
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()))

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

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
ans = 0
for a in range(1, N - 1):
    b = arr[a - 1 : a + 2]
    b.sort()
    if arr[a] == b[1]:
        ans += 1
print(ans)

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

ans = 0

for i in range(len(P) - 2):
    if sorted(P[i:i+3])[1] == P[i+1]:
        ans += 1


print(ans)

Submission status: Accepted

Solution code:
n = input()

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

for i in range(int(n)-2):
    if (p[i] < p[i+1] and p[i+1] < p[i+2]) or (p[i+2] < p[i+1] and p[i+1] < p[i]):
        counter += 1

print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    n = II()
    p = LI()

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

    print(counter)


main()

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

for i in range(N-2):
  pThree = [p[i],p[i+1],p[i+2]]
  pn = sorted(pThree)
  if pn[1] == p[i+1]:
    num += 1
  
print(num)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    ps = list(map(int, input().split(" ")))
    cnt = 0
    for i in range(1, N-1):
        if (ps[i-1] < ps[i] and ps[i] < ps[i+1]) or (ps[i-1] > ps[i] and ps[i] > ps[i+1]):
            cnt += 1
    print(cnt)
    
if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
import copy


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

    ans = 0
    ans += np.sum(np.logical_and(p_arr[1:-1]
                                 > p_arr[:-2], p_arr[1:-1] < p_arr[2:]))
    ans += np.sum(np.logical_and(p_arr[1:-1]
                                 < p_arr[:-2], p_arr[1:-1] > p_arr[2:]))
    print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0
for i in range(len(p)-2):
    tmp = [p[i], p[i+1], p[i+2]]
    tmp.sort()
    if tmp[1] == p[i+1]:
        count += 1

print(str(count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
Ps =  list(map(int,input().split(" ")))
ans = 0
for i in range(0,n-2):
    a,b,c = Ps[i:i+3]
    temp = Ps[i:i+3]
    temp.sort()
    if temp[1] == b:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:


def solve():
    n = int(input())
    P = [int(i) for i in input().split()]
    count = 0
    for i in range(1, n - 1):
        PP = [P[i - 1], P[i], P[i + 1]]
        PP.sort()
        if P[i] == PP[1] and PP[1] != PP[2]:
            count += 1
    print(count)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
p = [int(x) for x 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("{}".format(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def solv(n, p):
    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
    return count


if __name__ == '__main__':

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

    ans = solv(n, p)

    print(ans)

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

count = 0
for i in range(n-2):
    p0 = p_list[i]
    p1 = p_list[i+1]
    p2 = p_list[i+2]
    if (p0 < p1 and p1 < p2) or (p0 > p1 and p1 > p2):
        count += 1

print (count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

n = int(stdin.readline().rstrip())
p = list(map(int, stdin.readline().rstrip().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()))

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

Submission status: Accepted

Solution code:
n = int(input())
pn = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
  p1, p2, p3 = pn[i:i+3]
  if p1 < p2 and p2 < p3:
    cnt += 1
  elif p3 < p2 and p2 < p1:
    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 sorted(P[i-1:i+2])[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):
    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 = [int(i) for i in input().split()]

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

print(count)

Submission status: Accepted

Solution code:
n = int(input())
p = input().split(" ")
p = [int(i) for i in p]
c = 0
for i in range(n - 2):
    n1 = p[i]
    n2 = p[i+1]
    n3 = p[i+2]
    #print(n1,n2,n3)
    if (n2 > n1 and n2 < n3) or (n2 < n1 and n2 > n3):
        c += 1
print(c)

Submission status: Accepted

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


c = 0
for i in range(1, N-1):
    com = sorted([p[i-1], p[i], p[i+1]])
    if com[1] == p[i]:
        c += 1

print(c)

Submission status: Accepted

Solution code:
n = int(input())
P = [int(s) for s in input().split()]
count = 0
for i in range(n-2):
  tmp = []
  
  tmp.append(P[i])
  tmp.append(P[i+1])
  tmp.append(P[i+2])
  
  if (tmp[1] < tmp[2] and tmp[0] < tmp[1]) or (tmp[0] > tmp[1] and tmp[2] < tmp[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):
    pp = p[i-1:i+2]
    mid = pp[1]
    pp.sort()
    if mid == pp[1]: cnt += 1

print(cnt)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

count = 0
for i in range(n-2):
    l = p[i:i+3]
    two = l[1]
    l.sort()
    if l[1] == two :
        count += 1
print(count)

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

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] and a[i]<a[i+1]:
    ans+=1
  elif a[i-1]>a[i] and a[i]>a[i+1]:
    ans+=1
  else:
    pass
  
print(ans)

Submission status: Accepted

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

count = 0
for i in range(1, n - 1):
  if p[i] > p[i - 1] and p[i] < 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 = [int(v) for v in 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()))

counter = 0
for i in range(1, n-1):
    buff = []
    buff = P[i-1:i+2]
    buff.sort()
    if P[i] == buff[1]:
        counter += 1


print(counter)

Submission status: Accepted

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

while i!=n-1:
    d=[s[i-1],s[i],s[i+1]]
    d.sort()
    if d[1]==s[i]:
        ans+=1
    i+=1
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    n = int(input())
    P = [int(c) for c in input().split()]
    num = 0
    for i in range(1, n - 1):
        lists = [P[i - 1], P[i], P[i + 1]]
        max_ = max(lists)
        min_ = min(lists)
        if (P[i] != max_ and P[i] != min_):
            num += 1
    print(num)


if __name__ == '__main__':
    main()