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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nb = int(input())
liste = [int(x) for x in input().split()]
compteur = 0
for loop in range(nb-2):
    if (liste[loop+1]>liste[loop] and liste[loop+1]<liste[loop+2]) or (liste[loop+1]<liste[loop] and liste[loop+1]>liste[loop+2]):
        compteur +=1
print(compteur)

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    P = il()

    ret = 0
    for n in range(N - 2):
        trg = P[n:n + 3][1]
        if sorted(P[n:n + 3])[1] == trg: ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

Solution code:
num = int(input())
arr = input().split()
count = 0
 
for i in range(1, num-1):
  if int(arr[i-1]) < int(arr[i]) < int(arr[i+1]) or int(arr[i-1]) > int(arr[i]) > int(arr[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] and p[i] < p[i+1] :
        ans += 1
    elif p[i+1] < p[i] and p[i] < p[i-1] :
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
cnt=0
p=[int(x) for x in input().rstrip().split()]
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())
arr = input().split()
count = 0

for i in range(1, n-1):
  if int(arr[i-1]) < int(arr[i]) < int(arr[i+1]) or int(arr[i-1]) > int(arr[i]) > int(arr[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())
list=list(map(int, 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: Accepted

Solution code:
# 132 B

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

def sec(a, k, b):
    if (a <= k <= b) or (a >= k >= b):
        global num
        num += 1

for i in range(1, n-1):
    sec(p[i-1], p[i], p[i+1])

print(num)

Submission status: Accepted

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

cnt = 0
for i in range(N-2):
    LA = []
    LB = []
    LA = [LP[i],LP[i+1],LP[i+2]]
    LB = sorted(LA)
    if LA[1] == LB[1]:
        cnt += 1
print(cnt)

Submission status: Accepted

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

cnt = 0
for i in range(N-2):
    LA = []
    LB = []
    LA.append(LP[i])
    LA.append(LP[i+1])
    LA.append(LP[i+2])
    LB = sorted(LA)
    if LA[1] == LB[1]:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    n, *P = map(int, read().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)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

ans = 0
for i in range(1,len(p)-1):
    if p[i-1] < p[i] and p[i] < p[i+1]:
        ans += 1
    elif p[i-1] > p[i] and p[i] > p[i+1]:
        ans += 1
    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] 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:
import sys
sys.setrecursionlimit(10**6)

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,len(p)-1):
  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)

Submission status: Accepted

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
    if P[i-1] > P[i] > P[i+1]: 
      A += 1
print(A)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for i in range(n - 2):
  if p_list[i] < p_list[i+1] and p_list[i+1] < p_list[i + 2]:
    count += 1
  elif p_list[i + 2] < p_list[i+1] and p_list[i+1] < p_list[i]: 
    count += 1
  else:
    continue
  
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:
n = int(input())
p = list(map(int, input().split()))

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

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

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+1]!=min(p[i:3+i]) and p[i+1]!=max(p[i:3+i]):
        c+=1
    elif p[i+1]==max(p[i:3+i]) and p[i:3+i].count(p[i+1])==2:
        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):
    per = [p[i - 1], p[i], p[i + 1]]
    per.sort()
    
    if per[1] == p[i]:
        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):
    Pps = sorted(P[i:i + 3])
    if Pps[1] == P[i + 1]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    P = list(map(int, input().split()))

    ans = 0
    for i in range(n-2):
        a, b, c = P[i:i+3]
        if a < b <= c or c < b <= a:
            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):
    T = sorted(P[i - 1: i + 2])
    if T[1] == 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] <= p[i+1] <= p[i+2]:
        count += 1
    elif p[i+2] <= p[i+1] <= p[i]:
        count += 1
print(count)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for i in range(n-2):

    if(l[i] < l[i+1] and l[i+1] < l[i+2]):
        count += 1
        continue
    if(l[i+2] < l[i+1] and l[i+1] < l[i]):
        count += 1
        continue

