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:
# coding: utf-8
import time
import re
import math
import fractions

def main():
    global N,A,B,C,D,memo,mx,mn,temp
    N=int(input())
    P=list(map(int,input().split()))
    count=0
    for a in range(1,N-1):
        lst=[P[a-1],P[a],P[a+1]]
        lst.sort()
        if lst[2]==lst[1]:
            if lst[0]==P[a]:
                count+=1
        elif lst[0]==lst[1]:
            if not lst[2]==P[a]:
                count+=1
        else:
            if lst[1]==P[a]:
                count+=1
    print(count)


start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global N,A,B,C,D,memo,mx,mn,temp

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ps = [int(p) for p in input().split(" ")]
ans = 0
for i in range(n-2):
  if ps[i] < ps[i+1] < ps[i+2]:
     ans += 1
  elif ps[i+2] < ps[i+1] < ps[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):
  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:
if __name__ == '__main__':
    n = int(input())
    p_list = list(map(int, input().split()))

    answer = 0
    for i in range(1,len(p_list)-1):
        p1 = p_list[i-1]
        p2 = p_list[i]
        p3 = p_list[i+1]

        tmp_p_list = [p1, p2, p3]
        tmp_p_list = sorted(tmp_p_list)

        if tmp_p_list[1] == p2:
            answer += 1
    print(answer)

Submission status: Accepted

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

ans = 0

for i in range(1,n-1) :
    s = p[i-1:i+2]

    s.sort()

    if s[1] == p[i] :
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
N = int(input()) # 数字を変数に格納
List = list(map(int,input().split())) # 複数の数字をリストに格納

count = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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


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


if __name__ == '__main__':
    inputs = read()
    print('%d' % solve(*inputs))

Submission status: Accepted

Solution code:
import sys

def solve(n, p):
    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

    return count


if __name__ == '__main__':

    n = sys.stdin.readline().strip()
    p = map(int, sys.stdin.readline().strip().split(" "))
    print solve(int(n), p)

Submission status: Accepted

Solution code:
import sys

cin = sys.stdin
N = int(cin.readline())
p = list(map(int, cin.readline().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()))
lists = []
for i in range(1,len(p)-1):
    if p[i-1] < p[i] < p[i+1]:
        lists.append(p[i])
    elif p[i-1] > p[i] > p[i+1]:
        lists.append(p[i])
print(len(lists))

Submission status: Accepted

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

# 連続する3つの数の中で2番目の数が2番目に小さいような部分がいくつあるか？

counter = 0
for i in range(1, n - 1):
    # 値で降順ソートして2番目ならカウンター増やす
    d = {"i-1": nums[i - 1], "i": nums[i], "i+1": nums[i + 1]}
    sorted_d = sorted(d.items(), key=lambda x: x[1], reverse=True)
    if sorted_d[1][0] == "i":
        counter += 1
