#P1098. Flexible String Expansion

    ID: 13029 Type: Default 1000ms 256MiB

Flexible String Expansion

Flexible String Expansion

This problem extends the traditional "read-program, write-result" string expansion problem. You are given a string which may contain shorthand notations of the form c1-c2 where both c1 and c2 are either lowercase letters or digits. Such a substring is expanded under the following rules if and only if the ASCII code of c2 is strictly greater than that of c1:

  • If the characters are consecutive (i.e. \(c2 = c1 + 1\)), simply remove the hyphen.
  • Otherwise, expand by inserting the characters in between (i.e. those with ASCII codes from \(\mathtt{ord}(c1)+1\) to \(\mathtt{ord}(c2)-1\)).

The expansion is further controlled by three parameters:

  • p1: Expansion style. When p1 = 1, fill with lowercase letters (for letters). When p1 = 2, fill with uppercase letters (for letters). For digit ranges the expansion is identical regardless of p1. When p1 = 3, replace each character in the expansion with a star (*) character.
  • p2: The number of times each character in the expansion should be repeated.
  • p3: The order of the expansion. When p3 = 1, output in increasing order. When p3 = 2, output in reverse order. Note that the boundary characters (i.e. the characters adjacent to the hyphen) are never modified.

If the character immediately following the hyphen is exactly the successor of the character preceding the hyphen, you should simply remove the hyphen. Also, if the conditions for expansion are not met (for example, if the two sides are not both digits or both lowercase letters, or if the right character is not greater than the left), leave the hyphen as is.

Input Format:

The first line contains three integers p1, p2, and p3 separated by spaces. The second line contains the string to be processed.

Output Format:

Output the expanded string according to the rules described above.

Note: If there is no valid expansion candidate, output the string unchanged.

inputFormat

The first line contains three space-separated integers p1, p2, and p3. The second line contains a non-empty string s that may include hyphen shorthand notations.

outputFormat

Output the transformed string after processing all valid shorthand notations based on the given rules.

sample

1 3 1
a-d
abbbcccd