Result

AC

Duration

695ms

Code [DL]

/T/{t=index($0,"T");s=$0}/K/{for(s=substr($0,1,t);sub(/K /,"KK",s););}$0=s

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

stderr

strace