CF BUDDY
← Problems·

1143B · Nirvana

1200 · brute force, math, number theory

Problem: Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.

Help Kurt find the maximum possible product of digits among all integers from 11 to nn.

Input Format: The only input line contains the integer nn (1n21091 \le n \le 2\cdot10^9).

Output Format: Print the maximum product of digits among all integers from 11 to nn.

Note: In the first example the maximum product is achieved for 389389 (the product of digits is 389=2163\cdot8\cdot9=216).

In the second example the maximum product is achieved for 77 (the product of digits is 77).

In the third example the maximum product is achieved for 999999999999999999 (the product of digits is 99=3874204899^9=387420489).

Sample Cases

Case 1

Input

390

Output

216

Case 2

Input

7

Output

7

Case 3

Input

1000000000

Output

387420489

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback