TE. Nirvana
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 1 1 1 to n n n.
Input
The only input line contains the integer n n n ( 1 ≤ n ≤ 2 ⋅ 1 0 9 1 \le n \le 2\cdot10^9 1≤n≤2⋅109).
Output
Print the maximum product of digits among all integers from 1 1 1 to n n n.
Example
Input
390
Output
216
Note
In the first example the maximum product is achieved for 389 389 389 (the product of digits is 3 ⋅ 8 ⋅ 9 = 216 3\cdot8\cdot9=216 3⋅8⋅9=216).
In the second example the maximum product is achieved for 7 7 7 (the product of digits is 7 7 7).
In the third example the maximum product is achieved for 999999999 999999999 999999999 (the product of digits is 9 9 = 387420489 9^9=387420489 99=387420489).
code
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 110,INF=0x3f3f3f3f,mod=1e9+7;
typedef pair<int,int> PII;
int T=1;
int f(int a)
{
if(a<10){
return max(a,(int)1);
}
return max(a%10*f(a/10), f(a/10-1)*9);
}
void solve(){
int n;
cin>>n;
cout<<f(n)<<endl;
}
signed main(){
// cin>>T;
while(T--){
solve();
}
return 0;
}