Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/palindromgacha-qoshish

Adding up to a palindrome

Medium 1000 ms 64 MB 47%
Share

A positive integer $n$ is given. If it is not a palindrome (does not read the same from the left and from the right), we add to it the number written with its digits in reverse order ($87 + 78 = 165$) and repeat this until the number becomes a palindrome. Find the number of additions performed and the resulting palindrome.

A chain of adding the reversed number starting from 87: 165, 726, 1353, 4884

Input

One positive integer $n$.

Output

Two integers separated by a space: the number of additions and the palindrome.

Note

$1 \le n \le 10^{4}$
it is guaranteed that there are at most $50$ additions and the numbers obtained do not exceed $10^{18}$

Examples

Input #1
87
Output #1
4 4884
Input #2
121
Output #2
0 121

Sign in to submit a solution

Signing up is free and takes a minute.