Under construction

Still being built. Things may change

Making the Best Phone Number

Time limit2sMemory limit128 MB

Summary
Split a digit string into groups of 2 or 3 to maximize a score based on group types, then output the lexicographically smallest optimal formatting.
Level

Medium6 of 10

Topics
Dynamic programming, String, Greedy, Implementation
Solved
No attempts yet

Problem

Youngsik wants to share his new mobile phone number with friends in a form that is easy to remember. The phone number is a string of N digits, and it must be split with hyphens (-). Each group must contain exactly 2 or 3 digits.

Each group belongs to one of the following three types.

  1. O group: all digits in the group are the same. For instance, 000 and 77.
  2. G group: the group has length 3, and exactly two of its digits are the same. For instance, 030, 229, and 116.
  3. Z group: all digits in the group are different. For instance, 123 and 90.

The quality of a formatted phone number is defined as follows.

2 * (number of O groups) + (number of G groups)

Given Youngsik's phone number, output a valid formatting whose quality is as large as possible.

Input

The first line contains Youngsik's phone number.

The phone number consists only of digits from 0 to 9, and its length is between 2 and 1,000 inclusive.

Output

Output a valid formatting of the phone number with maximum quality.

Separate adjacent groups with hyphens (-). If there is more than one maximum-quality formatting, output the lexicographically smallest one. String comparison uses the following order.

- < 0 < 1 < 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9

Hint

For the first visible test, the phone number can be split in several ways.

  • 508-86-38: quality 0
  • 50-886-38: quality 1
  • 50-88-638: quality 2

Therefore the maximum-quality formatting is 50-88-638.

Examples5

  1. Example 1

    Input
    5088638
    Expected output
    50-88-638
    
  2. Example 2

    Input
    0123456789
    Expected output
    01-23-45-67-89
    
  3. Example 3

    Input
    09
    Expected output
    09
    
  4. Example 4

    Input
    54545454545454545454
    Expected output
    54-545-454-545-454-545-454
    
  5. Example 5

    Input
    00110001011100010111
    Expected output
    00-11-00-010-11-10-00-101-11