Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- a = list(map(int, input().split()))
- if n <= 1:
- print('0')
- raise SystemExit(0)
- i = 1
- while i < n and a[i - 1] == a[i]:
- i += 1
- if i == n:
- print(n - 1)
- raise SystemExit(0)
- ans = i - 1
- if a[i - 1] < a[i]:
- er = 1
- else:
- er = 2
- while i < n:
- j = i + 1
- if er == 1:
- while j < n and a[j - 1] <= a[j]:
- j += 1
- ans += j - i - 1
- er = 2
- else:
- while j < n and a[j - 1] >= a[j]:
- j += 1
- ans += j - i - 1
- er = 1
- i = j
- print(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement