def calculate_changes(a): errors = 0 is_positive_number = a[0] >= 0 for i in range(0, len(a)-1, 2): if is_positive_number and a[i] - a[i+1] <= 0: errors += 1 is_positive_number = False continue if not is_positive_number and a[i] - a[i + 1] >= 0: errors += 1 is_positive_number = True return errors n = int(input()) __a = input().split() a = [int(number) for number in __a] print(calculate_changes(a))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | def calculate_changes(a): errors = 0 is_positive_number = a[0] >= 0 for i in range(0, len(a)-1, 2): if is_positive_number and a[i] - a[i+1] <= 0: errors += 1 is_positive_number = False continue if not is_positive_number and a[i] - a[i + 1] >= 0: errors += 1 is_positive_number = True return errors n = int(input()) __a = input().split() a = [int(number) for number in __a] print(calculate_changes(a)) |