print(count)

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()))
ans=0
for i in range(n) :
    if i==0 or i==n-1 : continue
    if a[i-1]>a[i] and a[i]>a[i+1] or a[i-1]<a[i] and a[i]<a[i+1] : ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def is_no2(X):
    if X[1] == min(X) or X[1] == max(X):
        return 0
    else:
        return 1

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

ans = 0
for i in range(N-2):
    X = [P[i], P[i+1], P[i+2]]
    ans += is_no2(X)

print(ans)

Submission status: Accepted

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

input = lambda: sys.stdin.readline().rstrip()


def solve():
    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)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def main():
    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)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

    if p[i-1] > p[i] and p[i] > p[i+1]:
        c = c + 1

print(c)

Submission status: Accepted

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

ans = 0
for i in range(0,len(P)-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 = list(map(int, input().split()))

start = 2 - 1
end = len(p) - 1

count = 0
for i in range(start, end):
    
    a = p[i - 1]
    b = p[i]
    c = p[i + 1]
    
    # print(f'{p[i - 1]} {p[i]} {p[i + 1]}')
    
    new_list = sorted([a, b, c])
    
    if b == new_list[1]:
        # print(f'{a} {b} {c}')
        count += 1
        
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
N = int(input())
P = list(map(int, input().split()))
count = 0
for n in range(1, N - 1):
  if (P[n] > P[n - 1] and P[n] < P[n + 1]) or (P[n] < P[n - 1] and P[n] > P[n + 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):
    minp = min(p[i-1:i+2])
    maxp = max(p[i-1:i+2])
    if p[i] != minp and p[i] != maxp:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
def main():
    _ = input()
    A = list(map(int, input().split()))
    cnt = 0
    for i in range(len(A)-2):
        A_sub = sorted(A[i:i+3])
        a = A[i+1]
        if a == A_sub[1]:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def actual(n, P):
    count = 0

    for i in range(1, n - 1):
        a, b, c = P[i - 1], P[i], P[i + 1]

        if (a < b < c) or (a > b > c):
            count += 1

    return count

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

print(actual(n, P))

Submission status: Accepted

Solution code:
N=int(input())
S=list(map(int,input().split()))
count=0
for i in range(N-2):
    if max(S[i],S[i+1],S[i+2])==S[i+1] or min (S[i],S[i+1],S[i+2])==S[i+1]:
        count+=0
    else:
        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] and p[i] <= p[i+1]:
        ans += 1
    elif p[i+1] <= p[i] and p[i] <= p[i-1]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
P=list(map(int,input().split()))
res=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]:
        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] and p[i+1] < p[i+2]) or (p[i+2] < p[i+1] and p[i+1] < p[i]):
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
p=lmp()
ans=0
for i in range(n-2):
    if sorted(list((p[i],p[i+1],p[i+2])))[1]==p[i+1]:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math
def ip():return int(input())
def inp():return map(int,input().split())
def linp():return list(map(int,input().split()))

n=ip()
p=linp()
ans=0
for i in range(1,n-1):
    l=[p[i-1],p[i],p[i+1]]
    if p[i]>min(l) and p[i]<max(l):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):
  x = sorted(p[i:i+3])[1]
  if p[i+1] == x:
    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):
    tmp = [p[i-1], p[i], p[i+1]]
    if max(tmp) != p[i] and min(tmp) != p[i]:
        cnt += 1
        
print(cnt)

Submission status: Accepted

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

for i in range(n-2):
    if sorted(a[i:i+3])[1]==a[i:i+3][1]:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    p = list(map(int, input().split()))
    ans = 0
    for i in range(n - 2):
        tmp = p[i: i + 3]
        tmp.sort()
        if tmp[1] == p[i + 1]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
n = int(input())
p = list(map(int, input().split()))

#
count =[]
for i in range(1,n-1):
    p3 =p[i-1:i+2]
    p3.sort()
    if p3[1] ==p[i]:
        count.append(i)
print(len(count))

