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

counter = 0
for i in range(1, N - 1):
  a = P[i - 1]
  b = P[i]
  c = P[i + 1]
  #print(a, b, c)

  if a < b < c or c < b < a:
    counter += 1

print(counter)

Submission status: Accepted

Solution code:
inp = input()
n = int(inp)
inp = input()
split_inp = inp.split()
total_count = 0
ppre = int(split_inp[0])
pre = int(split_inp[1])
for st in split_inp[2:]:
    p = int(st)
    if pre != max(ppre, pre, p) and pre != min(ppre, pre, p):
        total_count += 1
    ppre = pre
    pre = p
print(total_count)

Submission status: Accepted

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

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

Submission status: Accepted

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


def solve():
    N = int(input())
    P = list(map(int, input().split()))
    count = 0
    for i in range(1, N - 1):
        pack = [P[i - 1], P[i], P[i + 1]]
        if P[i] != max(pack) and P[i] != min(pack):
            count += 1
    return count


def main():
    print(solve())


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    P = list(map(int, input().split()))

    cnt = 0
    for i in range(1, N-1):
        p = P[i]
        if min(P[i-1:i+2]) < p < max(P[i-1:i+2]):
            cnt += 1

    return cnt


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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys
from collections import defaultdict

N = int(input())
A = list(map(int, input().rstrip().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())
plist = list(map(int, input().split()))

cnt = 0
for num in range(2, n):
    p1 = plist[num-2]
    p2 = plist[num-1]
    p3 = plist[num]
    if p1 > p3:
        if p1 > p2 > p3:
            cnt = cnt + 1
    else:
        if p3 > p2 > p1:
            cnt = cnt + 1

print(cnt)

Submission status: Accepted

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

m = sum(1 for p in zip(P, P[1:], P[2:]) if p[1] == sorted(p)[1])
print(m)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)

N = int(input())
P = [int(x) for x in input().split()]
# L = [[int(x) for x in input().split()] for _ in range(N)]
# N, M = map(int, input().split())
# S = input()

ans = 0
for i in range(N - 2):
    p = P[i : i + 3]
    p.sort()

    if p[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(2, n):
    if (p[i-2] > p[i-1] and p[i-1] > p[i]) or (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(1, len(p) - 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]:
        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):
    s = P[i-1]+P[i]+P[i+1]
    if s-min(P[i-1],P[i],P[i+1])-max(P[i-1],P[i],P[i+1]) == P[i]:
        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:


def main():
    n = int(input())
    ps = list(map(int, input().split()))
    ans = 0

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

    print(ans)


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):
    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 = list(map(int, input().split()))
c = 0
for p1, p2, p3 in zip(ps, ps[1:], ps[2:]):
    if sorted([p1, p2, p3])[1] == p2:
        c += 1
print(c)

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]:
               cnt+=1
          elif p[i-1]>p[i] and p[i]>p[i+1]:
               cnt+=1
     print(cnt)
          
if __name__=='__main__':
     main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)



def solve():
    N = int(input())
    p_list = list(map(int, input().split()))

    cnt = 0
    for i in range(1, N-1):
        pre = p_list[i-1]
        p = p_list[i]
        pos = p_list[i+1]

        if p < pre and p > pos:
            cnt += 1
        elif p > pre and p < pos:
            cnt += 1

    print(cnt)

solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from collections import defaultdict
import math
import re

def main():
    #H, W = map(int, input().split())
    N = int(input().strip())
    P = list(map(int, input().split()))

    cnt = 0
    for i in range(1, N-1):
        if (P[i] < P[i+1] and P[i] > P[i-1])\
            or (P[i] < P[i-1] 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):
    ps = p[i-1:i+2]
    ps.sort()
    if p[i] == ps[1]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque

readline = sys.stdin.readline

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

a = len([1 for i in range(1, n - 1) if 
    (p[i] < p[i + 1] or p[i] < p[i - 1]) and
    (p[i] > p[i + 1] or p[i] > p[i - 1])
])

print(a)

Submission status: Accepted

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

ans = 0
for i in range(len(p)-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())
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+=1
    elif p[i]>p[i+1] and p[i+1]>p[i+2]:
        c+=1
