import io import os input=(io.BytesIO(os.read(0, os.fstat(0).st_size)).readline) n = int(input()) a = list(map(int,input().split())) def sgn(a): return -1 if a<0 else 1 if a>0 else 0 def calc(n,a,d): k = 0 b = a[0] for i in range(1,n): r = sgn(a[i]-b) if r != d: k += 1 b = 10000000*d else: b = a[i] d = -d return k print(min(calc(n,a,1),calc(n,a,-1)))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import io import os input=(io.BytesIO(os.read(0, os.fstat(0).st_size)).readline) n = int(input()) a = list(map(int,input().split())) def sgn(a): return -1 if a<0 else 1 if a>0 else 0 def calc(n,a,d): k = 0 b = a[0] for i in range(1,n): r = sgn(a[i]-b) if r != d: k += 1 b = 10000000*d else: b = a[i] d = -d return k print(min(calc(n,a,1),calc(n,a,-1))) |