
FORMULA

If x appears after x1 then we say that x is a ceiling point.
aup(n,k,i,l) = sum( sum( adown(n1,k,j,m) for m in [i+1..k] ) for j in [1..i] )
if i = 1 and l > i: adown(n,k,i,l) = aup(n1,k,l,l) + sum( adown(n1,k,j,l) for j in [i+1..k] ) + sum( a(n1,k1,j,l1) for j in [1..k1] )
if i = 1 and l <= 1: adown(n,k,i,l) = sum( adown(n1,k,j,l) for j in [i+1..k] ) + sum( a(n1,k1,j,l1) for j in [1..k1] )
if i > 1 and l > i: adown = aup(n1,k,l,l) + sum( adown(n1,k,j,l) for j in [i+1..k] )
otherwise: adown(n,k,i,l) = sum( adown(n1,k,j,l) for j in [i+1..k] )
a(n,k,i,l) = aup(n,k,i,l) + adown(n,k,i,l)
where n is the length, k is the number of left to right minima, i is the position of the maximum, l is the position of the first ceiling point where if l = 0 there is no ceiling point (notice positions are in relation the position of the left to right minima).
aup implies the maximum is a ceiling point and adown implies the maximum is not a ceiling point.
Initial Conditions: if k > n or i > k or i > l then aup(n,k,i,l)  adown(n,k,i,l) = 0, if i > l then aup(n,k,i,l) = 0, and finally aup(n,n1,i,l) = 1.
a(n) = sum( sum( sum( a(n,k,j,m) for m in [1..k] ) for j in [1..k] ) for k in [1..n] )
