sysconf zero_based
# 
trees[] = [ ]
len offs[] 32
offs[1] = 1
proc append t . .
   v = bitor 1 bitshift t 1
   trees[] &= v
.
proc show t l . .
   while l > 0
      l -= 1
      if t mod 2 = 1
         write "("
      else
         write ")"
      .
      t = t div 2
   .
.
proc list n . .
   for i = offs[n] to offs[n + 1] - 1
      show trees[i] n * 2
      print ""
   .
.
proc assemble n t sl pos rem . .
   if rem = 0
      append t
      return
   .
   if sl > rem
      sl = rem
      pos = offs[sl]
   elif pos >= offs[sl + 1]
      sl -= 1
      if sl = 0
         return
      .
      pos = offs[sl]
   .
   h = bitor bitshift t (2 * sl) trees[pos]
   assemble n h sl pos rem - sl
   assemble n t sl pos + 1 rem
.
proc make n . .
   if offs[n + 1] <> 0
      return
   .
   if n > 0
      make n - 1
   .
   assemble n 0 n - 1 offs[n - 1] n - 1
   offs[n + 1] = len trees[]
.
proc test n . .
   append 0
   make n
   print "Number of " & n & "-trees: " & offs[n + 1] - offs[n]
   list n
.
test 5
