Problem:


Score : 200 points

Problem Statement

We have a permutation p = {p_1,\ p_2,\ ...,\ p_n} of {1,\ 2,\ ...,\ n}.

Print the number of elements p_i (1 < i < n) that satisfy the following condition:

p_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}.

Constraints

All values in input are integers.

3 \leq n \leq 20

p is a permutation of {1,\ 2,\ ...,\ n}.

Input

Input is given from Standard Input in the following format:

n
p_1 p_2 ... p_n

Output

Print the number of elements p_i (1 < i < n) that satisfy the condition.

Sample Input 1

5
1 3 5 4 2

Sample Output 1

2

p_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.

Sample Input 2

9
9 6 3 2 5 8 7 4 1

Sample Output 2

5



Sample input:
5
1 3 5 4 2


Sample output:
2

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import io

nim = int(input())
 
mike = list(map(int,input().split()))
 
counter = 0

for i in range(nim):
    t = mike[i:i+3]
    if len(t) == 3:
        if max(t) > t[1] and min(t) < t[1]:
            counter += 1
            
            
print(counter)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#abc132_b.py
def is_center(A,i):
    if (A[i-1]<A[i] and A[i]<A[i+1]) or (A[i-1]>A[i] and A[i]>A[i+1]):
        return True
    return False

N = int(input())
A = list(map(int,input().split()))
cnt = 0
for i in range(1,N-1):
    if is_center(A,i):
        cnt+= 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0
for i in range(1,n-1):
  num1 = num[i-1:i+2]
  num2 = sorted(num1)
  if num2[1]==num1[1]: count += 1
    
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
p=list(map(int,input().split()))
ANS=0
ans=p[0]-p[1]
for i in range(2,N):
    if (p[i-1]-p[i])*ans>=0:
        ANS+=1
    ans=(p[i-1]-p[i])//abs(p[i-1]-p[i])
print(ANS)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import math
import collections
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
ps=LI()
compare=[]
count=0
for i in range(1,n-1):
    compare=[]
    compare.append(ps[i-1])
    compare.append(ps[i])
    compare.append(ps[i+1])
    s=sorted(compare)
    if ps[i]==s[1]:
        count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = input()
w = [int(i) for i in input().split()]
d = 0
for i in range(len(w) -2 ):
    if (w[i] > w[i+1] > w[i+2]) or (w[i] < w[i+1] < w[i+2]):
        d += 1

print(d)

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

print(Count)

Submission status: Accepted

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

Submission status: Accepted

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

# flag = True # p(i) が p(i-1) より大きいか小さいかのフラグ
count = 0
for i in range(1, n - 1):
    partial = sorted(pp[i - 1:i + 2])
    if partial[1] == pp[i]:
        count += 1

print(count)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

num = 0
for i in range(1, len(p) - 1):
    left = p[i - 1]
    center = p[i]
    right = p[i + 1]

    if (left < center < right) or (right < center < left):
        num += 1

print(num)

Submission status: Accepted

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

num = 0
for i, pi in enumerate(p):
    need = 1 <= i <= len(p) - 1 - 1
    if not need: continue
    
    left = p[i - 1]
    center = p[i]
    right = p[i + 1]

    if (left < center < right) or (right < center < left):
        num += 1

print(num)

Submission status: Accepted

Solution code:
N,*P,=map(int,open(0).read().split())
i=1
ans=0
while i<N-1:
    if P[i-1]<P[i]<P[i+1] or P[i-1]>P[i]>P[i+1]:
        ans+=1
    i+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
P = list(map(int, input().split()))
c = 0
for i in range(1, n-1):
  b = P[i-1:i+2]
  m = max(b)
  midx = b.index(m)
  b[midx] = 0
  sm = max(b)
  if sm == b[1]:
    c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a= int(input())
b = input().split()
count = 0
for i in range(a-1):
    if i >= 1:
        if abs(int(b[i-1])-int(b[i])) < abs(int(b[i-1])-int(b[i+1])) and abs(int(b[i+1])-int(b[i])) < abs(int(b[i-1])-int(b[i+1])):
            count += 1
print(count)

Submission status: Accepted

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

    
if __name__ == '__main__':
    q2()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n = int(input())
  P = list(map(int,input().split()))
  
  #COMP = P[1:len(P)-1]
  #print(COMP)
  cnt = 0
  for i in range(1,len(P)-1):
    #print(P[i])
    if P[i-1] < P[i] < P[i+1] or P[i-1] > P[i] > P[i+1]:
      cnt += 1
  
  print(cnt)
if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

count=0

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    n = int(input())
    p = input_nums()
    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)

if __name__ == '__main__':
    main()

Submission status: Accepted

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


for a in p:
  if x < n-1:
    if p[x-1] < a < p[x+1] and x != 0:
      count += 1
    elif a < p[x-1] and a > p[x+1] and x != 0:
      count += 1
  x += 1
    

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(n: int, p: "List[int]"):
    return sum(1 if p1 <= p2 <= p3 or p3 <= p2 <= p1 else 0 for p1, p2, p3 in zip(p, p[1:], p[2:]))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    print(solve(n, p))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    p=LIST()
    ct=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]):
            ct+=1
    print(ct)
if __name__ == '__main__':
    do()

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(c)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

Solution code:
N=int(input())
l=[int(x) for x in input().rstrip().split()]
now=[]
n=[]
cnt=0
for i in range(1,N-1):
  if l[i-1]<l[i] and l[i]<l[i+1]:
    cnt+=1
  elif l[i+1]<l[i] and l[i]<l[i-1]:
    cnt+=1

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
P = 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
    elif P[i-1] > P[i] > P[i+1]:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(n: int, p: "List[int]"):
    sum = 0
    for i in range(1,n-1):
        a = p[i-1]
        b = p[i]
        c = p[i+1]
        if (a < b and b < c) or (a > b and b > c):
            sum += 1
    print(sum) 
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, p)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(num)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#整数の入力
N = int(input())
#スペース区切りの整数の入力リスト
P_list = list(map(int, input().split()))

counter = 0
for i in range(N-2):
  if((P_list[i]<P_list[i+1]<P_list[i+2])or(P_list[i+2]<P_list[i+1]<P_list[i])):
    counter = counter + 1
    
    
print(counter)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

cnt = 0
for i in range(n-2):
    tmp = p[i:i+3]
    ma = max(tmp)
    mi = min(tmp)
    if(tmp[1] != ma and tmp[1] != mi):
        cnt += 1
print(cnt)

Submission status: Accepted

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

cnt = 0
for i in range(1, n - 1):
    f = 0
    if P[i - 1] < P[i] and P[i] < P[i + 1]:
        f = 1
    elif P[i -1] > P[i] and P[i] > P[i + 1]:
        f = 1
    if f == 1:
        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    p = [int(x) for x in input().split()]
    ans = 0
    for idx in range(n-2):
        if (p[idx] < p[idx+1] and p[idx+1] < p[idx+2]) \
            or (p[idx] > p[idx+1] and p[idx+1] > p[idx+2]):
            ans+=1
    print(ans)

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
arrP = list(map(int,input().split()))

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

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0
for i in range(n-2):
    tmp = sorted(p_list[i:i+3], reverse=True)[1]
    if tmp == p_list[i+1]:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

n = ni()
p  = nl()
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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(n-2):
    b = a[i:i+3]
    c = b[1]
    b.sort()
    if c == b[1]:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    c = 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]:
            c += 1
    return c

print(solve())

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
P = list(map(int, input().split()))
answer = sum(x>y>z or x<y<z for x, y, z in zip(P[:-2], P[1:-1], P[2:]))
print(answer)