by@k_hanazuki
AC
880ms
say $/=get;$!=.index('K'),say $!??.subst('K','R'x$/.index("T")-$!+1)!!$/for lines
T K
T T T T T T T T T T T T T T T T T T T T T T T T T T RRRRRRRRRRRRRRRRRR