def aup(n,k,i,l): #Recursive formula for |Av_n( (123,{2},{}) , (123,{},{1}) )| if i > l or k > n or i > k or l > k: #aup => max is ceiling point, abar => max is L-R min, adown => max is neither return 0 if i < l or l <= 0: return 0 if n - k == 1: return 1 if i == 1: return sum( abar(n-1,k,1,m) for m in [0..k] ) return sum( abar(n-1,k,1,m) for m in [l..k] ) + sum( sum( adown(n-1,k,j,m) for m in [i..k]) for j in [1..i-1] ) def abar(n,k,i,l): if i <> 1: return 0 if n - k == 0: if l == 0: return 1 return 0 if k > n or i > k or l > k or i > l: return 0 return sum( a(n-1,k-1,j,l-1) for j in [1..k-1] ) def adown(n,k,i,l): if i > l or k > n or i > k or l > k: return 0 return sum( aup(n-1,k,j,l) + adown(n-1,k,j,l) for j in [i..k] ) def a(n,k,i,l): return aup(n,k,i,l) + abar(n,k,i,l) + adown(n,k,i,l) def A(n,k): if k > n: return 0 return sum( sum( a(n,k,j,m) for m in [0..k] ) for j in [1..k] ) def FA(n): return sum( A(n,k) for k in [1..n] )