Result

AC

Duration

2526ms

Code [DL]

x=`dd`.split('
')[..-2]
x.map{|s|puts s.sub(x[0].index('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              
                                   T              
                                   T              
                                   T              
                                   T              
                                   T              
                                   T              
                                   T              
     KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK              

stderr

3+1 records in
3+1 records out
1581 bytes (1.6 kB, 1.5 KiB) copied, 9.3363e-05 s, 16.9 MB/s

strace