If a character from L is encountered , then the answer variable is incremented by the value obtained by using the mentioned formula and count is set to 0
if ( freq [ ( int ) ( x - ' a ' ) ] ) { ans += ( count * count + count ) / 2 ; count = 0 ; } else count ++ ; }