Result

AC

Duration

753ms

Code [DL]

open String
let rec r s=let t=read_line()in s^"\n"^try let p=index t 'K'in make p ' '^make(index s 'T'-p+1)'*'with _->r s;;print_string(r(read_line()))

stdin

            T                                     
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
        K                                         

stdout

            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                                     
            T                                     
            T                                     
            T                                     
            T                                     
            T                                     
            T                                     
            T                                     
            T                                     
            T                                     
            T                                     
            T                                     
            T                                     
            T                                     
        *****

stderr

strace