a=[1] f=->x{a[x]||=x*f[x-1]} gets $<.map{|l|eval'D,X,T='+l.split*?, puts T