Mingyeom Numbers
Time limit1sMemory limit1024 MB
Split a string of M and K into valid Mingyeom digits so that the concatenated decimal values are maximized and minimized.
- Level
Medium6 of 10
- Topics
- String, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Mingyeom found Roman numerals very interesting. So he created a new number system, the Mingyeom numbers.
For a nonnegative integer N, a Mingyeom digit writes a decimal number of the form 10N or 5 × 10N as a string of uppercase M and K. A decimal number of the form 10N is written as N + 1 copies of M, and a decimal number of the form 5 × 10N is written as N copies of M followed by one K. That is, they can be written as in the table below.
A Mingyeom number is made by concatenating one or more Mingyeom digits. For example, the Mingyeom number MKKMMK can be made by concatenating the three Mingyeom digits MK, K, and MMK.
To convert a Mingyeom number to a decimal number, split the string into one or more Mingyeom digits, convert each Mingyeom digit to a decimal number, and concatenate the results in order. Converting a Mingyeom digit to a decimal number is the reverse of converting a decimal number to a Mingyeom digit. For example, the Mingyeom number MKKMMK can be converted to several decimal numbers as shown in the figure below.

Mingyeom realized that a single Mingyeom number can be converted to various decimal numbers. He became curious about the largest and smallest values among the decimal numbers it can be converted to. For Mingyeom, find the maximum and minimum values that a single Mingyeom number can have when converted to a decimal number.
Input
One Mingyeom number is given. A Mingyeom number is a string consisting only of uppercase M and K, and its length does not exceed 3,000.
Output
Print the largest and smallest values that the given Mingyeom number can have when converted to a decimal number, each on its own line.