Determine the Widest Valley Imagine we get a slice of some mountainous region, this would result in a shape similar to this:

4                   _
3   _    _       __/ \
2  / \__/ \    _/     \_   /
1 /        \  /         \_/
0           \/
  12322223210012233343221112


As we can see, we can represent this (to a certain degree) with a sequence of integers.

For the purpose of this challenge we define a valley as a contiguous subsequence where the values initially are decreasing and from some point on they are increasing. More formally for a sequence \$(a_i)_{i=1}^n\$ a valley will be indices \$1 \leq s &lt; r &lt; t \leq n\$ for which the following holds:


the valley's start and endpoint are the same: \$a_s = a_t\$
the valley starts and ends once the region gets lower: \$a_s &gt; a_{s+1} \land a_{t-1} &lt; a_t\$
the valley is not flat: \$a_s \neq a_r \land a_r \neq a_t\$
the valley initially decreases: \$\forall i \in [s,r): a_i \geq a_{i+1}\$
the valley will at some point increase: \$\forall j \in [r,t): a_j \leq a_{j+1}\$


Now we define the width of such a valley as the size of the indices \$[s,t]\$, ie. \$t-s+1\$.

Challenge

Given a height-profile (sequence of non-negative integers), your task is to determine the width of the widest valley.

Example

Given the height-profile [1,2,3,2,2,2,2,3,2,1,0,0,1,2,2,3,3,3,4,3,2,2,1,1,1,2], we can visualize it as before:

4                   _
3   _    _       __/ \
2  / \__/ \    _/     \_   /
1 /        \  /         \_/
0           \/
  12322223210012233343221112
    aaaaaa             ccccc
         bbbbbbbbb


Note how the second valley [3,2,1,0,0,1,2,2,3] does not extend further to the right because the left-most point is \$3\$ and not \$4\$. Furthermore we don't add the remaining two \$3\$s because we require that the endpoint is higher up than the second-last point.

Therefore the width of the widest valley is \$9\$.

Rules


Input will be a sequence of non-negative (sorry Dutch people) integers


you can assume that there is always at least one valley

Output will be the size of the widest valley as defined above


Testcases

[4,0,4] -&gt; 3
[1,0,1,0,1] -&gt; 3
[1,0,2,0,1,2] -&gt; 4
[13,13,13,2,2,1,0,1,14,2,13,14] -&gt; 4
[1,2,3,2,2,2,2,3,2,1,0,0,1,2,2,3,3,3,4,3,2,2,1,1,1,2] -&gt; 9
[3,2,0,1,0,0,1,3] -&gt; 4
Python 2, 120 115 89 87 86 152 149 bytes



lambda a:max(r-l+1for l,v in e(a)for r,w in e(a)if max(a[l+1:r]+[0])&lt;v==w*any(s(a[l:i])[::-1]+s(a[i:r])==a[l:r]for i,_ in e(a)));e=enumerate;s=sorted


Try it online!