for(;r=readline()+1;)print.apply(0,[r.match('\\w*'+w)+(x-1?x:'')for each(w in'mgsAKld')if(x=0,[x+=+q||++q|0 for each([q]in r.split(w))],x)])