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: Wrong Answer

Solution code:
k = 0
a = input()

lista = input().split()

for c in range(1, len(lista)-1):

    if lista[c-1] > lista[c] > lista[c+1] or lista[c-1] < lista[c] < lista[c+1]:
        k += 1

print(k)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    input()
    a = list(input().split())
    count = 0
    for i in range(0, len(a) - 2):
        old = a[i:i + 3]
        new = sorted(old)
        if old[1] == new[1]:
            count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [int, input().split()]
cnt = 0

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

Submission status: Wrong Answer

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

# 入力
n = int(input())
p = list(input().replace(" ",""))
# axb

be = int(p[0])
ce = int(p[1])
num = 0

for i in range(2,n):
    p[i] = int(p[i])
    if (be-ce)*(p[i]-ce)<0:
        num += 1

print(str(num))

Submission status: Wrong Answer

Solution code:
def calc(n, p):
    count = 0
    for i, pn in enumerate(p):
        if i == 0 or i == len(p)-1:
            continue
        if pn == sorted([p[i-1], p[i], p[i+1]])[1]:
            count += 1
    return count
print(calc(input(), list(input().split())))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

n = int(input())
p = input().split()

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

    
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0
for i in range(1,len(l)-1):
    l_tmp = [l[i-1], l[i], l[i+1]]
    l_tmp.sort()
    if l_tmp[1]==l[i]:
        cnt += 1
        
print(cnt)

Submission status: Wrong Answer

Solution code:
k = 0
a = input()

lista = input().split()

for c in range(1, len(lista)-1):

    if lista[c-1] > lista[c] > lista[c+1] or lista[c-1] < lista[c] < lista [c+1]:
        k += 1

print(k)

Submission status: Wrong Answer

Solution code:
k = 0
a = input()

lista = input().split()

for c in range(1, len(lista)-1):

    if lista[c-1] > lista[c] > lista[c+1] or lista[c-1] < lista[c] < lista [c+1]:
        k += 1

