Result

AC

Duration

2548ms

Code [DL]

x=`dd`.split '
';x[..-2].map{|s|puts s.sub(x[0]=~/T/||0,'T').sub /K *T/{|y|"K"*y.size}}

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                                    
         KKKKK                                    

stderr

2+1 records in
2+1 records out
1224 bytes (1.2 kB, 1.2 KiB) copied, 0.000102128 s, 12.0 MB/s

strace