Folded Numbers

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:

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.

Problem information

Author: PRO1

Generation: 2026-01-25T16:12:06.143Z

© Jutge.org, 2006–2026.
https://jutge.org