print(k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

min1 = 20
min2 = 20
for pi in p:
  if min1 > pi:
    min2 = min1
    min1 = pi
print(min2)

Submission status: Wrong Answer

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

a = 0
b = 0
c = 0
cnt = 0

for i in range(n):
	c = pn[i]
	if i >= 2:
		if (a<b and b<c) or (a>b and b>c):
			cnt += 1
		elif (a==b and b<c) or (b==c and b<a):
			cnt += 1

	a = b
	b = c

print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0
a = input()
list1 = list(a.split())

for i in range(1,N-1):
    if list1[i-1] < list1[i] < list1[i+1]:
        count +=1
    elif list1[i+1] < list1[i] < list1[i-1]:
        count +=1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0
for i in range(1,len(l)-1):
    l_tmp = [l[i-1], l[i], l[i+1]]
    l_tmp.sort()
    if l_tmp[1]==l[i]:
        cnt += 1

Submission status: Wrong Answer

Solution code:
n = input()
p = input().split()

cnt=0

for i in range(1,int(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]):
    cnt+=1;
    
print(cnt)

Submission status: Wrong Answer

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

for i in range(1, n-2):
  min = np.min([p[i-1], p[i], p[i+1]])
  max = np.max([p[i-1], p[i], p[i+1]])
  if p[i] != min & p[i] != max:
    count += 1
print(count)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
numbers = [list(map(int, input().split()))]

numbers = numbers[0]
aaa = []
count = 0


for i in range(N-2):
    number_a = int(numbers[i])
    aaa.append(number_a)
    number_b = int(numbers[i+1])
    aaa.append(number_b)
    number_c = int(numbers[i+2])
    aaa.append(number_c)
    if number_b == sorted(aaa)[-2]:
        count += 1
    else:
        continue

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [int, input().split()]
cnt = 0

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = 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: Wrong Answer

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

a = 0
b = 0
c = 0
cnt = 0

for i in range(n):
	c = pn[i]
	if i >= 2:
		if (a<b and b<c) or (a>b and b>c):
			cnt += 1
	a = b
	b = c

print(cnt)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = 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: Wrong Answer

Solution code:
n = int(input())
ls = input().split(" ")
ans = 0

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#print(sorted(p)[1])
p.remove(min(p))
print(min(p))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

def main():
    # # 整数の入力
    # a = int(input())
    # # スペース区切りの整数の入力
    # b, c = map(int, input().split())
    # # 文字列の入力
    # s = input()
    # # 出力
    # print("{} {}".format(a+b+c, s))
    n = int(input())
    p_list = list(map(int, input().split()))
    cnt = 0
    for i in range(1, n-1):
        if min(p_list[i-1:i+2])<p_list[i] and p_list[i]<=max(p_list[i-1:i+2]):
            cnt += 1
        else:
            pass
    print(cnt)



if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [int, input().split()]
cnt = 0

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

Submission status: Wrong Answer

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

print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    n = input()
    ps = input().split(' ')
    count = 0
    for i in range(len(ps) - 2):
        if ps[i] == ps[i + 1]:
            if ps[i + 1] > ps[i + 2]:
                count += 1
        elif ps[i] < ps[i + 1]:
            if ps[i + 1] <= ps[i + 2]:
                count += 1
        elif ps[i] > ps[i + 1]:
            if ps[i + 1] > ps[i + 2]:
                count += 1
    print(str(count))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = [i for i in input().split()][0]
P = [i for i in input().split()]

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

print(count)

Submission status: Wrong Answer

Solution code:
a=[]
i=2
k=0
for x in input():
    a.append(int(x))
for x in input().split(" "):
    a.append(int(x))

while i<=a[0]-1:
    if a[i]>=a[i-1] and a[i]>=a[i+1]:
        k+=0
    elif a[i]<=a[i-1] and a[i]<=a[i+1]:
        k+=0
    else:
        k+=1
    i+=1
print(k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin
import numpy as np

def main():
    #pass
    n = int(stdin.readline().rstrip())
    p = np.array(stdin.readline().rstrip().rsplit())
    #print(n,p_list,type(p_list))
    count=0
    for i in range(n-2):
        #p_list[i+1] p_2
        if p[i+2]<p[i+1]<p[i] or p[i+2]>p[i+1]>p[i]:
            count+=1
        elif p[i+2]==p[i] and p[i]>p[i+1]:
            count+=1
        elif p[i+1]==p[i] and p[i+2]>p[i+1]:
            count+=1
        elif p[i+1]==p[i+2] and p[i]>p[i+1]:
            count+=1
    print(count)
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

print(sorted(p)[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
count = n-4
if p[0]==1 or p[0]==n:
  count+=1
if p[n-1]==1 or p[n-1]==n:
  count+=1
print(max(count,0))

Submission status: Wrong Answer

Solution code:
def check(l):
    a = l[1]
    l.sort()
    if a == l[1] and l.count(a) == 1:
        return True
    else:
        return  False

n = int(input())
p = list(map(lambda x:x,input().split()))
cnt = 0
for i in range(3,n+1):
    if check(p[i-3:i]):
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    n = input()
    ps = input().split(' ')
    count = 0
    for i in range(len(ps) - 2):
        if ps[i] == ps[i + 1]:
            if ps[i + 1] < ps[i + 2]:
                count += 1
        elif ps[i] < ps[i + 1]:
            if ps[i + 1] < ps[i + 2]:
                count += 1
        elif ps[i] > ps[i + 1]:
            if ps[i + 1] >= ps[i + 2]:
                count += 1
    print(str(count))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a=[]
i=2
k=0
for x in input():
    a.append(int(x))
for x in input().split(" "):
    a.append(int(x))

while i<=a[0]-1:
    if a[i]>a[i-1] and a[i]>a[i+1]:
        k+=0
    elif a[i]<a[i-1] and a[i]<a[i+1]:
        k+=0
    else:
        k+=1
    i+=1
print(k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def check(l):
    a = l[1]
    l.sort()
    if a == l[1]:
        return True
    else:
        return  False

n = int(input())
p = list(map(lambda x:x,input().split()))
cnt = 0
for i in range(3,n+1):
    if check(p[i-3:i]):
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    n = input()
    ps = input().split(' ')
    count = 0
    for i in range(len(ps) - 2):
        if ps[i] == ps[i + 1]:
            if ps[i + 1] < ps[i + 2]:
                count += 1
        elif ps[i] < ps[i + 1]:
            if ps[i + 1] < ps[i + 2]:
                count += 1
        elif ps[i] > ps[i + 1]:
            if ps[i + 1] > ps[i + 2]:
                count += 1
    print(str(count))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
count = n-2
if p[0]==1 or p[0]==n:
  count-=1
if p[n-1]==1 or p[n-1]==n:
  count-=1
print(max(count,0))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from sys import stdin
import numpy as np

def main():
    #pass
    n = int(stdin.readline().rstrip())
    p = np.array(stdin.readline().rstrip().rsplit())
    #print(n,p_list,type(p_list))
    count=0
    for i in range(n-2):
        #p_list[i+1] p_2
        if p[i+2]<p[i+1]<p[i] or p[i+2]>p[i+1]>p[i]:
            count+=1
    print(count)
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def main():
	#A, B, Q = map(int, input().split(" "))
	n = int(input())
	p = list(input().split(" "))
	
	ans = 0
	for i, val in enumerate(p):
		if i == 0:
			continue
		if i+1 > n-1:
			continue
		fst = p[i-1]
		snd = p[i]
		srd = p[i+1]
		if snd != max(fst,snd,srd) and snd != min(fst,snd,srd):
			ans += 1
	
	
	print(ans)	
	
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = input().split()
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
huga = input().split()
p = []
for i in range(N):
  p.append(huga[i])
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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
num =set()
for i in range(n-2):
    next = a[i:i+3]
    next.sort()
    num.add(next[1])
print(len(num))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = input()
num = input().split(' ')
count = 0
for i in range(int(N) - 2):
  if (int(num[i]) < int(num[i+1]) and int(num[i+1]) < int(num[i+2])) or (int(num[i+2]) < int(num[i+1]) and int(num[i]) < int(num[i+1])):
      count += 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
raw_input()
s = 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: Wrong Answer

Solution code:
n=int(input())
p=list(map(int,input().split()))
p_2=p[1]
p.sort()
a=p.index(p_2)
print(a)

Submission status: Wrong Answer

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = list(map(int,input().split()))
count = 0
i = 0
while(i < n-2):
  temp = lis[i:i+3]
  if temp[1] == sorted(temp)[1]:
    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] and li[i] < li[i+1]:
        cnt += 1
    elif li[i-1] > li[i] and li[i] > li[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):
    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()))

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

print(answer)

Submission status: Accepted

Solution code:
n = int(input())
data = list(map(int,input().split()))
point = 0
i = 1
while i <= len(data) - 2:
    if data[i-1] < data[i] and data[i] < data[i+1]:
        point += 1
    if data[i - 1] > data[i] and data[i] > data[i + 1]:
        point += 1
    i += 1

print(point)

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

for i in range(n-2):
    if Number[0] > Number[1] > Number[2] or Number[2] > Number[1] > Number[0]:
        count_number += 1
    del Number[0]

print(count_number)

Submission status: Accepted

Solution code:

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

for i in range(0,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()))

cnt = 0
for i in range(1, N - 1):
    l = [P[i - 1], P[i], P[i + 1]]
    l.sort()
    if l[1] == P[i]:
        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(num) for num in input().split()]
