Under construction

Still being built. Things may change

Two forms of a message

Time limit1sMemory limit1024 MB

Summary
Pack a brace-wrapped list of integers into a hexadecimal string by encoding zero runs and length prefixes, then print the result.
Level

Medium4 of 10

Topics
String, Implementation, Simulation
Solved
No attempts yet

Statement

Juku takes part in a student satellite project and is responsible for controlling the satellite with messages sent from the ground. A message is wrapped in a start mark and an end mark, '{' and '}', and contains integers separated by spaces. Worried about slow data links, Juku decides to give messages a shorter form.

A number written as text takes one byte, or 8 bits. A number written in hexadecimal takes only 4 bits. Some of the 16 hexadecimal digits can also be used to pack a message. (Hexadecimal uses 0…\ldots9 and A…\ldotsF as digits, where 0…\ldots9 have values 0…90 \ldots 9 and A…\ldotsF have values 10…1510 \ldots 15. The value of a two-digit hexadecimal number XYXY is 16⋅X+Y16 \cdot X + Y.)

Juku packs messages by these rules:

  1. The start mark is the hexadecimal digit E and the end mark is the hexadecimal digit F.
  2. If a number in the input message has 3 to 15 zeros in a row, replace them with the hexadecimal digit B, followed by the length of the zero run as a hexadecimal digit 3…\ldotsF. If the run is longer than 15, write B, then 0, then the length as two hexadecimal digits 10…\ldotsFF.
  3. Each number NN in the input message is written starting with the hexadecimal digit A. If the length of NN is at most 15, write A followed by the length as a hexadecimal digit 1…\ldotsF. If the length of NN is greater than 15, write A, then 0, then the length as two hexadecimal digits 10…\ldotsFF. In both cases, the digits of NN follow the length. If NN has more than two zeros in a row, pack them first by rule 2, and the length is the length of the packed result, not the length of the original number.
  4. If the packed message has an odd number of hexadecimal digits, append D at the end, after F.

Write a program that reads the message from the input file and writes the packed result in text form to the output file.

Input

The input file has exactly one line containing one message. The message has at most 100 positive integers, each less than 1025610^{256}.

Output

The output file has one line with the packed message in text form, where each hexadecimal digit is one character. The output is written this way so that a person can read it. If the hexadecimal digits were packed into real bytes, the result would be hard to read.

Examples1

  1. Example 1

    Input
    { 10 555 2000 79 }
    
    Expected output
    EA210A3555A32B3A279F