Submission status: Accepted

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

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:
#毎回ソートしよw
N = int(input())
p = list(map(int,input().split()))

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

Submission status: Accepted

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

count = 0
for x in range(N - 2):
    if (p[x] < p[x + 1] and p[x + 1] < p[x + 2]) or (p[x] > p[x + 1] and p[x + 1] > p[x + 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()))
count = 0

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

Submission status: Accepted

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

for p1, p2, p3 in zip(P, P[1:], P[2:]):
    p = [p1, p2, p3]
    p.sort()
    if p2 == p[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] != max(p[i-1],p[i],p[i+1]) and p[i] != min(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):
    nums = [p[i-1], p[i], p[i+1]]
    if sorted(nums)[1] == p[i]:
        ans += 1

print(ans)

Submission status: Accepted

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

for num in range(1,len(p)-1):
    p1 = p[num - 1]
    p2 = p[num]
    p3 = p[num + 1]
    
    p_list = [p1,p2,p3]
    p_list.sort()
    if p_list[1] == p2:
        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())
P=list(map(int,input().split()))
count=0
for i in range(n-2):
    if P[i+1]!=max(P[i:i+3]) and P[i+1]!=min(P[i:i+3]):
        count+=1
print(count)

Submission status: Accepted

Solution code:
n=int(input())
p=list(map(int,input().split()))
L=[]*3
ans=0
for i in range(n-2):
    L=p[i:i+3]
    L.sort()
    if L[1]==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]!=max(p[i-1],p[i],p[i+1]) and p[i]!=min(p[i-1],p[i],p[i+1]):
    ans=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:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    n = int(input())
    p_list = list(map(int, input().split()))
    count = 0
    for i in range(0,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])):
            count += 1
    print(count)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
input()
p = list(map(int, input().split()))
print(sum(pi < pj < pk or pk < pj < pi for pi, pj, pk in zip(p, p[1:], p[2:])))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
p=n1()
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(1, n-1):
    p_max = max(p[i-1],p[i], p[i+1])
    p_min = min(p[i-1], p[i], p[i+1])
    if p_max != p[i] and p_min != p[i]:
        count += 1
print(count)

Submission status: Accepted

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


def main():
    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)


if __name__ == '__main__':
    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()))
ans = 0
for i in range(1,n-1):
    t = p[i-1:i+2]
    if max(t)>t[1]>min(t):
        ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in range(n-2):
    #比較する3つのｐの値
    buf = p[i:i+3]
    #真ん中の数値
    buf1 = buf[1]
    
    buf.sort()
    if buf[1] == buf1:
        ans += 1
    #print(buf)

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

Submission status: Accepted

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

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

count = 0
for i in range(1, len(p)-1):
    min_ = min(p[i-1], p[i], p[i+1])
    max_ = max(p[i-1], p[i], p[i+1])
    if p[i] != min_ and p[i] != max_:
        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):
    a = []
    a.extend([p[i], p[i+1], p[i+2]])
    s = set(a)
    if len(s)==3:
        a3 = sorted(a)
        if a3[1]==a[1]:
            ans += 1
    elif len(s)==2:
        if a[1]<a[2] and a[1]<a[0]:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input()) - 2
L = list(map(int, input().split()))
a = 0

for i in range(n):
  if L[i] < L[i+1] and L[i+1] < L[i+2]:
    a = a+1
  elif L[i+2] < L[i+1] and L[i+1] < L[i]:
    a = a+1
    
print(a)

Submission status: Accepted

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 + 3])
  if(s[i + 1] == sorted(t)[1]):
    count += 1

print(count)

Submission status: Accepted

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

cnt = 0
for i, c in enumerate(p):
    if i == 0 or i == n-1:
        continue
    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())
a = list(map(int,input().split()))
cnt = 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]:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
P = list(map(int, input().split()))
a = 0
for i in range(1,n-1):
    L = P[i-1:i+2]
    if not (P[i]==min(L) or P[i]==max(L)):
        a = a+1
    else:
        pass
print(a)

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

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