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


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
#
import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Runtime Error

Solution code:
#ABC132 B

n = int(input())
K = 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]):
        K += 1
        
print(K)

Submission status: Runtime Error

Solution code:
n = int(input())
K = 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]:
        K += 1
        
print(K)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
p = 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: Runtime Error

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

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: Runtime Error

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

Submission status: Runtime Error

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

ans = 0

for i in range(N-2):
  if P[i] > P[i+1] and P[i+1] > P[i+2] or P[i] < P[i+1] and P[i+1] < P[i+2] or :
    ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
# Vicfred
# https://atcoder.jp/contests/abc132/tasks/abc132_b
# implementation
n = int(input())
p = list(map(int,input()))

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

print(answer)

Submission status: Runtime Error

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


count = 0
for i in range(n):
        if min(L[i],L[i+2]) < L[i+1] < max(L[i], L[i+2]):
            count += 1
            if i+2 == n - 1:
                break
print(count)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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+1],p[i+2]) == p[i+1]:
        count += 1

print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

print(cnt)

Submission status: Runtime Error

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: Runtime Error

Solution code:
n=int(input())
p=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
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
p_list = [int(s) for s in input.split()]

cnt = 0

for i in range(1,N-1):
  if p_list[i-1] < p_list[i] and p_list[i] < p_list[i+1]
  	cnt += 1

  if p_list[i+1] < p_list[i] and p_list[i] < p_list[i-1]
  	cnt += 1
    
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
if n == 1:
  p = int(input())
else:
  p = list(map(input().split()))
i = 1
cnt = 0
while i < len(p):
  if p[i] > p[i - 1] and p[i] < p[i + 1] :
    cnt += 1
  i += 1

Submission status: Runtime Error

Solution code:
n = int(input())
p = list(map(input().split()))
i = 1
cnt = 0
while i < len(p):
  if p[i] > p[i - 1] and p[i] < p[i + 1] :
    cnt += 1
  i += 1

Submission status: Runtime Error

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

import numpy
p = np.array(p)
cnt = 0
for i in range(1, n-1):
    pi = np.array(p[i-1:i+2])
    #print(pi)
    if np.argsort(pi)[1] == 1:
        cnt += 1
print(cnt)

Submission status: Runtime Error

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

import numpy
p = np.array(p)
cnt = 0
for i in range(1, n-1):
    pi = np.array(p[i-1:i +2])
    #print(pi)
    if np.argsort(pi)[1] == 1:
        cnt += 1
print(cnt)

Submission status: Runtime Error

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

  count = 0
  p1 = P[0]
  p2 = P[1]
  for i in range(2, n):
    p3 = P[i]
    if p1 < p2 < p3 or p1 > p2 > p3:
      count += 1
    p1 = p2
    p2 = p3

main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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: Runtime Error

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

Submission status: Runtime Error

Solution code:

n = int(input())
P = [i for i in range(n)]
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: Runtime Error

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

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

Submission status: Runtime Error

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

count = 0
for i in range(1, len(lstp)-1):
    lst = list(lstp[i-1], lstp[i], lstp[i+1])
    if (min(lst) != lstp[i]) and (max(lst) != lstp[i]):
        count = count + 1

print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, *L,  = [list(map(int, s.split())) for s in open(0)]
A = L[0]
p
cnt = 0
for i in range(len(A) - 2):
    ma = max(A[i], A[i+1], A[i+2])
    mi = min(A[i], A[i+1], A[i+2])
    if A[i+1] not in [ma, mi]:
        cnt += 1
print(cnt)

Submission status: Runtime Error

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

count=0

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

print(count)

Submission status: Runtime Error

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

ans = 0

#+2まで考慮してるから、nの数を-2にして調整しろ
for i in range(n):
	if p[i] < p[i + 1] < p[i + 2] or p[i + 2] < p[i + 1] < p[i]:
		ans = ans + 1

print(ans)

Submission status: Runtime Error

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

count = 0

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

Submission status: Runtime Error

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

count = 0

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

Submission status: Runtime Error

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

count = 0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
Pn = list(input().split(' '))

count_pn = 0
for i in range(1,N-1):
    if ( Pn[i-1] <= Pn[i] and Pn[i] < Pn[i+1] ) or ( Pn[i+1] <= Pn[i] and Pn[i] < Pn[i-1] ):
        count_pn += 1
print(count_pn)


S = list(input())
S.sort()

if S[0] == S[1] and S[2] == S[3] and S[1] != S[2]:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
input();a=0
print([sorted(i)[1]==i[1]for i in [list(map(int,input().split()))[i:i+3] for i in range(len(list(map(int,input().split())))-4)]].count(True))

Submission status: Runtime Error

Solution code:
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([1, 3, 5, 4, 2]), 2)

    def test_2(self):
        self.assertEqual(think([9, 6, 3, 2, 5, 8, 7, 4, 1]), 5)


def solve():
    p = read()
    result = think(p)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(data):
    n = len(data)
    count = 0
    for i in range(n):
        if i + 2 >= n:
            break
        if data[i] < data[i + 1] < data[i + 2]:
            count += 1
    return count


