Stack to maintain the order of characters after removal of substrings
for i in range ( N ) : NEW_LINE INDENT if ( str [ i ] == ' p ' ) : NEW_LINE INDENT countP += 1 NEW_LINE DEDENT elif ( str [ i ] == ' r ' ) : NEW_LINE DEDENT