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:
def calc(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
            continue
        if p[i-1] > p[i] and p[i] > p[i+1]:
            count += 1
            continue
    return count
print(calc(int(input()), list(input().split())))

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
        if p[i-1] < pn and pn < p[i+1]:
            count += 1
            continue
        if p[i-1] > pn and pn > p[i+1]:
            count += 1
            continue

    return count
print(calc(input(), list(input().split())))

Submission status: Wrong Answer

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

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()
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())
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<=c or c<b<=a:
			cnt += 1
	a = b
	b = c

print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 29 22:38:02 2019

@author: daif
"""
def second_smallest(numbers):
    m1, m2 = float('inf'), float('inf')
    for x in numbers:
        if x <= m1:
            m1, m2 = x, m1
        elif x < m2:
            m2 = x
    return m2

n = int(input())
numbers = input()

numbers = [int(x)  for x in numbers.split()]

smallest = set()
for i in range(len(numbers)):
    if (i + 2) >= len(numbers):
        break
    
    min_number = second_smallest([numbers[i], numbers[i+1], numbers[i+2]])
    if not(min_number in smallest):
        smallest.add(min_number)
        
print(len(smallest))

Submission status: Wrong Answer

Solution code:
def second_smallest(numbers):
    m1, m2 = float('inf'), float('inf')
    for x in numbers:
        if x <= m1:
            m1, m2 = x, m1
        elif x < m2:
            m2 = x
    return m2

n = int(input())
numbers = input()

numbers = [int(x)  for x in numbers.split()]

print(numbers)
smallest = set()
for i in range(len(numbers)):
    if (i + 2) >= len(numbers):
        break
    
    min_number = second_smallest([numbers[i], numbers[i+1], numbers[i+2]])
    if not(min_number in smallest):
        smallest.add(min_number)
        
print(len(smallest))

Submission status: Wrong Answer

Solution code:
_,p=open(0);*p,=map(int,p.split());print(sum(a<b<c for a,b,c in zip(p,p[1:],p[2:])))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
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:
# coding: utf-8
# Your code here!
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
    print(count)
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
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:
long = int(input())
p = input()
plng = []
pstr = p.split(" ")
n = 0

for i in range(long):
    plng.append(int(pstr[i]))


for i in range(long-2):
    three = [plng[i-1],plng[i],plng[i+1]]
    three.sort()

    if three[1] == plng[i]:
     n = n + 1

print(n)

Submission status: Wrong Answer

Solution code:
n = input()
nums = input().split(' ')
print(nums)
nums = [int(num) for num in nums]
cnt=0

for i in range(1,len(nums)-1):
  
  print(nums[i-1], nums[i], nums[i+1])
  if nums[i-1] < nums[i] and nums[i] < nums[i+1]:
    cnt += 1
    print('OK')
  if nums[i+1] < nums[i] and nums[i] < nums[i-1]:
    cnt += 1
    print('OK')
      
print(cnt)

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) or (a==b and b>c) or (b==c and b>a)or(a==c and b>a):
			cnt += 1
	a = b
	b = c

print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import numpy as np
n = int(input())
p= input().split()
c = 0
for i in range(1, n-1):
    if int(p[i]) == int(np.sort(p[i-1:i+2])[1]) and int(p[i]) != int(np.sort(p[i-1:i+2])[0]):
        c +=1
    else:
        pass
print(c)

Submission status: Wrong Answer

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

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

print(count)

Submission status: 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) or (a==b and b>c) or (b==a and b>c)or(a==c and b>a):
			cnt += 1
	a = b
	b = c

print(cnt)

Submission status: Wrong Answer

Solution code:
long = int(input())
p = input()
plng = []
pstr = p.split(" ")
n = 0

for i in range(long):
    plng.append(int(pstr[i]))

print(plng)

for i in range(long-2):
    three = [plng[i],plng[i+1],plng[i+2]]
    three.sort()

    if three[1] == plng[i + 1]:
     n = n +1

print(n)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    ans = []
    p = list(map(int,input().split()))
    cnt = 1

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

    print(cnt)



main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    ans = []
    p = list(map(int,input().split()))
    cnt = 0

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

    print(cnt)



main()

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int,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(p[i:i+3],sorted_p)

print(count)

Submission status: Wrong Answer

Solution code:
count=0

su_list = input().split()
for i  in range(0,len(su_list)-1):
    if su_list[i-1]<= su_list[i] and su_list[i] < su_list[i+1] or su_list[i-1] > su_list[i] and su_list[i]>=su_list[i+1]:
        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 not ((a<b and c<b) or (a>b and c>b)):
			cnt += 1
	a = b
	b = c

print(cnt)

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 not (a<b and c<b) or (a>b and c>b):
			cnt += 1
	a = b
	b = c

print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    n = int(input())

    p = [int(x) for x in stdin.readline().split()]
    count = 0

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = input()
nums = input().split(' ')

cnt=0

for i in range(1,len(nums)-1):
  if nums[i-1] < nums[i] and nums[i] < nums[i+1]:
    cnt += 1  
  if nums[i+1] < nums[i] and nums[i] < nums[i-1]:
    cnt += 1
      
print(cnt)

Submission status: Wrong Answer

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


n=int(n)

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




print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import numpy as np
n = int(input())
p= input().split()
c = 0
for i in range(1, n-1):
    if int(p[i])== int(np.sort(p[i-1:i+2])[1]):
        c +=1
    else:
        pass
print(c)

Submission status: Wrong Answer

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

cnt=0

for i in range(1,len(nums)-1):
  if nums[i-1] == nums[i] and nums[i+1] < nums[i]:
    cnt += 1
  elif nums[i+1] == nums[i] and nums[i-1] < nums[i]:
    cnt += 1  
  elif nums[i-1] < nums[i] and nums[i] < nums[i+1]:
    cnt += 1  
  elif nums[i+1] < nums[i] and nums[i] < nums[i-1]:
    cnt += 1
      
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
P = input().split()
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
if P[0]>P[1] :
    count+=1
if P[-1]>P[-2] :
    count+=1
print(count)

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
    q = sorted([p[i-1], p[i], p[i+1]], reverse=True)  # 降順にソート→先頭２要素のみで比較
    if p[i] == q[1]:
        # print(p[i-1], p[i], p[i+1])
        counter +=1
    else:
        pass
    
print(counter)

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(list3)
print(len(set(list3)))

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(list3)
print(len(set(list3)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
P = input().split()
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
if P[-1]<P[-2] :
    count+=1
print(count)

Submission status: Wrong Answer

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


n = int(n)

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


   
  
print(cnt)

Submission status: Wrong Answer

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

cnt=0

for i in range(1,len(nums)-1):
  if nums[i-1] == nums[i]:
    if nums[i+1] < nums[i]:
      cnt += 1
  if nums[i+1] == nums[i]:
    if nums[i-1] < nums[i]:
      cnt += 1
  if nums[i-1] < nums[i]:
    if nums[i] < nums[i+1]:
      cnt+=1      
  if nums[i+1] < nums[i]:
    if nums[i] < nums[i-1]:
      cnt+=1
      
print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


n = int(n)

cnt=0

for i in range(1,n-1):
  print(i)
  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:

#{1, 2, ..., n} の順列 p = {p1,p2, ..., pn } があります。
#以下の条件を満たすような pi (1<i<n) がいくつあるかを出力してください。
#pi−1, pi, pi+1 の 3 つの数の中で、pi が 2 番目に小さい。

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

    else:
        ans==ans
print(ans)

Submission status: Wrong Answer

Solution code:
count=0

su_list = input().split()
for i  in range(1,len(su_list)-1):
    if su_list[i-1]<= su_list[i] and su_list[i] < su_list[i+1] or su_list[i-1] > su_list[i] and su_list[i]>=su_list[i+1]:
        count += 1
print(count)

Submission status: Wrong Answer

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

cnt=0

for i in range(1,len(nums)-1):
  if nums[i-1] < nums[i]:
    if nums[i] <= nums[i+1]:
      cnt+=1
  if nums[i+1] < nums[i]:
    if nums[i] <= nums[i-1]:
      cnt+=1
      
print(cnt)

Submission status: Wrong Answer

Solution code:
#{1, 2, ..., n} の順列 p = {p1,p2, ..., pn } があります。
#以下の条件を満たすような pi (1<i<n) がいくつあるかを出力してください。
#pi−1, pi, pi+1 の 3 つの数の中で、pi が 2 番目に小さい。

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

    else:
        ans==ans
print(ans)

Submission status: Wrong Answer

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


n = int(n)

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


    
if(p[0] > p[1]):
  cnt+=1

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

Submission status: Wrong Answer

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

cnt=0

for i in range(1,len(nums)-1):
  if nums[i-1] < nums[i]:
    if nums[i] < nums[i+1]:
      cnt+=1
  if nums[i+1] < nums[i]:
    if nums[i] < nums[i-1]:
      cnt+=1
      
print(cnt)

Submission status: Wrong Answer

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

cnt=0

for i in range(1,len(nums)-1):
  if nums[i-1] < nums[i]:
    if nums[i] < nums[i+1]:
      cnt+=1
  elif nums[i+1] < nums[i]:
    if nums[i] < nums[i-1]:
      cnt+=1
      
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0

for num in range(0, n-2):
  print(num)
  if A[num+1] > A[num] and A[num+1] < A[num+2]:
    cnt += 1
    print(num+1, num, num+2)
  elif A[num+1] < A[num] and A[num+1] > A[num+2]:
    cnt +=1

print(cnt)

Submission status: Wrong Answer

Solution code:
z = input()
k = z.split(" ")
k1 = k[1:len(k)]
count = 0
for kk in range(1,(len(k1)-1)):
    k2 = k1[kk-1:kk+2]    
    if( (max(k2) != k1[kk]) & (min(k2) != k1[kk])):        
        count = count + 1     
print(count)

Submission status: Wrong Answer

Solution code:
count=0

su_list = input().split()
for i  in range(1,len(su_list)-1):
    if su_list[i-1]< su_list[i] and su_list[i] < su_list[i+1] or su_list[i-1] > su_list[i] and su_list[i]>su_list[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(1,N-1):
    if P[n-1] < P[n] < P[n+1]:
        cnt+=1
    elif P[n-1] > P[n] > P[n+1]:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
cnt = 0
for i in range(len(A)):
    if i >1 and i < N-1:
        if (A[i] >A[i-1] and A[1]< A[i+1]) or (A[i] <A[i-1] and A[1] >A[i+1]):
            cnt+=1
        else:
            i+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
P = input().split()
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
print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
P = input().split()
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
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0

for num in range(0, n-2):
  print(num)
  if A[num+1] > A[num] and A[num+1] < A[num+2]:
    cnt += 1
  elif A[num+1] < A[num] and A[num+1] > A[num+2]:
    cnt +=1

print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    n = int(input())

    p = stdin.readline().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)


if __name__ == "__main__":
    main()

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-1]<p[i]<p[i+1]) or  (p[i-1]>p[i]>p[i+1]):
    c=c+1

print(c)

Submission status: Wrong Answer

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

collect = 0
for i in range(n - 2):
    p_small = p[i: i + 3]
    p_min = min(p_small)
    p_max = max(p_small)
    pi = p_small[1]
    
    if pi > p_min and pi <= p_max:
        collect += 1
        
print(collect)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import os, sys, re, math

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

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

Submission status: Wrong Answer

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

i = 1
c = 0
for i in range((int(p)-1)):
  s1 = n[i-1]
  s2 = n[i]
  s3 = n[i+1]
  if s1 < s2 and s2 < s3:
    c += 1
  if s1 > s2 and s2 > s3:
    c += 1
print(c)

Submission status: Wrong Answer

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

count=0
for i in range(1,c-1):
  tree= [b[i-1], b[i], b[i+1]]
  if (min(tree) != b[i]) and (max(tree) != b[i]):

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

Submission status: Wrong Answer

Solution code:
#{1, 2, ..., n} の順列 p = {p1,p2, ..., pn } があります。
#以下の条件を満たすような pi (1<i<n) がいくつあるかを出力してください。
#pi−1, pi, pi+1 の 3 つの数の中で、pi が 2 番目に小さい。

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

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
        pCount = 0
        if pn < p[i-1]:
            pCount += 1
        if pn < p[i+1]:
            pCount += 1
        if pCount == 1 or (pn < p[i-1] and p[i-1] == p[i+1]):
            count += 1
    return count
print(calc(input(), list(input().split())))

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from operator import itemgetter, attrgetter
n=0
 
n = input()
d_list= list(map(int, input().split()))
cnt=0
for i in range(1,len(d_list)-1):
    print(d_list[i])
    b=d_list[i-1]
    m=d_list[i]
    a=d_list[i+1]
    if (b< m <a) or (a< m< b):
        cnt+=1
        
    
print(cnt)

Submission status: Wrong Answer

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

collect = 0
for i in range(n - 2):
    p_small = p[i: i + 2]
    p_min = min(p_small)
    p_max = max(p_small)
    pi = p_small[1]
    
    if pi > p_min and pi < p_max:
        collect += 1
        
print(collect)

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 a[0] != a[1] and a[1] != a[2] and a[0] != a[2]:
      if p[i] == a[1]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    n = int(input())

    p = stdin.readline().split()
    count = 0

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


if __name__ == "__main__":
    main()

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

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] and p[i+1]<p[i-1]) or (p[i]<p[i+1] and p[i]>p[i-1] and p[i+1]>p[i-1]) ):
        count +=1
    elif(p[i-1]==p[i+1] and p[i]<p[i-1]):
        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):
    next = a[i:i+3]
    next.sort()
    num.add(next[1])
if a[0] in num:
    num.remove(a[0])
if a[-1] in num:
    num.remove(a[-1])
print(len(num))

Submission status: Wrong Answer

Solution code:

n = int(input())
p = input().split()
count = 0
for i in range(n-2):
    l = [p[i], p[i+1], p[i+2]]
    l2 = sorted(l)

    # print(l)
    # print(l2)
    if l2[1] == p[i+1]:
        count += 1

print(count)

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
        pCount = 0
        if pn < p[i-1]:
            pCount += 1
        if pn < p[i+1]:
            pCount += 1
        if pCount == 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()))

collect = 0
for i in range(n - 2):
    p_small = p[i: i + 2]
    p_min = min(p_small)
    p_max = max(p_small)
    pi = p_small[1]
    
    if pi > p_min and pi <= p_max:
        collect += 1
        
print(collect)

Submission status: Wrong Answer

Solution code:
n=input()
S=list(input().split())
for i in S:
    i=int(i)
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 = 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]:
    count += 1
  else:
    pass
  
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:
    a = p[i-1:i+2]
    a.sort()
    if a[0] != a[1] and a[1] != a[2]:
      if p[i] == a[1]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
numbers = [int(n) for n in 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()
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
  elif 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:
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]:
        cnt += 1
    elif 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()))
count = 0
for i in range(n-2):
  if p[i] < p[i+1] < p[i+2]:
    count += 1
  else:
    pass

Submission status: Wrong Answer

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

cnt = 0
l_ext = []

for i in range(n-2):
  l_ext.clear()
  l_ext.append(l[i])
  l_ext.append(l[i+1])
  l_ext.append(l[i+2])
  if not l_ext.index(max(l_ext)) and not l_ext.index(min(l_ext)):
    cnt += 1
  i += 1

print(cnt)

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

Submission status: Wrong Answer

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

count=0
for i in range(c-1):
  if (b[i-1] < b[i]) and (b[i] < b[i+1]):
    count=count+1
  else:
    next
    
print(count)

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 = 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:
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+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 = input().split()
count = 0
for i in range(n-2):
    l = [p[i], p[i+1], p[i+2]]
    l2 = sorted(l)

    # print(l)
    # print(l2)
    if l2[1] == l[1]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:

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

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