Result

AC

Duration

1390ms

Code [DL]

sed '1h
1!{$!g
${x
:1
/T /{s/T /T/;x;s/K /K/;x}
t1
:2
/ T/{x;/K /{x;s/ T/T/;x;s/K /KK/};x}
t2
x}}'

stdin

               T                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
      K                                           

stdout

               T                                  
               T                                  
               T                                  
               T                                  
               T                                  
               T                                  
               T                                  
               T                                  
               T                                  
               T                                  
               T                                  
               T                                  
               T                                  
               T                                  
      KKKKKKKKKK

stderr

strace