print(counter)

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]:
    c += 1
  elif p[i] > p[i+1] > p[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(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(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:
n = input()
plst = list(map(int, input().split()))

anscnt = 0
for i in range(1, len(plst) - 1):
    if plst[i - 1] < plst[i] and plst[i] < plst[i + 1]:
        anscnt += 1
    elif plst[i + 1] < plst[i] and plst[i] < plst[i - 1]:
        anscnt += 1

print(anscnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def input_from_console():
    n = int(input())
    p_list= list(map(int, input().strip().split()))
    return n, p_list


def solve(n, p_list):
    result = 0
    if n <= 2:
        return result
    for i in range(n - 2):
        if min(p_list[i], p_list[i+2]) < p_list[i+1] and max(p_list[i], p_list[i+2]) > p_list[i+1]:
            result += 1
    return result


def main():
    n, p_list = input_from_console()
    print(solve(n, p_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

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

Submission status: Accepted

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

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

count = 0

for i in range(n-2):
  list = [p[i],p[i+1],p[i+2]]
  sort_list = [p[i],p[i+1],p[i+2]]
  sort_list.sort()
  if sort_list[1] == list[1]:
    count = count +1
print(count)

Submission status: Accepted

Solution code:
n = int(input())

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

def f(a, b, c):
    if a < b and b < c:
        return True
    if c < b and b < a:
        return True
    return False


ans = 0
for i in range(len(p) - 2):
    if f(p[i], p[i+1], p[i+2]):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
count = 0

for i in range(1,N-1):
    if arr[i] > arr[i-1] and arr[i] > arr[i+1]:
        continue
    if arr[i] < arr[i-1] and arr[i] < arr[i+1]:
        continue
    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):
    p_ = sorted(p[i-1:i+2])
    if p_[1] == p[i]:
        count += 1
print(count)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

print(Nres)

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

print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N = int(input())
p = list(map(int,input().split()))
idx = 3
cnt = 0
while idx<=N:   
    tmp = p[idx-3:idx]
    tmps = sorted(tmp)
    if tmp[1] == tmps[1]:
        cnt += 1
    idx += 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):
    if min(p[i-1:i+2])!=p[i] and max(p[i-1:i+2])!=p[i]:
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = p[:3]
ans = 0
for i in range(n-2):

    if s[1]>min(s) and s[1]<max(s):
        ans += 1
    if i == n-3:
        break
    s = s[1:]+[p[i+3]]
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 max(p[i-1],p[i],p[i+1])!=p[i] and min(p[i-1],p[i],p[i+1])!=p[i]:
        ans+=1
print(ans)

Submission status: Accepted

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

print(num)

Submission status: Accepted

Solution code:

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


n=int(input())
p=acinput()

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

Submission status: Accepted

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

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

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] < 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())
num_list=[int(x) for x in stdin.readline().rstrip().split()]
output=0
for n in range(N-2):
    if (num_list[n]-num_list[n+1])*(num_list[n+2]-num_list[n+1])<0:
        output+=1

print(output)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

ans = 0
for i in range(len(p)-2):
    p1 = p[i]
    p2 = p[i+1]
    p3 = p[i+2]
    if p1 < p2 and p2 < p3:
        ans += 1
    elif p3 < p2 and p2 < p1:
        ans += 1

print(ans)

Submission status: Accepted

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

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

print(counter)

Submission status: Accepted

Solution code:
n = int(input())
ppp = list(map(int, input().split()))
ans = 0
for p, q, r in zip(ppp, ppp[1:], ppp[2:]):
    if sorted([p, q, r])[1] == q:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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 permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


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

def main():
    n=INT()
    p_lis=LIST()
    ct=0
    for i in range(1,n-1):
        if p_lis[i]>p_lis[i-1] and p_lis[i]<p_lis[i+1]:
            ct+=1
        elif p_lis[i]<p_lis[i-1] and p_lis[i]>p_lis[i+1]:
            ct+=1

    print(ct)



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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
P = input()
P = P.split(' ')

count = 0
for i in range(1, n-1):
    p_1 = int(P[i-1])
    p_2 = int(P[i])
    p_3 = int(P[i+1])
    
    p_list = np.argsort([p_1, p_2, p_3])
    if p_list[1] == 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]:
    ans += 1
  if p[i+1] < p[i] < p[i-1]:
    ans += 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

cnt = 0
for i in range(1, n, 1):
    pi = ps[i]
    if pi != max(ps[i-1:i+2]) and pi != min(ps[i-1:i+2]):
        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]<p[i+2] or p[i+2]<p[i+1]<p[i]:
        count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
p_s = [int(v) for v in input().split()]

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

Submission status: Accepted

Solution code:
#ABC132 = 2*2*3*11
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]:
        ans += 0
    elif min(p[i-1],p[i],p[i+1]) == p[i]:
        ans += 0
    else:
        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 = list(map(int, input().split()))
cnt = 0
for i in range(n - 2):
    a = list()
    a.append(p[i])
    a.append(p[i + 1])
    a.append(p[i + 2])
    check = p[i + 1]
    a.sort()
    if check == a[1]:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().strip().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())
