Result

AC

Duration

782ms

Code [DL]

f={case[p,q]->p}
g={i,s->if(i>0)g(i-1,s)+s else""}
stdin|reduce(["",""],{case[c,d],s->if(c.length>0){v=s.split("K");if(v.length>=2)d+c+v.f+g(c.split("T").f.length-f(v).length+1,"A")else[c,d+c]}else[s+"\n",d]})|stdout

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                  
                               T                  
                               T                  
                               T                  
                               T                  
                               T                  
                               T                  
                               T                  
                               T                  
                               T                  
                        AAAAAAAA

stderr

strace

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