Compress

Time limit1sMemory limit128 MB

Summary
Given pairs F and R with F < R, print F and the shortest compressed form C that decodes back to R.
Level

Medium4 of 10

Topics
String, Implementation, Math
Solved
No attempts yet

Problem

Reduce the number of digits.

An experimental physicist generates a huge amount of data. The data has a special property, and he wants to exploit it to shrink the space needed to store the results.

The data comes as pairs of numbers where the first number is always smaller than the second. He wants to store each pair much the way people abbreviate a range of pages in a book: instead of writing "pages 11 through 18" they sometimes write "11-8".

Notation

SymbolMeaningExample
FFthe first number of a pairin "18482-02", F=18482F = 18482
CCthe second number in compressed formin "18482-02", C=02C = 02
RRthe second number in decoded (original) formin "18482-02", R=18502R = 18502
MSD(x,y)\text{MSD}(x, y)the xx most significant digits of yy in base ten; the empty string when x≤0x \le 0MSD(3,19283)=192\text{MSD}(3, 19283) = 192, MSD(0,12)\text{MSD}(0, 12) is empty
LSD(x,y)\text{LSD}(x, y)the xx least significant digits of yy in base ten, left-padded with zeros when neededLSD(2,48290)=90\text{LSD}(2, 48290) = 90, LSD(2,3)=03\text{LSD}(2, 3) = 03

Decoding a compressed second number

RuleExample
CC is always written with the fewest possible digits.
If C>FC > F, then R=CR = C.for "123-283": F=123F = 123, C=283C = 283, so R=283R = 283
If C≤FC \le F, apply the rules below.
LSD(len(C),R)\text{LSD}(\text{len}(C), R) always equals CC.
If LSD(len(C),F)<C\text{LSD}(\text{len}(C), F) < C, then RR is MSD(len(F)−len(C),F)\text{MSD}(\text{len}(F) - \text{len}(C), F) followed by the digits of CC.for "4137-223": F=4137F = 4137, C=223C = 223; MSD(1,4137)=4\text{MSD}(1, 4137) = 4, so R=4223R = 4223
If LSD(len(C),F)≥C\text{LSD}(\text{len}(C), F) \ge C, then RR is 10len(C)10^{\text{len}(C)} plus MSD(len(F)−len(C),F)\text{MSD}(\text{len}(F) - \text{len}(C), F) followed by the digits of CC.for "8543-13": F=8543F = 8543, C=13C = 13; MSD(2,8543)=85\text{MSD}(2, 8543) = 85, so R=8513+100=8613R = 8513 + 100 = 8613

Leading zeros in CC are significant: "7", "07" and "007" are all different. For example:

  • for "2839-06": F=2839F = 2839, C=06C = 06, so R=2906R = 2906
  • for "2839-006": F=2839F = 2839, C=006C = 006, so R=3006R = 3006

Your task is the reverse of decoding: given each uncompressed pair FF and RR, output the compressed second number CC using the fewest possible digits.

Input

Each line contains a pair of non-negative integers separated by a hyphen. The second number is always larger than the first, and the second number is always less than 231−12^{31} - 1. Read lines until end of file.

Output

For each input line, print one line containing the first number, a hyphen, and the compressed form of the second number.

Examples4

  1. Example 1

    Input
    10-18
    83294-84137
    100-200
    
    Expected output
    10-8
    83294-137
    100-00
    
  2. Example 2

    Input
    123-283
    4137-4223
    8543-8613
    
    Expected output
    123-283
    4137-23
    8543-13
    
  3. Example 3

    Input
    2839-2906
    2839-3006
    
    Expected output
    2839-06
    2839-006
    
  4. Example 4

    Input
    0-5
    5-15
    1-12
    
    Expected output
    0-5
    5-5
    1-12