#P10253. Echo Rap Challenge

    ID: 12251 Type: Default 1000ms 256MiB

Echo Rap Challenge

Echo Rap Challenge

ZHY practices rap in an empty room. Initially, he produces a sound of intensity \(x\). When this sound hits the wall, an echo is produced with intensity \(\left\lfloor \frac{x}{10} \right\rfloor\). This echo in turn hits the wall and produces another echo, and so on, until the echo intensity becomes 0.

The room also contains a radio that records all the sounds (including the original and all echoes). Unfortunately, the radio is broken and can only display the sum of the intensities of all recorded sounds, \(y\). Given this value \(y\), your task is to determine whether there exists a unique \(x\) such that

[ f(x)=\begin{cases} 0 & \text{if } x=0,\ x+f\left(\left\lfloor \frac{x}{10} \right\rfloor\right) & \text{if } x>0,\end{cases} ]

and \(f(x)=y\) holds. If such a unique \(x\) exists, output its value; otherwise, output \(-1\). For example, \(f(123) = 123+12+1 = 136\).

inputFormat

The input consists of a single integer \(y\) representing the total sum of the intensities recorded by the radio.

Input Format:

y

outputFormat

Output a single integer, the unique value \(x\) such that \(f(x) = y\), or \(-1\) if no such unique \(x\) exists.

Output Format:

x

sample

136
123