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:
n = int(input())
p = input().split()
ans = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(1,int(n)-1):
  if p[i-1] < p[i] <p[i+1]:
    counter = counter +1
  elif p[i-1] > p[i] >p [i+1]:
    counter = counter +1

print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

result = 0

if n >= "3":
	number_list = []

	for i in numbers:
		number_list.append(i)
		if len(number_list) < 3:
			continue
		elif len(number_list) > 3:
			number_list.pop(0)

		sorted_list = sorted(number_list)
		# print(sorted_list, number_list)
		if sorted_list[1] == number_list[1]:
			result += 1

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

result = 0

if n >= "3":
	number_list = []

	for i in numbers:
		number_list.append(i)
		if len(number_list) < 3:
			continue
		elif len(number_list) > 3:
			number_list.pop(0)

		sorted_list = sorted(number_list)
		print(sorted_list, number_list)
		if sorted_list[1] == number_list[1]:
			result += 1

print(result)

Submission status: Wrong Answer

Solution code:
import os, sys, re, math

N = int(input())
s = input().split(' ')

cnt = 0
for i in range(N-2):
    temp = s[i:i+3]
    temp.sort()
    if temp[1] == s[i+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] ) or (p[i-1] >= p[i] and p[i] > p[i+1]) or (p[i-1] == p[i+1]) and (p[i] > p[i-1]) ):
        cnt += 1

    
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

i = 1
i0 = i -1
i1 = i + 1
c = 0
for i in range(1, n):
    if (p[i] >= p[i0]) & (p[i] < p[i1]):
        c += 1
    elif (p[i] < p[i0]) & (p[i] >= p[i1]):
        c += 1
    else:
        c += 0    
print(c)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from heapq import nsmallest

n = int(stdin.readline())
p = [int(x) for x in stdin.readline().rstrip().split()]

# [heapq — Heap queue algorithm — Python 3\.7\.4rc1 documentation](https://docs.python.org/3/library/heapq.html#heapq.nsmallest)

cnt = 0

for i in range(len(p)):
    if i == 0 or i == n:
        continue
    if nsmallest(2, p[i-1:i+2])[-1] == p[i]:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
pp = list(map(int,input().split()))
three = [pp[0],pp[1],pp[2]]
cou = 0
th = 0

for i in range(n-2):
    th = three[1]
    three.sort()
    if three[1] == th:
        cou += 1
    three[0] = pp[i]
    three[1] = pp[i+1]
    three[2] = pp[i+2]
print(cou)

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 = map(int, input().split())
p = list(p)
n = len(p)
n = n - 1

i = 1
i0 = i -1
i1 = i + 1
c = 0
for i in range(1, n):
    if (p[i] > p[i0]) & (p[i] < p[i1]):
        c += 1
    elif (p[i] < p[i0]) & (p[i] > p[i1]):
        c += 1
    else:
        c += 0    
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import os, sys, re, math

N = int(input())
s = input().split(' ')

cnt = 0
for i in range(N-2):
    if s[i] < s[i+1] and s[i+1] < s[i+2]:
        cnt += 1
    elif s[i+2] < s[i+1] and s[i+1] < s[i]:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())  #入力回数を決める
p = [int(x) for x in input().split()]

counter = 0

for i in range(n):

    if i == n - 1:
        continue
    if p[i - 1] <= p[i] < p[i + 1] or p[i - 1] > p[i] >= p[i + 1]:
        # print(p[i-1], p[i], p[i+1])
        counter += 1
    else:
        pass

print(counter)

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
p=input().split(' ')
list=[]

list3=[]
for i in p:
  list.append(int(i))
for i in range(2,n):
  list2=[]
  list2.append(list[i-2])
  list2.append(list[i-1])
  list2.append(list[i])
  list2.sort()
  list3.append(list2[1])
print(len(set(list3)))

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
def calc(n, p):
    count = 0
    for i, pn in enumerate(p):
        if i == 0 or i == len(p)-1:
            continue
        sortedPn = sorted(collections.Counter([p[i-1], p[i], p[i+1]]))

        if len(sortedPn) != 1 and pn == sortedPn[1]:
            count += 1
    return count
print(calc(input(), list(input().split())))

Submission status: Wrong Answer

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

for i in range(len(p)-1):
  if i != 0:
    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: 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(1,n-1):
        #print(p[i])
        #p_list[i+1] p_2
        if p[i-1]<p[i]<p[i+1]:
            count+=1
        if p[i-1]>p[i]>p[i+1]:
            count+=1
        if p[i-1]==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(input().split())

count=0
for i in range(n-2):
    sorted_p=sorted(p[i:i+3])
    if p[i+1]==sorted_p[1]:
        count+=1

print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
pp = list(map(int,input().split())) + ['']*2
three = [pp[0],pp[1],pp[2]]
cou = 0
th = 0

for i in range(n):
    if i > n-3:
        break
    th = three[1]
    three.sort()
    if three[1] == th:
        cou += 1
    three[0] = pp[i]
    three[1] = pp[i+1]
    three[2] = pp[i+2]
print(cou)

Submission status: Wrong Answer

Solution code:
# ordinary number
n = int(input())
list = [int(i) for i in input().split(' ')]
print(n,list)
ans = 0
for i in range(1,n-1):
	tmp = list[i-1:i+2]
	tmp.sort()
	print(tmp)
	if tmp[0] != list[i] and  tmp[1] == list[i]:
		ans = ans + 1
print(ans)

Submission status: Wrong Answer

Solution code:

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

count = 0

for i in range(n-2):
    num_id = i+1
    temp = [num_list[num_id-1], num_list[num_id], num_list[num_id+1]]
    list_sorted = sorted(temp, reverse=True)
    print(temp)
    if list_sorted[1] == num_list[num_id]:
        count += 1


print(count)

Submission status: Wrong Answer

Solution code:
p = list(map(int,input().split()))
res = 0
for i, num in enumerate(p):
	if(1 <= i and i <= (len(p) - 2)):
		li = [p[i-1],p[i],p[i + 1]]
		li.sort()
		if((p[i-1] != p[i + 1]) and (p[i-1] != p[i]) and (p[i] != p[i + 1]) and (li[1] == p[i])):
			res = res + 1
print(res)

Submission status: Wrong Answer

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

result = 0

number_list = []

for i in numbers:
	number_list.append(i)
	if len(number_list) < 3:
		continue
	elif len(number_list) > 3:
		number_list.pop(0)

	sorted_list = sorted(number_list)
	# print(sorted_list, number_list)
	if sorted_list[1] == number_list[1]:
		result += 1

print(result)

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(1,n-1):
        #print(p[i])
        #p_list[i+1] p_2
        if p[i-1]<p[i]<p[i+1]:
            count+=1
        if p[i-1]>p[i]>p[i+1]:
            count+=1
        if p[i-1]<p[i]==p[i+1]:
            count+=1
        if p[i-1]==p[i]>p[i+1]:
            count+=1
        if p[i-1]==p[i+1]<p[i]:
            count+=1
        if p[i-1]==p[i]==p[i+1]:
            count+=1
    print(count)
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

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

	a = b
	b = c

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
num =set()
for i in range(n-2):
    # print(a[i+1])
    if a[i]<a[+1] and a[i+1]<a[i+2] and (1<a[i+1]<n):
        num.add(a[i+1])
    elif a[i]>a[+1] and a[i+1]>a[i+2] and (1<a[i+1]<n):
        num.add(a[i + 1])
print(len(num))

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(1,n-1):
        #print(p[i])
        #p_list[i+1] p_2
        if p[i-1]<p[i]<p[i+1]:
            count+=1
        if p[i-1]>p[i]>p[i+1]:
            count+=1
        if p[i-1]<p[i]==p[i+1]:
            count+=1
        if p[i-1]==p[i]>p[i+1]:
            count+=1
        if p[i-1]==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(input().split())
cnt=0
for i in range(1,n-1):
    tmp=[]
    key=p[i]
    a=p[i-1]
    b=p[i]
    c=p[i+1]
    tmp.append(a)
    tmp.append(b)
    tmp.append(c)
    tmp=list(set(tmp))
    tmp.sort(reverse=True)
    
    if tmp[1]==key:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=input()
s=input()
s=s.replace(" ","")
a=0
for i in range(2,int(n)):
  if s[i-2]<s[i-1] and s[i-1]<s[i]:
    a=a+1
  if s[i-2]>s[i-1] and s[i-1]>s[i]:
    a=a+1
print(a)

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

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

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

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

	a = b
	b = c

print(cnt)

Submission status: Wrong Answer

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

count=0
for i in range(n-2):
    sorted_p=sorted(p[i:i+3])
    if p[i+1]==sorted_p[1]:
        count+=1
        print(sorted_p)

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

Submission status: Wrong Answer

Solution code:
import collections
def calc(n, p):
    count = 0
    for i, pn in enumerate(p):
        if i == 0 or i == len(p)-1:
            continue
        sortedPn = sorted([p[i-1], p[i], p[i+1]])

        if len(collections.Counter(sortedPn)) != 1 and pn == sortedPn[1]:
            count += 1
    return count
print(calc(input(), list(input().split())))

Submission status: Wrong Answer

Solution code:
n=int(input())
str=input()
p=str.split(" ")
count=0

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

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
pp = input().split(" ")

count = 0

i = 1
while i < N - 1:
    if pp[i - 1] < pp[i] < pp[i + 1] or pp[i - 1] > pp[i] > pp[i + 1]:
        count += 1
    i += 1

