n = int(input()) a = [int(x) for x in input().split()] b = [x for x in a] ra, rb = 0, 0 m = 1000000000 for i in range(n-1): if (i % 2): if a[i+1] <= a[i]: ra += 1 a[i+1] = m if b[i+1] >= b[i]: rb += 1 b[i+1] = -m else: if b[i+1] <= b[i]: rb += 1 b[i+1] = m if a[i+1] >= a[i]: ra += 1 a[i+1] = -m print(min(ra, rb))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | n = int(input()) a = [int(x) for x in input().split()] b = [x for x in a] ra, rb = 0, 0 m = 1000000000 for i in range(n-1): if (i % 2): if a[i+1] <= a[i]: ra += 1 a[i+1] = m if b[i+1] >= b[i]: rb += 1 b[i+1] = -m else: if b[i+1] <= b[i]: rb += 1 b[i+1] = m if a[i+1] >= a[i]: ra += 1 a[i+1] = -m print(min(ra, rb)) |