There are n mountains in a row, with their heights given by an array h. You are planning a hang gliding route and want to find the longest possible trip, measured by the number of mountains visited.
A trip consists of a sequence of glides. You can start your trip at any mountain. From a mountain a at index i, you can glide to a mountain b at index j if and only if:
Mountain a is strictly taller than mountain b (h[i] > h[j]).
All mountains physically located between a and b are also strictly shorter than mountain a.
A route can change direction. For example, a valid route could be starting at mountain i, gliding left to mountain j, and then gliding left again to mountain k. Another valid route could start at i, glide right to j, and then glide right again. A third valid route could involve a path that goes left from a peak and a path that goes right from the same peak.
Your task is to find the maximum number of distinct mountains that can be visited in a single continuous route.
Input Format:
The first line contains a single integer n, the number of mountains.
The second line contains n space-separated integers, h_1, h_2, ..., h_n, representing the heights of the mountains.
Output Format:
Print a single integer representing the maximum number of mountains that can be visited.
Note:
This problem can be modeled as finding the longest path in a Directed Acyclic Graph (DAG), where mountains are nodes and valid glides are edges.