print(count)

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 = input().split()
ans = 0

for i in range(len(p)-1):
  if i != 0:
    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: 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(1,n-1):
        #print(p[i])
        #p_list[i+1] p_2
        if p[i-1]<p[i]:
            if p[i]<p[i+1] or p[i]==p[i+1] or p[i-1]==p[i+1]:
                count+=1
        if p[i-1]==p[i]:
            if p[i]>p[i+1]:
                count+=1
        if p[i-1]>p[i]:
            if p[i]>p[i+1]:
                count+=1
    print(count)
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

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

count = 0

for i in range(n-2):
    num_id = i+1
    temp = [num_list[num_id-1], num_list[num_id], num_list[num_id+1]]
    list_sorted = sorted(temp)
    print(temp)
    if max(temp) != num_list[num_id] and (min(temp) != num_list[num_id]):
        count += 1


print(count)

Submission status: Wrong Answer

Solution code:
size=input()
P=input()

p=P.split(" ")

counter=0
for i in range(1,len(p)-1):
    if(p[i-1]<p[i] and p[i]<p[i+1]):
        counter+=1
    elif(p[i-1]>p[i] and p[i]>p[i+1]):
        counter+=1
    elif(p[i-1]==p[i] and p[i]<p[i+1]):
        counter+=1
    elif(p[i+1]==p[i] and p[i]<p[i-1]):
        counter+=1
    elif(p[i+1]==p[i-1] and p[i]<p[i+1]):
        counter+=1
print(counter)

Submission status: Wrong Answer

Solution code:
input_num = int(input())

input_line = input().split(" ")
count = 0

# 入力された数-2回試行する
for i in range(0, input_num - 2):
	temp_array = []
	temp_array.append(input_line[i])
	temp_array.append(input_line[i+1])
	temp_array.append(input_line[i+2])
	temp_array.sort()
	if int(temp_array[1]) == int(input_line[i+1]):
		count += 1 
print(count)

Submission status: Wrong Answer

Solution code:
# B - Ordinary Number

def main():
	n = int(input())
	p = list(map(int,input().split()))
	count = 0
	for i in range(1, n-1):
		if check(p, i):
			count += 1
	print(count)

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

main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

counter = 0

for i in range(n):

    if i == n -1:
        continue
    elif p[i - 1] < p[i] < p[i + 1] or p[i - 1] > p[i] > p[i + 1]:
        counter += 1
    else:
        pass

print(counter)

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;

if (p[0] < p[1]):
  cnt+=1
if p[int(n)-1] < p[int(n)-2]:
  cnt+=1
  
print(cnt)

Submission status: Wrong Answer

Solution code:
p = list(map(int,input().split()))
res = 0
for i, num in enumerate(p):
	if(1 <= i and i <= (len(p) - 1)):
		li = [p[i-1],p[i],p[i + 1]]
		li.sort()
		if((p[i-1] != p[i]) and (p[i] != p[i + 1]) and (li[1] == p[i])):
			res = res + 1
print(res)

Submission status: Wrong Answer

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

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

print(l)

Submission status: Wrong Answer

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

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()
    if next[1]>1 and next[1]<n:
        num.add(next[1])
print(len(num))

Submission status: Wrong Answer

Solution code:
p = list(map(int,input().split()))
res = 0
for i, num in enumerate(p):
	if(1 <= i and i <= (len(p) - 2)):
		li = [p[i-1],p[i],p[i + 1]]
		li.sort()
		if((p[i-1] != p[i]) and (p[i] != p[i + 1]) and (li[1] == p[i])):
			res = res + 1
print(res)

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:
if __name__ == '__main__':
    input()
    a = list(map(int, input().split()))
    count = 0
    for i in range(0, len(a) - 2):
        old = a[i:i + 3]
        new = sorted(old)
        print(old, new, old[1], new[1])
        if old[1] == new[1]:
            count += 1
    print(count)

Submission status: Wrong Answer

Solution code:

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

count = 0

for i in range(n-2):
    num_id = i+1
    temp = [num_list[num_id-1], num_list[num_id], num_list[num_id+1]]
    list_sorted = sorted(temp)
    print(num_list[num_id])
    print(temp)
    if list_sorted[1] == num_list[num_id]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

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()
    arr_tmp = np.array(l_tmp)
    if len(arr_tmp[arr_tmp>l[i]])==1:
        cnt += 1
        
print(cnt)

Submission status: Wrong Answer

Solution code:
size=input()
P=input()

p=P.split(" ")

counter=0
for i in range(1,len(p)-1):
    if(p[i-1]<p[i] and p[i]<p[i+1]):
        counter+=1
    elif(p[i-1]>p[i] and p[i]>p[i+1]):
        counter+=1
