#!ruby -pl _=o=[] gsub(/./){x=86%$&[0]&67 _+=[x<4?[0,1].map{|i|x-i>o.pop&66?"(#{_.pop})":_.pop}.reverse*$&:$&] o<