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

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(sum)

Submission status: Accepted

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

def niban(i,list):
    if list[i]<list[i+1]<list[i+2] or list[i+2]<list[i+1]<list[i]:
      # print(list[i+1])                                                       
       return 1
    else:
       #print(list[i+1])                                                       
       return 0


#print(n)                                                                      
for i in range(n-2):
    if niban(i,plist):
        count += 1

print(count)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

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

count = 0

for i in range(N-2):
    if A[i] < A[i+1] and A[i+1] < A[i+2]:
        count += 1
    elif A[i] > A[i+1] and A[i+1] > A[i+2]:
        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=[]
    for j in range(3):
        a.append(p[i+j])
    a.sort()
    if a[1]==p[i+1]:
        cnt+=1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def secc(a,b,c):
    k =[]
    k.append(a)
    k.append(b)
    k.append(c)
    k.sort()
    if(k[1]==b):
        return True
    else:
        return False
n = int(input())
a = list(map(int,input().split()))
c =0 
for i in range(1,n-1):
    if(secc(a[i-1],a[i],a[i+1])):
        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(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()))
X = []
for i in range(1,n-1):
  A = [p[i-1],p[i],p[i+1]]
  A.sort()
  if p[i]==A[1]:
    X.append(p[i])
print(len(X))

Submission status: Accepted

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

result = 0

for count in range(N-2):
    sliced_list = numbers[:3]
    if min(sliced_list) != sliced_list[1] and max(sliced_list) != sliced_list[1]:
        result = result + 1
    numbers.pop(0)
print(result)

Submission status: Accepted

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

ans = 0
for i in range(1, n - 1):
    P_list = [P_n[i - 1], P_n[i], P_n[i + 1]]
    P_list.sort()

    if P_n[i] == P_list[1]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
num = int(input())
numbers = [ int(i) for i in input().split()]
count = 0
for i in range(len(numbers)):
    if i == 0:
        continue
    elif i == num-1:
        continue
    else:
        if numbers[i] < numbers[i-1] and numbers[i] > numbers[i+1]:
            count +=1
        elif 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()))
count = 0

for i in range(N-2):
    p1,p2,p3 = p[i:i+3]
    if p1 < p2 < p3 or p1 > p2 > p3:
        count += 1
print(count)

Submission status: Accepted

Solution code:
num = int(input())
seq = input().split()

sequence = [int(i) for i in seq]
count = 0

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

Submission status: Accepted

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

cnt = 0

for a in range(n-2) :
    x = [p[a], p[a+1], p[a+2]]
    x.sort()
    if(x[1] == p[a+1]) :
        cnt = cnt + 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
nump = input().split()
nump = [int(i) for i in nump]

count = 0
for i in range(1,N-1):
  p = nump[i]
  tmp = nump[i-1:i+2]
  tmp.sort()
  if tmp[1] == p:
    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 = p[i];
  b = p[i+1];
  c = p[i+2];
  if(a < b and c > b ):
     count = count + 1 
  elif(c < b and a > b ):
     count = count + 1 

print(count)

Submission status: Accepted

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

ordinary()

Submission status: Accepted

Solution code:
import sys


def main():
    n = sys.stdin.readline().strip()
    p_s = sys.stdin.readline().strip()
    p = [int(s) for s in p_s.split()]
    ans = 0
    for i in range(len(p)-2):
        sorted_three = sorted(p[i:i+3])
        if sorted_three[1] == p[i+1] and sorted_three[0] < 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(n-2):
    if (p[i]<p[i+1] and p[i+1]<p[i+2]) or (p[i+1]<p[i] and p[i+1]>p[i+2]):
        count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())

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

cnt=0
for i in range(num-2):
    if list_A[i] < list_A[i+1] and list_A[i+1] < list_A[i+2]:
        cnt += 1
    elif list_A[i] > list_A[i+1] and list_A[i+1] > list_A[i+2]:
        cnt += 1

    else:
        pass

print(cnt)

Submission status: Accepted

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
p = tuple(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())
count = 0
a = input()
list1 = list(map(int,a.split()))

for i in range(1,N-1):
    if list1[i-1] < list1[i] < list1[i+1]:
        count +=1
    elif list1[i+1] < list1[i] < list1[i-1]:
        count +=1

print(count)

Submission status: Accepted

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

total = 0
for i in range(len(b) - 2):
  templist = [b[i], b[i+1], b[i+2]]
  if b[i+1] != max(templist) and b[i+1] != min(templist):
    total += 1

print(total)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

# main
n = int(input())
array_p = [int(i) for i in input().split(' ')]

def is_second(input_list):
    sort = sorted(input_list)
    if input_list[1] == sort[1]:
        return True
    else:
        return False

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

print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def main():
    # # 整数の入力
    # a = int(input())
    # # スペース区切りの整数の入力
    # b, c = map(int, input().split())
    # # 文字列の入力
    # s = input()
    # # 出力
    # print("{} {}".format(a+b+c, s))
    n = int(input())
    p_list = list(map(int, input().split()))
    cnt = 0
    for i in range(1, n-1):
        if min(p_list[i-1],p_list[i+1])<p_list[i] and p_list[i]<=max(p_list[i-1],p_list[i+1]):
            cnt += 1
        else:
            pass
    print(cnt)



if __name__=='__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

answer = 0

prev_bigger = P[0] < P[1]
for i in range(2, N):
    current_bigger = P[i-1] < P[i]
    if prev_bigger and current_bigger:
        answer += 1
    elif not prev_bigger and not current_bigger:
        answer += 1
    prev_bigger = current_bigger

print(answer)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(1,n-1):
    if not((p[i-1] > p[i] and p[i] < p[i+1]) or (p[i-1] < p[i] and p[i] > p[i+1]) or (p[i-1] == p[i] 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()))
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:
#B
N= map(int, input().split())
W = list(map(int, input().split()))
ans_max=0
ans_min=0
for i in range(1,len(W)-1,1):
    if(W[i]==max(W[i-1],W[i],W[i+1])):
        ans_max = ans_max+1
    if(W[i]==min(W[i-1],W[i],W[i+1])):
        ans_min = ans_min+1


print(len(W)-2-(ans_max+ans_min))

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]:
        if p[i+1]<p[i+2]:
            A=A+1
    else:
        if p[i+1]>p[i+2]:
            A=A+1

print(A)

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 P[i] < P[i+1] and P[i+1] < P[i+2]:
    cnt += 1
  elif P[i] > P[i+1] and P[i+1] > P[i+2]:
    cnt += 1
    
  #print(P[i:i+3])
  
print(cnt)

Submission status: Accepted

Solution code:
def code_for_B(test=None):

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

    pre = list_p[0]
    count = 0

    for i in range(1,n-1):
        cur = list_p[i]
        nxt = list_p[i+1]

        if pre >= cur > nxt:
            count += 1
        elif pre < cur < nxt:
            count += 1

        pre, cur = cur, nxt

    print(count)

code_for_B()

Submission status: Accepted

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

answer = 0

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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=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):
   b=[A[i-1],A[i],A[i+1]]
   b.sort()
   if b[1]==A[i]:
      cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
t=input().split()
v=[]
for i in range(n):
    v.append(int(t[i]))

count=0

for i in range(n-1):
    if i == 0:
        count=0
    elif v[i-1] < v[i] < v[i+1] or v[i-1] > v[i] > v[i+1]:
        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(2,n):
    #i-1が二番目に小さい
    if p[i-2] > p[i-1] > p[i] or p[i] > p[i-1] > p[i-2]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
arr = [int(i) for i in input().split(" ")]
l = len(arr)
count = 0
for i in range(0, l-2):
    m = arr[i+1]
    tmp = [arr[i], arr[i+1], arr[i+2]]
    tmp.sort()
    if m == tmp[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] > 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())
