"Almonds? Oh yeah, I have tried those before. Covered in chocolate." Dudu, 2015.
Dudu is getting in shape for a trip to Thailand, so he weighs himself every morning.
Some stretches of days are good, with the weight going down day after day. Some are bad, with the weight going up day after day. Others are just weird.
An interval of measurements is weird if it alternates between going up and going down. For example, if the measurements on consecutive days are 1, 3, 2, 5, 1, that interval is weird. The measurements 1, 3, 5, 4 are not weird, because the value goes up from 1 to 3 and then up again from 3 to 5. Two neighbouring measurements that are equal go neither up nor down, so an interval holding two equal neighbours is not weird unless its length is 1. Every interval of length 1 is weird.
Given the sequence of measurements, count the weird intervals. Two intervals at different positions count separately even when they hold the same values.