print(c)

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

Submission status: Accepted

Solution code:
# 2019/06/29
# AtCoder Beginner Contest 132 - B

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

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

# Output
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):
    p = P[i - 1 : i + 2]
    p.sort()
    if len(set(p)) > 1 and p.index(P[i]) == 1:
        ans += 1

print(ans)

Submission status: Accepted

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

    cnt = 0

    for p1,p2,p3 in zip(pp,pp[1:],pp[2:]):
        if p1 > p2 >= p3 or p1 <= p2 < p3:
            cnt += 1

    print(cnt)
    
resolve()

Submission status: Accepted

Solution code:
n = int(input())

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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


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


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

fin = sys.stdin.readline
n = int(fin())
p_list = [int(elem) for elem in fin().split()]

count = 0
for i in range(1, len(p_list)-1):
    prev_p = p_list[i-1]
    next_p = p_list[i+1]
    cur_p = p_list[i]
    if prev_p < cur_p < next_p:
        count += 1
    elif prev_p > cur_p > next_p:
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
p_list = [int(x) for x in input().split()]
cnt = 0
for i in range(n-2):
    cnt += ((p_list[i] < p_list[i+1] < p_list[i+2]) or (p_list[i] > p_list[i+1] > p_list[i+2]))
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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


def solve(n: int, p: "List[int]"):
    count = 0
    for i in range(1, n-1):
        part = p[i-1:i+2]
        if p[i] == max(part) or p[i] == min(part):
            continue
        count += 1
    print(count)
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0

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

print(ans)

Submission status: Accepted

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

for i in range(n-2):
    if p[i]<p[i+1] and p[i+2]>p[i+1]:
        ans+=1
    elif p[i]>p[i+1] and p[i+2]<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):
    p1 = p[i-1]
    p2 = p[i]
    p3 = p[i+1]
    if (p2 >= p1 and p3 >= p2) or (p2 >= p3 and p1 >= p2):
        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):
    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
    else:
        continue

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# @author 

import sys

class BOrdinaryNumber:
    def solve(self):
        n = int(input())
        p = [int(_) for _ in input().split()]
        ans = 0
        for i in range(1, n - 1):
            if min(p[i - 1], p[i + 1]) < p[i] < max(p[i - 1], p[i + 1]):
                ans += 1
        
        print(ans)

solver = BOrdinaryNumber()
input = sys.stdin.readline

solver.solve()

Submission status: Accepted

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

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

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):
    A = [P[i - 1], P[i], P[i + 1]]
    maxA = max(A)
    minA = min(A)
    if P[i] != maxA and P[i] != minA:
        cnt += 1
        
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
p = [int(x) for x in input().split()]

ans = 0
for i in range(1, len(p) - 1):
    a, b, c = p[i - 1:i + 2]
    if a < b < c or a > b > c:
        ans += 1

print(ans)

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ri = lambda: int(input())
#rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

n=ri()
p=list(rl())
ans = 0
for i in range(1,n-1):
    p1,p2,p3 = p[i-1],p[i],p[i+1]
    p123 = [p1,p2,p3]
    if p2 != max(p123) and p2 != min(p123):
        ans += 1

print(ans)

Submission status: Accepted

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

answer = 0
for i in range(len(p)-2):
	if p[i+1] > min(p[i], p[i+2]) and p[i+1] < max(p[i], p[i+2]):
		answer += 1

print(answer)

Submission status: Accepted

Solution code:

input()

x=list(map(int,input().split(' ')))

count=0

for i in range(1,len(x)-1):
    temp=sorted(x[i-1:i+2],reverse=True)
    if temp[1]==x[i]:
        count+=1

print(count)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split(" ")]
flag = False
cnt = 0
for i in range(1,N-1):
    if A[i-1]>A[i]:
        if A[i+1]<A[i]:
            flag = True
    else:
        if A[i+1]>A[i]:
            flag = True
    if flag:
        cnt+=1
        flag = False
print(cnt)

Submission status: Accepted

Solution code:
import sys
import statistics
input = sys.stdin.readline

n = int(input())
p = list(map(int, input().split()))
counter = 0
for i in range(1, n-1):
    lis = (p[i-1], p[i], p[i+1])
    mid = statistics.median(lis)
    if p[i] == mid:
        counter += 1

