100 atcoder#ABC221C. [ABC221C] Select Mul

[ABC221C] Select Mul

Score : 300300 points

Problem Statement

You are given an integer NN. Consider permuting the digits in NN and separate them into two positive integers.

For example, for the integer 123123, there are six ways to separate it, as follows:

  • 1212 and 33,
  • 2121 and 33,
  • 1313 and 22,
  • 3131 and 22,
  • 2323 and 11,
  • 3232 and 11.

Here, the two integers after separation must not contain leading zeros. For example, it is not allowed to separate the integer 101101 into 11 and 0101. Additionally, since the resulting integers must be positive, it is not allowed to separate 101101 into 1111 and 00, either.

What is the maximum possible product of the two resulting integers, obtained by the optimal separation?

Constraints

  • NN is an integer between 11 and 10910^9 (inclusive).
  • NN contains two or more digits that are not 00.

Input

Input is given from Standard Input in the following format:

NN

Output

Print the maximum possible product of the two integers after separation.

123
63

As described in Problem Statement, there are six ways to separate it:

  • 1212 and 33,
  • 2121 and 33,
  • 1313 and 22,
  • 3131 and 22,
  • 2323 and 11,
  • 3232 and 11.

The products of these pairs, in this order, are 3636, 6363, 2626, 6262, 2323, 3232, with 6363 being the maximum.

1010
100

There are two ways to separate it:

  • 100100 and 11,
  • 1010 and 1010.

In either case, the product is 100100.

998244353
939337176