cswork / OAOpen practice workspace

AmazonOA #371

Get Min Cost Data

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & HeapsGreedyStrings

Fill every ? with a lowercase letter. The cost of each position is the number of times the same letter appears before it. First minimize the total cost, then make the whole result lexicographically smallest.

Input

One line containing data. The original bounds are 1≤length≤100000, with at least one ?, and every other character in a..z.

Output

Output the complete filled-in lowercase string.

Example 1

Input:

aaaa?aaaa

Output:

aaaabaaaa

Example 2

Input:

abcd?

Output:

abcde

Example 3

Input:

?a?cdefghijklmnopqrstuvwxyz

Output:

aabcdefghijklmnopqrstuvwxyz

Example notes

The outputs are aaaabaaaa, abcde and aabcdefghijklmnopqrstuvwxyz. In the third example you cannot fill the letters directly in the order the min-heap picks them; the chosen a and b must be sorted into the question-mark positions.

Editorial

Loading solution…