def write(result):
    print(result)


if __name__ == '__main__':
    unittest.main()
    # solve()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n=input()
l=[map(int,input().strip().split())]
ans=0
for i in range(1,len(l)-2):
  gc=0;
  lc=0;
  if(l[i] >l[i-1] or l[i]>l[i+1]):
    gc=1
  if(l[i] <l[i-1] or l[i]<l[i+1]):
    lc=1
   ans+=gc & lc

Submission status: Runtime Error

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

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

    
print(m)

Submission status: Runtime Error

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

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

    
print(m)

Submission status: Runtime Error

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

a = 0

for i in range(n - 1):
  p_l = [p[i], p[i + 1], p[i + 2]]
  p_l2 = sorted(p_l)
  if p_l2[1] == p_l[1]:
    a += 1
    
print(int(a))

Submission status: Runtime Error

Solution code:
#

from bisect import bisect

for _ in range(int(input())):
    N, D = map(int, input().split())
    P = list(map(int, input().split()))
    swaps = 0
    possible = True
    for m in range(D):
        order = []
        for i in range(m, N, D):
            if (P[i]-(i+1)) % D:
                possible = False
                break
            idx = bisect(order, P[i])
            swaps += len(order) - idx
            order.insert(idx, P[i])
    if possible:
        print(swaps)
    else:
        print(-1)

Submission status: Runtime Error

Solution code:
n = int(input())

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

co = 0

for i in range(1,len(li)-1):
  work = sort([li[i-1],li[i],li[i+1]])

  if work.index(li[i]) == 1:
    co += 1
print(co)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
p = [int(i) for i in range(n)]
s = 0
for i in range(1,n-1):
  l1 = p[i-1,i+2]
  l2 = l1.copy()
  l2.sort()
  if l1[1] == l2[2]:
    s += 1
print(s)

Submission status: Runtime Error

Solution code:
n,*p=[int(t.split())for t in open(0)]
print(sum([(p[i+1]-p[i])*(p[i]-p[i-1]) < 0 for i in range(1,n)]))

Submission status: Runtime Error

Solution code:
n = int(input())
p = list(map(int,input().split()))
for x in range(N-2):
  for y in range(x+1,x+1):
    for z in range(x+2,x+2):

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(intput())
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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

n = int(input())
p = getlist()

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
	else:
		pass

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
Ps = 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: Runtime Error

Solution code:
#5
#1 3 5 4 2
#2
N=int(input())
num=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: Runtime Error

Solution code:
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
inputb = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

listb = []
listb = [int(n) for n in inputb]

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

pritn(cnt)

Submission status: Runtime Error

Solution code:
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
inputb = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

listb = []
listb = [int(n) for n in inputb]

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

pritn(cnt)

Submission status: Runtime Error

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=count+1
print(count)

n

Submission status: Runtime Error

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=count+1
print(count)

Submission status: Runtime Error

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=count+1
print(count)

Submission status: Runtime Error

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=count+1
print(count)

Submission status: Runtime Error

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=count+1
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
p = [int(x) for x in 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=count+1
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
p = [int(x) for x in input().split()] 
count=0
for i in p
	if p[i]>p[i+1]>p[i+2] or p[i+2]>p[i+1]>p[i]:
    	count=count+1
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

num = 0
for i in range(n):
    list_i = P[i:i+3]
    if list_i[1] == sorted(list_i)[-2]:
        num += 1
    else:
        num += 0

print(num)

Submission status: Runtime Error

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

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

print(c)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

def count(ps):
    if len(ps) <= 2:
        return 0
    qs = sorted(ps[0:3])
    res = 1 if qs[1] == ps[1] else 0
    return res + count(ps[1:])

print(count(ps))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#ABC132 A
S = list(input())
S.sort()
if S[0] == S[1] and S[2] == S[3] and S[0] != S[2]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
seq_str = input().split(" ")
seq = [int(s) for s in seq_str]
counter = 0

for i in range(1,n-1):
    if seq[i-1] < sqe[i] and seq[i] < seq[i+1]
    counter =+ 1
print(counter)

Submission status: Runtime Error

Solution code:
n = int(input())
P = [int(input()) for _ in range(n)]
count = 0
for i in range(1, n-1):
  A = [P[i-1], P[i], P[i+1]]
  sort = sorted(A)
  if sort[1] = A[1]:
    count = count + 1

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
P = [int(input()) for _ in range(n)]
count = 0
for i in range(1, n-1):
  A = [P[i-1], P[i], P[i+1]]
  sort = sorted(A)
  if sort[-1] = A[1]:
    count++

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
P = [int(input()) for _ in range(n)]

for i in range(1, n-1):
  A = [P[i-1], P[i], P[i+1]]
  sort = sorted(A)
  if sort[-1] = A[1]:
    count++

print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

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: Runtime Error

Solution code:
import sys
n = int(sys.stdin.readline())
p = list(int(sys.stdin.readline().rstrip().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)