Result

AC

Duration

1090ms

Code [DL]

<?php
$b=0;$d=1;while($c=fread(STDIN,1)){$d*=$c!='T';$b=$c=='K'||$b&&$d;echo(!$d||$b?'A':$c);$d=($d+1)%51;}

stdin

                                            T     
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                      K           

stdout

                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                            A     
                                      AAAAAAA     

stderr

strace