<s>[INST] Arrangement without any monotone section 
Here's the question:
"In how many ways can the sequence 45678 be arranged such that there aren't any three consecutive terms increasing or decreasing"

The first thing I thought of is to do complementary counting and then make cases for each number of consecutive terms that there could be (3, 4, 5).
However there's a lot of overlap between the three cases and I'm not sure how to deal with that in an efficient way. If someone could solve it and then tell me how they did it that would be great.
 [/INST] My simple Python script enumerates them as
(4, 6, 5, 8, 7)
(4, 7, 5, 8, 6)
(4, 7, 6, 8, 5)
(4, 8, 5, 7, 6)
(4, 8, 6, 7, 5)
(5, 4, 7, 6, 8)
(5, 4, 8, 6, 7)
(5, 6, 4, 8, 7)
(5, 7, 4, 8, 6)
(5, 7, 6, 8, 4)
(5, 8, 4, 7, 6)
(5, 8, 6, 7, 4)
(6, 4, 7, 5, 8)
(6, 4, 8, 5, 7)
(6, 5, 7, 4, 8)
(6, 5, 8, 4, 7)
(6, 7, 4, 8, 5)
(6, 7, 5, 8, 4)
(6, 8, 4, 7, 5)
(6, 8, 5, 7, 4)
(7, 4, 6, 5, 8)
(7, 4, 8, 5, 6)
(7, 5, 6, 4, 8)
(7, 5, 8, 4, 6)
(7, 6, 8, 4, 5)
(7, 8, 4, 6, 5)
(7, 8, 5, 6, 4)
(8, 4, 6, 5, 7)
(8, 4, 7, 5, 6)
(8, 5, 6, 4, 7)
(8, 5, 7, 4, 6)
(8, 6, 7, 4, 5)
so there are $32$
</s>