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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#ABC132 B

n = int(input())
P = list(map(int,input().split()))
K = 0
for i in range(n-2):
    T = [P[i], P[i+1], P[i+2]]
    T.sort()
    if T[2] == P[i+1]:
        K += 1
        
print(K)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
list.sort(A)
print(A[1])

Submission status: Wrong Answer

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


print(ct)

Submission status: Wrong Answer

Solution code:
N = int(input())
N_List = sorted(list(map(int,input().split())))
ct = 0
for i in range(1,N-1):
    if (N_List[i] >= N_List[i-1]) & (N_List[i] <= N_List[i+1]):
        ct += 1

print(ct)

Submission status: Wrong Answer

Solution code:
N = int(input())
N_List = sorted(list(map(int,input().split())))
ct = 0
for i in range(1,N-1):
    if (N_List[i] > N_List[i-1]) & (N_List[i] < N_List[i+1]):
        ct += 1

print(ct)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
*p,=map(int,input().split())
c=0
for i in range(n-1):
    c+=sorted(p[i:i+3])[1]==p[i+1]
print(c)

Submission status: Wrong Answer

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

Submission status: 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=ans+1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

for i in range(N-2):
  if P[i] > P[i+1] and P[i+1] > P[i+2]:
    ans += 1

print(ans)

Submission status: Wrong Answer

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

for i in range(1, len(ps)-1):
    if ps[i] == min(ps[i-1], ps[i], ps[i+1]):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# Vicfred
# https://atcoder.jp/contests/abc132/tasks/abc132_b
# implementation
n = int(input())
p = list(map(int,input().split()))

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

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
li = rl()
cnt = 0
for i in range(1, n-1):
  if li[i-1] <= li[i] <= li[i+1]:
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
li = rl()
cnt = 0
for i in range(1, n-1):
  if li[i-1] < li[i] < li[i+1]:
    cnt += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
list=input().split()
for f in list:
    f=float(f)
def sec(a, b, c):
    l=[a, b, c]
    l.sort()
    return l[1]
count=1
c=0
for i in range(n-2):
    if sec(list[count], list[count+1], list[count-1])==list[count]:
        c=c+1
    count=count+1
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
list=input().split()
for f in list:
    f=float(f)
def sec(a, b, c):
    l=[a, b, c]
    xxx=min(l)
    xx=max(l)
    l.remove(xx)
    l.remove(xxx)
    return l[0]
count=1
c=0
for i in range(n-2):
    if sec(list[count], list[count+1], list[count-1])==list[count]:
        c=c+1
    count=count+1
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
list=input().split()
for f in list:
    f=float(f)
count=1
c=0
for i in range(n-2):
    if list[count]<list[count+1] and list[count]>list[count-1]:
        c=c+1
    elif list[count]>list[count+1] and list[count]<list[count-1]:
        c=c+1
    count=count+1
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(1,n - 1):
    if p[i - 1] < p[i] and p[i] < p[i + 1]:
        c = c + 1

print(c)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

count = 0

for i in range(n - 2):
  t = copy.copy(s[i:i + 2])
  if(s[i + 1] == sorted(t)[1]):
    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(1,n-2):
    if p[i-1]<p[i]<p[i+1]:
        ans+=1
    else :
        ans+=0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    d = list(map(int, input().split()))
    d.sort()
    ans += d[n//2] - d[n//2-1]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a=int(input())
seqS=input().split(" ")
num=[]
for q in seqS:
    num.append(int(q))
contador=0

#primeiro
#if num[0] > num[1]:
    #contador+=1

for i in range(1,len(num)-1):
    if num[i-1] > num[i] and num[i] > num[i+1] or num[i-1] < num[i] and num[i] < num[i+1]:
        contador+=1
        print(num[i-1],num[i],num[i+1])

#ultimo
#if num[-1] > num[-2]:
    #contador+=1
print(contador)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n,p=int(input()),input().split();print(sum(1 for x in range(n-2)if p[x]<p[x+1]<p[x+2]or p[x]>p[x+1]>p[x+2]))

Submission status: Wrong Answer

Solution code:
#ABC 132 B
n = int(input())
p= [int(j) for j in input().split()]
ans =0
for i in range(0,n-3+1):
    if p[i:i+3][1] ==sorted(p[i:i+3])[1]:
        ans+=1
        print(p[i:i+3])
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

count=0
for name, i in enumerate(p):
    try:
  	    if (p[name+1] > p[name] > p[name-1]) or (p[name-1] > p[name] > p[name+1]):
              count+=1
    except IndexError:
        continue
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=list(map(int,input().split()))
s=m[0]
t=m[1]
o=m[2]
ans=0
i=3
while i<len(m):
  if s<t and t<o:
    ans+=1
  s=m[0]+1
  t=m[1]+1
  o=m[2]+1
  i+=1
print(ans)

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

print(count)

Submission status: Wrong Answer

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

if n % 2 == 0:
    n -= 1
count = 0
for a in range(1, n-1):
    if p[a-1] > p[a] and p[a+1] < p[a]:
        #print(p[a-1], p[a], p[a+1])
        count += 1
    if p[a-1] < p[a] and p[a+1] > p[a]:
        #print(p[a-1], p[a], p[a+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)-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:
def solve():
    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]:
            cnt+=1
    print(cnt)
if __name__=='__main__':
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
seconds = []
for a in range(0,n-2):
    num = [p[a],p[a+1],p[a+2]]
    num.sort()
    seconds.append(num[1])

print(len(set(seconds)))

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
seconds = []
for a in range(0,n-3):
    num = [p[a],p[a+1],p[a+2]]
    num.sort()
    seconds.append(num[1])

print(len(set(seconds)))

Submission status: Wrong Answer

Solution code:
N=int(input())
l=[int(x) for x in input().rstrip().split()]
now=[]
n=[]

for i in range(1,N-1):
  now.append(l[i-1])
  now.append(l[i])
  now.append(l[i+1])

  now=list(set(now))
  now.sort()
  if len(now)==1 or len(now)==2:
    now=[]
    continue
  else:
    n.append(now[1])
    now=[]

print(len(set(n)))

Submission status: Wrong Answer

Solution code:
N=int(input())
l=[int(x) for x in input().rstrip().split()]
now=[]
n=[]

for i in range(1,N-1):
  now.append(l[i-1])
  now.append(l[i])
  now.append(l[i+1])

  now.sort()
  n.append(now[1])
  now=[]

print(len(set(n)))

Submission status: Wrong Answer

Solution code:
s = input()

result = ""
result_old = ""

#現在の文字列の長さ
#1個前の文字列の長さ

for i in range(int(len(s))):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        result = result +s[i] 
    else:
        if int(len(result_old)) <= int(len(result)):
            result_old = result
        else:
            result = [None for _ in range(int(len(result)))]
            result = ""


if s == "A" or s == "C" or s == "G" or s == "T":
    result_old = "A"
print(len(result_old))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
number = input().split(" ")
ans = 0
for i in range(n-2):
    if number[i] > number[i+1]:
        if number[i+1] > number[i+2]:
            ans += 1
    elif number[i] < number[i+1]:
        if number[i+1] < number[i+2]:
            ans += 1
    else:
        pass
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
number = input().split(" ")
ans = 0
for i in range(n-2):
    if number[i] >= number[i+1] and number[i+1] >= number[i+2]:
        ans += 1
    elif number[i] <= number[i+1] and number[i+1] <= number[i+2]:
        ans += 1
    else:
        pass
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
number = input().split(" ")
ans = 0
for i in range(n-2):
    if number[i] > number[i+1] and number[i+1] > number[i+2]:
        ans += 1
    elif number[i] < number[i+1] and number[i+1] < number[i+2]:
        ans += 1
    else:
        pass
print(ans)

Submission status: Wrong Answer

Solution code:
input()
a=list(map(int,input().split()))
b=0
for i in range(1,len(a)-1):
  b+=a[i-1]<i and i<a[i+1]
  b+=a[i-1]>i and i>a[i+1]
print(b)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a=int(input())
b=list(map(int,input().split()))
b.sort()
print(b[1])

Submission status: Wrong Answer

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

  if print(y[1]) == p[i]:
    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(1,n-1):
    tmp = sorted([p[i-1],p[i],p[2]])
    if tmp[1] == p[i]:
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())

t = input().split()

count = 0

for i in range(n-2):
    A = t[i:i+3]
    #print(A)
    y = A[1]
    A.sort()

    if y == A[1]:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())

t = input().split()

count = 0

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

Submission status: Wrong Answer

Solution code:
import math
#import numpy


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


n = int(input())
p = readints()
print(p)
sum = 0
for i in range(n-2):
    #print(p[i], end="")
    #print(p[i+1], end="")
    #print(p[i+2], end="")
    if p[i] < p[i+1] < p[i+2] or p[i] > p[i+1] > p[i+2]:
        sum += 1
print(sum)

Submission status: Wrong Answer

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

cnt = 0
for i in range(1,n-1):
  print(p[i-1], p[i], p[i+1])
  if (p[i] > p[i-1]) and (p[i] < p[i+1]): cnt += 1
  if (p[i] < p[i-1]) 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()))
cnt = 0
for i in range(1,n-1):
  if (p[i] > p[i-1]) 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()))
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if p[i]<p[j]<p[k] or p[k]<p[j]<p[i]:
                ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

dic = {}
for i in range(1, n+1):
    dic.setdefault(i, 0)

for i in range(n-2):
    tmp = sorted(pl[i:i+3])
    if tmp[0] < tmp[1] < tmp[2]:
        dic[tmp[1]] += 1

count = 0
for v in dic.values():
    if v > 0:
        count += 1

print(count)

Submission status: Wrong Answer

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

dic = {}
for i in range(1, n+1):
    dic.setdefault(i, 0)

for i in range(n-2):
    tmp = sorted(pl[i:i+3])[1]
    dic[tmp] += 1

count = 0
for v in dic.values():
    if v > 0:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
ans = []
for i in range(n-2):
    ans.append(sorted(p[i:i+3])[1])
print(len(set(ans)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = set()
for i in range(1, n-1):
	a = []
	a.append(p[i-1])
	a.append(p[i])
	a.append(p[i+1])
	a.sort()
	if a[0] < a[1] and a[1] < a[2]:
	  ans.add(a[1])
	elif a[0] == a[1]:
	 	ans.add(a[2])
	elif a[1] == a[2]:
		ans.add(a[1])
	
print(len(ans))

Submission status: Wrong Answer

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

ans = set()
for i in range(1, n-1):
	print(i)
	a = []
	a.append(p[i-1])
	a.append(p[i])
	a.append(p[i+1])
	a.sort()
	if a[0] < a[1] and a[1] < a[2]:
	  ans.add(a[1])
	elif a[0] == a[1]:
	 	ans.add(a[2])
	elif a[1] == a[2]:
		ans.add(a[1])
	
print(len(ans))

Submission status: Wrong Answer

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

ans = set()
for i in range(1, n-1):
	a = []
	a.append(p[i-1])
	a.append(p[i])
	a.append(p[i+1])
	a.sort()
	if a[0] < a[1] and a[1] < a[2]:
	  ans.add(a[1])
	
print(len(ans))

Submission status: Wrong Answer

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

ans = set()
for i in range(1, n-1):
	a = []
	a.append(p[i-1])
	a.append(p[i])
	a.append(p[i+1])
	a.sort()
	ans.add(a[1])
	
print(len(ans))

Submission status: Wrong Answer

Solution code:
def main():
    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]:
            print(i)
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    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]:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

cnt = 0
for i in range(0, n-2):
    print(p[i], p[i+1], p[i+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: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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-1] < p[i] < p[i+1] or p[i+1] < p[i] < p[i-1]:
    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 P[i-1] < P[i] < P[i+1] or P[i-1] > P[i] > P[i+1]:
        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(n-2):
    if (p[i] > p[i+1]) & (p[i+2] > p[i+1]):
        count += 1
print(count)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
strr = input().split()
count = 0

for i in range(1,n-1):
    if strr[i-1]<strr[i]<strr[i+1] or strr[i+1]<strr[i]<strr[i-1]:
        count +=1
    else:
        pass

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
strr = input().split()
count = 0

for i in range(1,n-1):
    if (strr[i-1] <strr[i] and strr[i] <strr[i+1]) or (strr[i-1] >strr[i] and strr[i]> strr[i+1]):
        count +=1
    else:
        pass

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
c = 0
for i in range(n-1):
    if sorted(A[i:i+3]).index(A[i+1]) == 1:
        c += 1
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count=0

for i in range(n-2):
    q=sorted(p[i:i+3])
    print(q)
    if q[1]==p[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(n-2):
    q=sorted(p[i+1:i+3])
    if q[1]==p[i+1]:
        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(1, n - 1):
    if p[i - 1] < p[i] < p[i+1] or p[i-1] < p[i] < p[i + 1]:
        cnt += 1
    else:
        continue

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] < p[i+1] or p[i-1] < p[i] < p[i + 1]):
        cnt += 1
    else:
        continue

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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