main=interact$unlines.s(((f.span(<'J')).).zipWith max).lines f(x,y)=x++s max y s=scanr1