1946.Maximize Sum of Digits

Time Limit: 1s Memory Limit: 256MB

Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits.

Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them.

Input Format(From the terminal/stdin)

The first line contains the positive integer x (1 \le x \le 1018) - the integer which Anton has.

Output Format(To the terminal/stdout)

Print the positive integer which doesn't exceed x and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.

Sample Input 1

Copy
100
   \n

Sample Output 1

Copy
99
  \n

Sample Input 2

Copy
48
  \n

Sample Output 2

Copy
48
  \n

Sample Input 3

Copy
521
   \n

Sample Output 3

Copy
499
   \n

Submit

请先 登录

© 2025 FAQs