print(counter)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

p_list = P[:]

ans = 0
for a, b, c in zip(p_list[0:-2],p_list[1:-1],  p_list[2:]):
    x = [a, b, c]
    x = sorted(x)
    if x[1] == b:
        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+2] < 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):
    tmp=[p[i],p[i+1],p[i+2]]
    tmp.sort()
    if p[i+1]==tmp[1]:
        cnt+=1
print(cnt)

Submission status: Accepted

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

cnt = 0
for i, pi in enumerate(p[:-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
  elif p[i+2] < p[i+1] and p[i+1] == p[i]: cnt += 1
  elif p[i+2] < p[i+1] and p[i+1] < p[i]: cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def solve(N, P):
    c = 0
    for i in range(1,N-1):
        if P[i-1] < P[i] < P[i+1]:
            c += 1
        if P[i+1] < P[i] < P[i-1]:
            c += 1
    return c

N = int(input())
P = [int(x) for x in input().split()]
print(solve(N, P))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
p=list(map(int,input().split()))
a=1
c=0
while True:
    f=0
    x=p[a-1]
    y=p[a]
    z=p[a+1]
    if y>x and z>y:
        f=1
    if y>z and x>y:
        f=1
    if f==1:
        c=c+1
    a=a+1
    if a==n-1:
        break
print(c)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
n = int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
p = [int(i) for i in input().split()]
ans = 0
for x,y,z in zip(p,p[1:],p[2:]):
    ls = []
    ls.append(x)
    ls.append(y)
    ls.append(z)
    ls.sort()
    if ls[1] == y:
        ans += 1
print(ans)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

def solve():
    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+2] < l[i+1] < l[i]:
            ans += 1
    print(ans)
    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

# vim: set foldmethod=marker:}}}

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
for i in range(n-2):
    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:
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(1,n-1):
  l=a[i-1:i+2]
  if a[i]!=max(l) and a[i]!=min(l):
    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):
    if (p[i] < p[i+1] and p[i] > p[i-1]) or (p[i] > p[i+1] and p[i] < p[i-1]):
        cnt += 1

print(cnt)

Submission status: Accepted

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

ans = 0

for i in range(1, n-1):
  if ps[i-1] < ps[i] < ps[i+1]:
    ans += 1
  elif ps[i-1] > ps[i] > ps[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):
  A = P[i-1:i+2]
  #print(A)
  if max(A) > P[i] and min(A) < 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(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:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 29 20:53:06 2019

@author: Yamazaki Kenichi
"""

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] - p[i+1]) < 0:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lm = list(map(int,input().split()))
s = 0
for x in range(1,n-1):
    if (lm[x] > lm[x+1] and lm[x]<lm[x-1]) or(lm[x] > lm[x-1] and lm[x]<lm[x+1]):
        s += 1
    else:
        continue
print('{}'.format(s))

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

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

Submission status: Accepted

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

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

print cnt

Submission status: Accepted

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

cnt = 0
for i in range(1, len(P) - 1):
    if P[i] == sorted(P[i-1:i+2])[1]:
        cnt += 1

print(cnt)

Submission status: Accepted

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

count = 0
for i in range(1, n-1):
    if p[i] != max(p[(i-1):(i+2)]) and p[i] != min(p[(i-1):(i+2)]):
        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-1] < p[i] and p[i] < p[i+1]:
        counter += 1
    elif p[i-1] > p[i] and p[i] > p[i+1]:
        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] 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):
    a, b, c = p[i], p[i + 1], p[i + 2]
    if (b > a and b <= c) or (b <= a and b > c):
        ans += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
P = list(map(int,input().split(" ")))
c=0
for i in range(1,len(P)-1):
    #print(P[i-1],P[i],P[i+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())
ps = list(map(int, input().split(" ")))

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

print(count)

Submission status: Accepted

Solution code:
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

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

Submission status: Accepted

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

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

print(cnt)

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


main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    P = list(map(int, input().split()))
    count = 0
    for i in range(N-2):
        a = sorted(P[i:i+3])
        if a[1] == 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()))
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)