#by Charlie Neder, Sep 18 2018
#Gives S() hierarchical sequences (cf. A059133, A059138)
#Currently does not support W'

E = lambda n : 2**n - n - 1

def A(n,star): #product of areas
..prod = 1
..for i in n:
....prod *= (2**i - 1)
....if not star: prod *= i
..return prod

def S(arr,term,star): #recursively breaks down the sequence
..if len(arr):
....return E(term)*A(arr,star) + (2**term - 1)*S(arr[1:],arr[0],star)
..else: return E(term+1)

for i in range(1,11):
..print(S([2],i,star=False))   #A059133
..print(S([3],i,star=False))   #A059135
..print(S([2,2],i,star=False)) #A059138
..print(S([2],i,star=True))    #A059140
..print(S([3],i,star=True))    #A059142
..print(S([2,2],i,star=True))  #A059145