Result

AC

Duration

921ms

Code [DL]

<?php
for($d=1;$c=fgetc(STDIN);$d=-~$d%51)echo!($d*=$c!='T')|($b=$c=='K'|$b*$d)?'A':$c;

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                            
     AAAAAAAAAAAAAAAAA                            

stderr

PHP Notice:  Undefined variable: b in /volume/CODE on line 2

strace