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())
a=list(map(int,input().split()))
cnt=0
for i in range(1,n-1):
    b=a[i-1:i+2]
    #print(b,sorted(b),b[1],sorted(b).index(b[1]))
    if sorted(b).index(b[1])==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] <= p[i+1] <= p[i+2] or p[i+2] <= p[i+1] <= p[i]:
        count += 1
print(count)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
p=list(map(int, input().split()))
ans=0
for i in range(1, N-1):
    ans+=1 if (p[i]-p[i+1])*(p[i]-p[i-1])<0 else 0
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())
L=list(map(int,input().split()))
M=[]
ans=0
for i in range(1,n-1):
    M=[L[i-1],L[i],L[i+1]]
    M.sort()
    if M[1]==L[i]:
        ans+=1
    M=[]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
p = input().split()
p = [int(num) for num in p]
t = 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])):
    t += 1
print(t)

Submission status: Accepted

Solution code:
n = int(input())
p = input().split()
p = [int(num) for num in p]
t = 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])):
    t += 1
print(t)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
p = list(map(int, input().split()))
result = 0
i = 1
for index, v in enumerate(p):
    if index != i:
        continue
    else:
        if len(p) >= index+2:
            a = p[index-1]
            b = p[index]
            c = p[index+1]
            if (a > b and b > c) or (b > a and c > b):
                result += 1
    i += 1
print(result)

Submission status: Accepted

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

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

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

cnt = 0

for i in range(1,n-1):
    if a[i-1] < a[i] and a[i] < a[i+1]:
        cnt += 1
    elif a[i-1] > a[i] and a[i] > a[i+1]:
        cnt += 1
    else:
        continue

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
ans = [1 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]]
print(sum(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=[int(i) for i in 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 = [int(i) for i in input().split()]
count = 0
for i in range(1, n - 1):
    if max(p[i - 1], p[i], p[i + 1]) != p[i] and min(p[i - 1], p[i], p[i + 1]) != p[i]:
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

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

Submission status: Accepted

Solution code:
#132

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))
l = [p[i] 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(len(l))

Submission status: Accepted

Solution code:
#132 b
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 b!=min(a,b,c) and b!=max(a,b,c):
        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):
  a,b,c=p[i-1],p[i],p[i+1]
  if b>min(a,c) and b<max(a,c):
    count+=1
print(count)

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] == sorted(P[i-1:i+2])[1]:
    counter += 1
print(counter)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0
for i in range(1,N-1):
    if (list[i-1] < list[i] and list[i] < list[i+1]) or (list[i-1] > list[i] and list[i] > list[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(1,n-1):
    low=min(p[i-1],p[i],p[i+1])
    heigh=max(p[i-1],p[i],p[i+1])
    if low<p[i]<heigh:
        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):
    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()))
count = 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]):
        count += 1
print(count)

Submission status: Accepted

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

count = 0

for i in range(0, len(lst)-2):
    target = lst[i:i+3]
    minVal = min(target)
    maxVal = max(target)
    val = lst[i+1]
    if val != minVal and val != maxVal:
        count += 1

print(count)

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]!=max(p[i-1],p[i],p[i+1]) and p[i]!=min(p[i-1],p[i],p[i+1]):
        a+=1
    else:
        pass
print(a)

Submission status: Accepted

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

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:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(n: int, p: "List[int]"):
    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)
    return



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())
def LI():
  return [int(s) for s in input().split()]

p = LI()

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

print(count)

Submission status: 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()))
count=0
for i in range(n-2):
    if((p[i]<p[i+1])and(p[i+1]<p[i+2])):
        count=count+1
    elif((p[i+2]<p[i+1])and(p[i+1]<p[i])):
        count=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):
    min_p = min(p[i-1], p[i+1])
    max_p = max(p[i-1], p[i+1])
    if min_p < p[i] < max_p:
        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
    else:
        pass

print(count)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

    count = 0

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

    print(count)

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

result = 0

for i in range(1,n-1):
    buf=[p[i-1],p[i],p[i+1]]
    if sorted(buf).index(p[i]) == 1:
        result+=1

print(result)

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

Submission status: Accepted

Solution code:
n, *ps = map(int, open(0).read().split())
cou =0
for x, y, z in zip(ps[:-2], ps[1:-1], ps[2:]):
  if (x-y)*(z-y)<0:
    cou += 1
print(cou)

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

    ans = 0

    for i in range(1,n-1):
        tmp = [p[i-1],p[i],p[i+1]]
        tmp.sort()
        if tmp[1] == p[i]:
            ans += 1
    
    print(ans)


if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

pp = [[p[i-1], p[i], p[i+1]] for i in range(1, n-1)]
print(len([x for x in pp if (x[1]>=x[0] and x[1]<=x[2]) or (x[1]<=x[0] and x[1]>=x[2])]))

Submission status: Accepted

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

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

hantei = 0


for i in range(number-2):
  if (list_input[i]-list_input[i+1])*(list_input[i+2]-list_input[i+1])<0:
    hantei = hantei +1

print(hantei)

Submission status: Accepted

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

for i in range(1, n - 1):
    larger = max(p[i-1], p[i+1])
    smaller = min(p[i-1], p[i+1])
    if p[i] > smaller and p[i] < larger:
        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 ):
  l=[p[i-1], p[i], p[i+1]]
  if ((max(l) != p[i]) and (min(l) != p[i])):
      ans+=1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
p = list(map(int, input().split()))
counter = 0
for g in range(1, N - 1):
    if p[g - 1] < p[g] < p[g + 1]:
        counter += 1
    if p[g + 1] < p[g] < p[g - 1]:
        counter += 1

print(counter)

Submission status: Accepted

Solution code:
#python3
n=int(input())
p=[int(i) for i in input().split()]
cnt=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]):
    cnt+=1
print(cnt)

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] < 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:
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys
# import numpy as np
# import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = map(int, read().split())
print()
ans = 0
for i in range(N - 2):
    S = [P[i], P[i + 1], P[i + 2]]
    SS = sorted(S)
    if S[1] == SS[1]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys
# import numpy as np
# import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = map(int, read().split())
print(sum(x<y<z or x>y>z for x,y,z in zip(P,P[1:],P[2:])))

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys
import numpy as np
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = map(int, read().split())
print(sum(x<y<z or x>y>z for x,y,z in zip(P,P[1:],P[2:])))

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys
import numpy as np
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = map(int, read().split())
print()
ans = 0
for i in range(N - 2):
    S = [P[i], P[i + 1], P[i + 2]]
    SS = sorted(S)
    if S[1] == SS[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 = [int(_) for _ in 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: Accepted

Solution code:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        n = int(input())
        p = list(map(int, input().split()))

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


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

def ju(a,b,c):
    return b==(a+b+c)-min(a,b,c)-max(a,b,c)
    

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(n-2):
    l=[p[i],p[i+1],p[i+2]]
    l.sort()
    if l[1]==p[i+1]:
        cnt+=1
        l=[]
    else:
        l=[]
print(cnt)

Submission status: Accepted

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

for p1, p2, p3 in zip(p, p[1:], p[2:]):
    if (p1 < p2 and p2 < p3) or (p1 > p2 and p2 > p3):
        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):
    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())
ps = [int(i) for i in input().split()]

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,n-1):
    if min(l[i-1],l[i+1]) <= l[i] and l[i] <= max(l[i-1],l[i+1]):
        pair += 1 

print(pair)

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

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

print(count)

Submission status: Accepted

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

pi = []
cnt = 0

for i in range(1, n-1):
    pi = [p[i-1], p[i], p[i+1]]
    pi.sort()
    if p[i] == pi[1]:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
p_list = list(map(int, input().split()))
count = 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]:
        count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))
tmp = []
count = 0
for i in range(n):
  tmp.append(p[i])
  if len(tmp)==3:
    if sorted(tmp)[1]==p[i-1]:
      count+=1
    tmp.pop(0)
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())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
    if p[i]>min(p[i-1],p[i+1]) and p[i]<max(p[i-1],p[i+1]):
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
# Ordinary Number

# libraries
import numpy as np

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

# solve
res = 0
for i in range(1, n-1):
    s = [p[i-1], p[i], p[i+1]]
    if min(s) < s[1] and s[1] < max(s):
        res += 1

# output
print(res)

Submission status: Accepted

Solution code:
N, *P = map(int, open(0).read().split())
c = 0
for i in range(N-2):
    p1 = P[i]
    p2 = P[i+1]
    p3 = P[i+2]
    if p1 < p2 < p3 or p3 < p2 < p1:
        c += 1

print(c)

Submission status: Accepted

Solution code:
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]>p[i]):
            ans += 1
        elif (p[i-1]>p[i]) & (p[i+1]<p[i]):
            ans += 1
    return ans

if __name__ == '__main__':
    print(main())

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

Submission status: Accepted

Solution code:
N = int(input())
list = list(map(int,input().split()))
cnt=0
for i in range(1,N-1):
	sub = [list[i-1],list[i],list[i+1]]
	match = list[i]
	sub.sort()
	if(sub[1] == match):
		cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    *p, = map(int, input().split())
    
    c = 0
    for i in range(1, n - 1):
        if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
            c += 1
    print(c)

if __name__ == '__main__':
    main()