Result

AC

Duration

2598ms

Code [DL]

puts (s=`dd`).gsub(/
.{#{s=~/T/}}/,"\\0T").sub /K */{|y|"K"*y.size}

stdin

                            T                     
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
               K                                  

stdout

                            T                     
                            T                      
                            T                      
                            T                      
                            T                      
                            T                      
                            T                      
                            T                      
                            T                      
               KKKKKKKKKKKKKT                      

stderr

0+1 records in
0+1 records out
510 bytes copied, 0.000269022 s, 1.9 MB/s

strace