If some character appears more than once all of its occurrences except 1 can be traded for some gain
elif occurrences [ i ] > 1 : NEW_LINE INDENT gain += cost [ i ] * ( occurrences [ i ] - 1 ) NEW_LINE DEDENT