p = list(map(int,input().split()))
count = 0
for i in range(n-2):
  if (p[i]-p[i+1])*(p[i+2]-p[i+1]) < 0:
    count+=1
print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

n = int(input())
s = [int(c) for c in input().split(' ')]

count = 0

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
list1 = list(map(int, input().split()))
cnt = 0
for i in range(0,n-2):
    if (list1[i]>list1[i+1] and list1[i+1]>list1[i+2]):
        cnt += 1
    if (list1[i]<list1[i+1] and list1[i+1]<list1[i+2]):
        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] 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 = input()
p = input().split(" ")
for i, pp in enumerate(p):
    p[i] = int(pp)
count = 0
for i in range(len(p)-2):
    mirutoko = p[i:i+3]
#     print(mirutoko)
    mirutoko_sort = sorted(mirutoko)
#     print(mirutoko_sort)
    if mirutoko[1] == mirutoko_sort[1]:
        count += 1
#     print(count)
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    import numpy
    N = int(input())
    P =[int(i) for i in input().split()]
    #print(P)
    count = 0
    for i in range(1,N-1):
        tmp = [P[i-1],P[i],P[i+1]]
        #print(tmp)
        PP=numpy.array(tmp)
        #print(PP)
        PPI = PP.argsort()
        #print(PPI)
        if PPI[1] == 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(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:
num = int(input())
# 各行を入力しリストに格納
array = list(map(int, input().split()))
count = 0
for i in range (1,num-1,1):
  if array[i-1] < array[i] and array[i] <array[i+1] or array[i+1] < array[i] and array[i] <array[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):
    tmp = list((p[i-1],p[i],p[i+1]))
    tmp.sort()
    if p[i] == tmp[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] 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()))
cnt=0

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

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(len(a)-2):
    c = a[i+1]
    a_sub = a[i:i+3]
#     print(a_sub, c)
#     print(sorted(a_sub))
    if sorted(a_sub)[1] == c:
        cnt += 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0

for i in range(1, len(p_list) -1):
  check_list = [p_list[i-1], p_list[i], p_list[i+1]]
  check_p = p_list[i]
  check_list.sort()
  if check_list[1] == check_p:
    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):
    if i == 0 or i == 1:
        continue
    else:
        MAX = max(P[i-2],P[i-1],P[i])
        # print("max {}, p-2 {} ,p-1 {} p {}".format(MAX,P[i-2],P[i-1],P[i]))


        if MAX == P[i]:
            if P[i-1] >= P[i-2]:
                count += 1
                continue
            else:
                continue

        elif MAX == P[i-1]:
            continue

        elif MAX == P[i-2]:
            if P[i-1] >= P[i]:
                count += 1
                continue
            else:
                continue


print(count)




# print(max(1,3,5))

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
    else:
        ans += 0
print(ans)

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


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

Submission status: Accepted

Solution code:
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    p_list = li()
    second_count = 0
    for i in range(n - 2):
        if p_list[i] < p_list[i + 1] < p_list[i + 2] or p_list[i] > p_list[i + 1] > p_list[i + 2]:
            second_count = second_count + 1
    print(second_count)

Submission status: Accepted

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

cnt = 0
#print(n)
p = list(p)
for i in range(1,n-1):
    a = p[i-1]
    b = p[i]
    c = p[i+1]
    ans = [a, b, c]
    #print(ans)
    ans.pop(ans.index(min(ans)))
    if b == min(ans):
        cnt+=1

print(cnt)

Submission status: Accepted

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

count = 0
for i in range(1,n-1):
	d = sorted(ps[i-1:i+1+1])
	#print(d,d[0],d[1],d[2])
	if d[0] < d[1] and d[1] < d[2] and ps[i] == d[1]:
		count += 1
		
print(count)

Submission status: Accepted

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

co=0
for i in range(0,n-2):
    li=[p[i],p[i+1],p[i+2]]
    li.sort()
    if li[1]==p[i+1]:
            co=co+1

print(co)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(1,n-2+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:
import numpy as np

n = int(input())
a = input().split(" ")
p = [int(i) for i in a]

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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


counter = 0

for i in range(1,n-1):
    p_partial = [p[i-1],p[i],p[i+1]]
    p_partial.sort()
    if p_partial[1] == p[i]:
        counter += 1

print(counter)

Submission status: Accepted

Solution code:
import re

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

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

print(ans)

Submission status: Accepted

Solution code:
# ABC132
def main():
    n = int(input())
    p = list(map(int, input().rstrip().split()))
    ans = 0
    for i, j, k in zip(p, p[1:], p[2:]):
        if i < j < k or k < j < i:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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]) or (l[i + 2] <= l[i + 1] and l[i + 1] <= l[i]):
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int,input().split()))
def hantei(aa,b,c):
    if(b<=c and aa<=c and b <= aa):
        return 1
    elif (c<=b and aa <= b and c <= aa):
        return 1
    else:
        return 0

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

Submission status: Accepted

Solution code:
n = int(input())

p = [int(_) for _ in 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
    
print (count)

Submission status: Accepted

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

Submission status: Accepted

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

num = 0
for i in range(len(s)-2):
    if ((s[i] < s[i+1] <s[i+2] ) or (s[i] > s[i+1] > s[i+2] )) == True:
        num +=1
print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
lp=[int(e) for e in input().split(' ')]

c=0
for i,p in enumerate(lp):
    if i>=1 and i<= N-2:
        if (lp[i-1]<p<=lp[i+1]) or (lp[i+1]<p<=lp[i-1]):
            c+=1
print(c)

Submission status: Accepted

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

print(result)

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

Submission status: Accepted

Solution code:
def main():
    n = input()
    ps = input().split(' ')
    count = 0
    for i in range(1, len(ps) - 1):
        if int(ps[i]) > min(int(ps[i - 1]), int(ps[i + 1])):
            if int(ps[i]) <= max(int(ps[i - 1]), int(ps[i + 1])):
                count += 1
    print(str(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):
    tmp = sorted(p[i-1:i+2])
    if p[i] == tmp[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(len(p)-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())
numlist = list(map(int,input().split()))
count = 0
for i in range(n-2):
    if numlist[i+2] > numlist[i+1] > numlist[i] or numlist[i+2] < numlist[i+1] < numlist[i]:
        count += 1

print(count)

Submission status: Accepted

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

numbers = numbers[0]

count = 0


for i in range(N-2):
    aaa = []
    number_a = int(numbers[i])
    aaa.append(number_a)
    number_b = int(numbers[i+1])
    aaa.append(number_b)
    number_c = int(numbers[i+2])
    aaa.append(number_c)
    if number_b == sorted(aaa)[-2]:
        count += 1
    else:
        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):
    if p[i] < p[i+1] < p[i+2] or p[i] > p[i+1] > p[i+2]:
        count += 1
    elif p[i] == p[i+2]:
        if p[i] > p[i+1]:
            count += 1
print(count)

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
a=[]
i=2
k=0
a.append(int(input()))
for x in input().split(" "):
    a.append(int(x))

while i<=a[0]-1:
    if a[i]>=a[i-1] and a[i]>=a[i+1]:
        k+=0
    elif a[i]<=a[i-1] and a[i]<=a[i+1]:
        k+=0
    else:
        k+=1
    i+=1
print(k)

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]:
		c = c+1
	elif p[i]==p[i+1] and p[i+1]<p[i+2]:
		c = c+1
	elif p[i+2]<p[i+1] and p[i+1]<p[i]:
		c = c+1
	elif p[i+2]==p[i+1] and p[i+1]<p[i]:
		c = c+1

print(c)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    p = tuple(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
    return count

print(main())

Submission status: Accepted

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

Submission status: Accepted

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

print sum(a[i] == sorted(a[i - 1: i + 2])[1] for i in xrange(1, n - 1))

Submission status: Accepted

Solution code:
#coding:utf-8

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

counter = 0

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

print(counter)