count = 0
for i in range(1, n-1):
    if a[i-1] < a[i] and a[i] < a[i+1]:
        count += 1
    elif a[i-1] > a[i] and a[i] > 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):
    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 = [int(i) for i in 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()))
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:
permutation_number = int(input())
permutation = list(map(int, input().split()))
conditional_permutation = 0
for i in range(permutation_number - 2):
    if permutation[i] < permutation[i + 1] < permutation[i + 2] or permutation[i] > permutation[i + 1] > permutation[i + 2]:
        conditional_permutation += 1
print(conditional_permutation)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
P = list(map(int, input().split()))
print(sum(A < B < C or C < B < A for A, B, C in zip(P, P[1:], P[2:])))

Submission status: Accepted

Solution code:
#ABC132 B

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

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 = [int(s) for s in input().split()]
count = 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] :
        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] < 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()))
ans = 0
for i in range(1,n-1):
  pl = [p[i-1],p[i],p[i+1]]
  if p[i] != max(pl) and p[i] != min(pl):
    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):
  ans+=1 if a[i-1]<a[i]<a[i+1] or a[i+1]<a[i]<a[i-1] else 0
  
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l_n = list(map(int, input().split()))
ans_count = 0

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

print(ans_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 min(P[i-1],P[i],P[i+1]) < P[i] and max(P[i-1],P[i],P[i+1]) > P[i]:
        cnt += 1

print(cnt)

Submission status: Accepted

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

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_list.append(i)
print(len(ans_list))

Submission status: Accepted

Solution code:
"""
問題文 { 1 , 2 , . . . , n } の順列 p = { p 1 , p 2 , . . . , p n } があります。
以下の条件を満たすような p i ( 1 < i < n ) がいくつあるかを出力してください。
p i − 1 , p i , p i + 1 の 3 つの数の中で、 p i が 2 番目に小さい。
制約 入力は全て整数である。
3 ≤ n ≤ 20 p は { 1 , 2 , . . . , n } の順列である。
入力 入力は以下の形式で標準入力から与えられる。
n
p 1 p 2 . . . p n
"""

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

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

count = 0
for i in range(1,len(P)-1):
    p_ = [P[i-1], P[i], P[i+1]]
    if (P[i] != min(p_)) and (P[i] != max(p_)):
        count+= 1

print(count)

Submission status: Accepted

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

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()))

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

print(ans)

Submission status: Accepted

Solution code:
from typing import Tuple


def answer(n: int, p: Tuple[int]) -> int:
    count = 0
    for i in range(1, n - 1):
        max_ = max(p[i - 1], p[i + 1])
        min_ = min(p[i - 1], p[i + 1])
        if min_ < p[i] < max_:
            count += 1

    return count


def main():
    n = int(input())
    p = tuple(map(int, input().split()))
    print(answer(n, p))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

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

print(ans)

Submission status: Accepted

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

cnt = 0
for i in range(N - 2):
    if max(n[0 + i], n[1 + i], n[2 + i]) \
            > n[1 + i] \
            > min(n[0 + i], n[1 + i], n[2 + i]):
        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 min(a[i - 1], a[i], a[i + 1]) != a[i] and max(a[i - 1], a[i], a[i + 1]) != a[i]:
        ans += 1
print(ans)