pi = list(map(int, input().split()))

#print(pi)

ans=0
for i in range(n-2):
    if (pi[i+2] < pi[i+1] and pi[i+1] <= pi[i]) or (pi[i] < pi[i+1] and pi[i+1] <= pi[i+2]):
        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):
    j = max(0, i - 1)
    k = min(n - 1, i + 1)
    b = a[j:k+1]
    b.sort()
    ans += b[1] == a[i]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = [int(num) for num in input().split()]

count = 0

for i in range(len(l)-2) :
    part = l[i:i+3]
    part.sort(reverse=False)
    if (part.index(l[i+1]) == 1) :
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

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


count = 0

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

print(count)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
input = stdin.readline().split()
mem = 0
cnt = 0
for i in range(N):
    if i == 0:
        continue
    if i == N-1:
        continue
    if int(input[i]) > int(input[i-1]) and int(input[i+1]) > int(input[i]):
        # print(input[i])
        cnt += 1
    if int(input[i]) < int(input[i-1]) and int(input[i+1]) < int(input[i]):
        # print(input[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(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:
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(len(p)-2):
    x = p[i:i+3]
    x1 = sorted(x)
    if x[1] == x1[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, len(p) - 1):
    if (p[i-1] < p[i] and p[i] < p[i+1]) or (p[i-1] > p[i] and p[i] > p[i+1]):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
p = tuple(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())
p=list(map(int,input().split()))

cnt =0
l=[]

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

print(cnt)

Submission status: Accepted

Solution code:
# B - Ordinary Number

N = int(input().rstrip())
p_s = input().split()
p = [int(s) for s in p_s]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for idx,val in enumerate(p):
    if idx == 0:
        continue
    elif idx == n - 1:
        break
    if val < max(p[idx - 1], p[idx + 1]) and val > min(p[idx - 1], p[idx + 1]):
        cnt += 1

print(cnt)

Submission status: Accepted

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

ans = 0
A = [0,0,0]
for i in range(1, n-1):
    A = [P[i-1],P[i],P[i+1]]
    A.sort()
    if A[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):
    x = [ p[i-1], p[i], p[i+1] ]
    x.sort()
    if x[1] == p[i]:
        cnt +=1

print(cnt)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

c = 0

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

ct = 0
for j in range(len(p)-2):
  if (p[j]<p[j+1] and p[j+1]<p[j+2])or(p[j]>p[j+1] and p[j+1]>p[j+2]):
    ct += 1
    
print(ct)

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-1] < P[i] < P[i+1] or 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()))
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()))

ans = 0
for i in range(1, len(p) - 1):
    setv = p[(i - 1) : (i + 2)]
    setv_mid = setv[1]
    if sorted(setv)[1] == setv_mid:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
for i in range(1, n-1):
    i_and_neighbours = [ps[i-1], ps[i], ps[i+1]]
    if ps[i] != max(i_and_neighbours) and ps[i] != min(i_and_neighbours):
        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] < p[i+2] or p[i+2] < p[i+1] < p[i]:
        count+=1
print(count)

Submission status: Accepted

Solution code:
#while True:     
#  try:         
#    listC.append(list(map(int,input().split())))
#  except:         
#    break; 
#x,y = map(int,input().split())
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+2] > p[i+1]):
    count += 1
  elif (p[i+1] < p[i]) and (p[i+2] < 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):
    p = P[i:i+3]
    p_min = min(p)
    p_max = max(p)
    if p[1] != p_min and p[1] != p_max:
        ans += 1

print(ans)

Submission status: Accepted

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: Accepted

Solution code:
n = input()
lst = [int(x) for x in input().split()]
ret = 0
for idx, n in enumerate(lst[0:-2]):
    a, b, c = lst[idx], lst[idx + 1], lst[idx + 2]
    if b != min(a, b, c) and b != max(a, b, c):
        ret += 1
print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)