print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split())) 
cnt = 0
for i in range(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
    else:
        cnt =cnt
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(1,n-1):
        #print(p[i])
        #p_list[i+1] p_2
        if p[i-1]<p[i]:
            if p[i]<p[i+1] or p[i]==p[i+1] or p[i-1]==p[i+1]:
                count+=1
        elif p[i-1]==p[i]:
            if p[i]>p[i+1]:
                count+=1
        else:
            if p[i]>p[i+1]:
                count+=1
    print(count)
    return

if __name__ == "__main__":
    main()

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-1):
  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-1)

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:
import collections

n = int(input())
p = list(map(int, input().split()))
count2 = []
for i in range(1, n-1):
    count = []
    count.append(p[i-1])
    count.append(p[i])
    count.append(p[i+1])
    count.sort()
    count2.append(count[1])
ans = collections.Counter(count2)
print(len(ans))

Submission status: Wrong Answer

Solution code:
N = input()
P = list(input().split())
count = 0

for i in range(len(P)-2) :
	judge_list = list() 
	midle = P[i+1]
	judge_list.extend([P[i],P[i+1],P[i+2]])
	judge_list.sort()

	if midle == judge_list[1]:
		count+=1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(input().split())
cnt=0
print(p)
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:
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(1,n-1):
        #print(p[i])
        #p_list[i+1] p_2
        if p[i-1]<p[i]:
            if p[i]<p[i+1] or p[i]==p[i+1]:
                count+=1
        elif p[i-1]==p[i]:
            if p[i]>p[i+1]:
                count+=1
        else:
            if p[i]>p[i+1] or p[i-1]==p[i+1]:
                count+=1
    print(count)
    return

if __name__ == "__main__":
    main()

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
    elif be - ce ==0 and p[i]>ce:
        num += 1

    elif be - ce ==0 and p[i]>ce:
        num += 1


print(str(num))

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

count = 1

for i in range(n-2):
    num_id = i+1
    temp = [num_list[num_id-1], num_list[num_id], num_list[num_id+1]]
    list_sorted = sorted(temp)

    if list_sorted[1] == num_list[1]:
        count += 1

print(count)

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())
nump = input().split()
nump = [int(i) for i in nump]
print(nump)

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

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-1):
	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())
lst = [int, input().split()]
cnt = 0

#print(lst[1][1])

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] or lst[1][i] == lst[1][i+2] > lst[1][i+1]:
    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 min2 > pi:
        min2 = pi
        if min1 > min2:
            tmp = min2
            min2 = min1
            min1 = tmp
print(min2)

Submission status: Wrong Answer

Solution code:
def secc(a,b,c):
    k =[]
    k.append(a)
    k.append(b)
    k.append(c)
    k.sort()
    if(k[1]==b):
        return True
    else:
        return False
n = int(input())
a = list(map(int,input().split()))
c =0 
for i in range(2,n-1):
    if(secc(a[i-1],a[i],a[i+1])):
        c+=1 
print(c+1)

Submission status: Wrong Answer

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

count=0
for i in range(n-1):
    sorted_p=sorted(p[i:i+3])
    if p[i+1]==sorted_p[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(n-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:
p = list(map(int,input().split()))
res = 0
for i, num in enumerate(p):
	if(len(p) < 3):
		break
	if(1 <= i and i <= (len(p) - 2)):
		li = [p[i-1],p[i],p[i + 1]]
		li.sort()
	if(li[1] == p[i]):
		res = res + 1
print(res)

Submission status: Wrong Answer

Solution code:

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

count = 1

for i in range(n-2):
    num_id = i+1
    temp = [num_list[num_id-1], num_list[num_id], num_list[num_id+1]]
    list_sorted = sorted(temp)

    if list_sorted[1] == num_list[num_id]:
        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[2]:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

# main
n = int(input())
array_p = [int(i) for i in input().split(' ')]

def is_second(input_list):
    print(input_list)
    sort = sorted(input_list)
    print(sort)
    if input_list[1] == sort[1]:
        return True
    else:
        return False

count = 0
for i in range(1, n - 1):
    if is_second(array_p[i - 1 : i + 2]):
        count += 1

print(count)

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=min(lst)
  P=p[i+1]
  del m
  if min(lst)==P:
    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(1,n-1):
        #print(p[i])
        #p_list[i+1] p_2
        if p[i-1]<p[i]:
            if p[i]<p[i+1] or p[i]==p[i+1]:
                count+=1
        elif p[i-1]==p[i]:
            if p[i]>p[i+1]:
                count+=1
        else:
            if p[i]>p[i+1]:
                count+=1
    print(count)
    return

if __name__ == "__main__":
    main()

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 = 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 len(list(set(l_tmp)))==3:
        if l_tmp[1]==l[i]:
            cnt += 1
        
print(cnt)