t = int(input()) sounds = [int(x) for x in input().split()] sounds_1 = sounds.copy() result_down = 0 for i in range(1, t - 1): if min(sounds_1[i + 1], sounds_1[i - 1]) <= sounds_1[i] <= max(sounds_1[i + 1], sounds_1[i - 1]): sounds_1[i] = -10e9 result_down += 1 result_up = 0 sounds_2 = sounds.copy() for i in range(1, t - 1): if min(sounds_2[i + 1], sounds_2[i - 1]) <= sounds_2[i] <= max(sounds_2[i + 1], sounds_2[i - 1]): sounds_2[i] = 10e9 result_up += 1 print(min(result_down, result_up))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | t = int(input()) sounds = [int(x) for x in input().split()] sounds_1 = sounds.copy() result_down = 0 for i in range(1, t - 1): if min(sounds_1[i + 1], sounds_1[i - 1]) <= sounds_1[i] <= max(sounds_1[i + 1], sounds_1[i - 1]): sounds_1[i] = -10e9 result_down += 1 result_up = 0 sounds_2 = sounds.copy() for i in range(1, t - 1): if min(sounds_2[i + 1], sounds_2[i - 1]) <= sounds_2[i] <= max(sounds_2[i + 1], sounds_2[i - 1]): sounds_2[i] = 10e9 result_up += 1 print(min(result_down, result_up)) |