by@akouryy1
AC
803ms
a,*b,c=*$<;puts a,b.map{a},' '*(g=c=~/K/)+?a*(1-g-=a=~/T/)
T K
T T T T T T T T T T T T T T T aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa