Result

AC

Duration

736ms

Code [DL]

# stdin | map({x -> [1,x]}) | stdout
# stdin | map({x -> [1,x.split("K").length]}) | stdout
# stdin | map({x -> "H" + x + "R"}) | stdout
# stdin | map({x -> x.chars}) | stdout

# stdin | reduce(0,{x,y -> [1,x]}) | stdout
# stdin | reduce(0,{x,y -> [2,y]}) | stdout

fst = {case [p,q] -> p}
snd = {case [p,q] -> q}
addc = {case [i,s] -> if(i==0){ "" }else{ addc([i-1,s])+s }}

stdin | reduce([0,"",""],{
  case [b,c,d],s -> if(b==0){
     [1,s,s]
  }else{
     if(s.split("K").length >= 2){
       lt = fst(c.split("T")).length;
       lk = fst(s.split("K")).length;
       la = addc([lt-lk+1,"A"]);
       tc = d+"\n"+fst(s.split("K"))+la;
       tc
     }else{
       [1,c,d+"\n"+c]
     }
  }
}) | stdout

stdin

                                           T      
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                 K                                

stdout

                                           T      
                                           T      
                                           T      
                                           T      
                                           T      
                                           T      
                                           T      
                                           T      
                                           T      
                                           T      
                                           T      
                                           T      
                                           T      
                 AAAAAAAAAAAAAAAAAAAAAAAAAAA

stderr

strace

11    execve("/bin/sh", ["/bin/sh", "/root/script", "/volume/CODE"], 0x7ffdc4e7ae40 /* 7 vars */) = 0
13    execve("/usr/bin/streem", ["/usr/bin/streem", "/volume/CODE"], 0x555c66b5fd40 /* 7 vars */) = 0
12    execve("/bin/cat", ["cat", "-"], 0x555c66b5fd30 /* 7 vars */) = 0
12    +++ exited with 0 +++
11    --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=12, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
16    +++ exited with 0 +++
14    +++ exited with 0 +++
15    +++ exited with 0 +++
13    +++ exited with 0 +++
11    --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=13, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
11    +++ exited with 0 +++