#C9589. Maximum Digit Product after a Swap

    ID: 53698 Type: Default 1000ms 256MiB

Maximum Digit Product after a Swap

Maximum Digit Product after a Swap

You are given a positive integer (n). You are allowed to perform at most one swap between any two digits of (n). After this optional swap, compute the product of the digits of the resulting number (i.e. multiply all its digits together). Your task is to determine the maximum possible product that can be obtained by performing at most one swap.

For example, if (n = 2736), you can swap the digits 2 and 6 to form 6732, but the best swap leads to the product 252. Remember, if no swap increases the product, then simply calculate the product of the digits of the original number.

Formally, if (D = d_1 d_2 \dots d_k) is the digit representation of (n), and (P(D) = d_1 \times d_2 \times \dots \times d_k), you need to maximize (P(D')) over all (D') obtainable by swapping two digits (or by leaving (D) unchanged).

inputFormat

The input consists of a single line with a positive integer (n) (without leading zeros). This integer is provided via standard input (stdin).

outputFormat

Output a single integer representing the maximum product of digits of the number after performing at most one swap. The result should be printed to standard output (stdout).## sample

2736
252