% is a part of the array or the rest of the array
I define my notation B(@{1}%) in the following recursive way:
B(a{1}%) = a
B(a,b{1}2) = B(a,b,b,...,b,b) with b entries
B(a,b{1}%) = B(a,b,b,...{1}%,k-1) where k is the last entry in %.
B(a,b,c{1}2) = B(a,b-1,B(a,b,c-1){1}2)
B(a,b,c@{1}n) = B(a,b-1@,B(a,b,c-1@){1}n)
B(a,b,c@{1}n,m) = B(a,b-1@,B(a,b,c-1@){1}B(B(a,b-1@,B(a,b,c-1@){1}...B(a,b-1@,B(a,b,c-1@){1}B(B(a,b-1@,B(a,b,c-1@){1}m))...)))) with n recursions
B(a,b,c@{1}%) = B(a,b-1@,B(a,b,c-1@){1}%,B(B(a,b-1@,B(a,b,c-1@){1}%,...B(a,b-1@,B(a,b,c-1@){1}%,B(B(a,b-1@,B(a,b,c-1@){1}%))...)))) with k recursions, where k is the last entry in %.
If there is a 1 in the array, use the same process as LAN.