Folded Numbers X43287


Statement
 

pdf   zip

You have to compute the value of “folding” a number. “Folding” a number nn is an operation shown in the following figure (open the PDF if you can’t see the figure correctly on the Jutge web page).

In particular, any number nn can be considered a sequence of digits and be divided into two subsequences of consecutive digits aa and bb, be they of the same length, or alternatively of lengths differing only in one unit (including the case where aa or bb are empty). Concatenating these two halves aa and bb we would recover the original number nn.

Then, to compute the "folding" operation, we invert the order of the aa subsequence, which we will call ainva_{inv}, and, interpreting ainva_{inv} and bb as numbers once again, add them together to obtain the result of "folding".

As an example, if nn is 1234, the subsequence aa is 12 and bb is 34. Inverting the order of aa gives 21, and the result will be, then, 21+34=5521 + 34 = 55.

In the case where nn has an odd length, the partition can be made in two different ways. For instance, if nn is 12345, we can compute the "folding" in these two ways:

  • Divide nn in a=123a = 123 and b=45b = 45, and inverting aa and adding, we would get 321+45=366321 + 45 = 366.

  • Divide nn in a=12a = 12 and b=345b = 345, and inverting aa and adding, we would get 21+345=36621 + 345 = 366.

The middle digit, then, ends up contributing in the same way to the final sum in both cases.

Input

The input consists of a sequence of strictly positive integers.

Output

The output consists of each number in the input “folded” as explained, each one in a separate line.

Public test cases
  • Input

    1
    55
    444
    555
    9901
    12345
    123456
    9991001
    

    Output

    1 -> 1
    55 -> 10
    444 -> 48
    555 -> 60
    9901 -> 100
    12345 -> 366
    123456 -> 777
    9991001 -> 2000
    
  • Information
    Author
    PRO1
    Language
    English
    Translator
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    C++
    User solutions
    C++