Problem: Example

Input

20


Output

4

Solution (in CPP):

Solution:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long  ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

ll p[30];
void init() {
	p[0] = 1;
	rep1(i, 15) {
		p[i] = p[i - 1] * i;
	}
}

string s;
int n;
vector<vec> v;
vec a;
void dfs(int id,int s) {
	if (id == n) {
		v.push_back(a); return;
	}
	Rep(i, s, 10) {
		a.push_back(i);
		dfs(id + 1, i);
		a.pop_back();
	}
}
void solve() {
	init();
	cin >> s;
	n = s.length();
	int sum = 0;
	rep(i, n) {
		sum += (s[i] - '0');
	}
	ll pro = 1;
	rep(i, n) {
		ll t = (s[i] - '0') + 1;
		pro = pro * t;
	}
	dfs(0, 0);
	ll ans = 0;
	rep(i, v.size()) {
		vec &u = v[i];
		ll c = p[n];
		rep(j, n) {
			int le = j;
			while (j + 1 < n&&u[j] == u[j + 1])j++;
			int len = j - le + 1;
			c /= p[len];
		}

		int csum = 0;
		rep(j, n)csum += u[j];
		if (csum < sum) {
			//cout << "sum " << c << endl;
			ans += c; continue;
		}
		else if (csum > sum)continue;
		ll pr = 1;
		rep(j, n)pr *= u[j] + 1;
		if (pr < pro) {
			//cout << "pr " << c << endl;
			ans += c; continue;
		}
		else if (pr > pro)continue;
		vector<vector<ll>> dp(1 << n);
		rep(i, (1 << n))dp[i].resize(2, 0);
		dp[0][0] = 1;
		rep(i, (1 << n)-1) {
			int cnt = 0;
			rep(j, n)if (i&(1 << j))cnt++;
			rep(j, n) {
				if (i&(1 << j))continue;
				if (j > 0) {
					if (u[j] == u[j - 1]) {
						if (i&(1 << (j - 1)))continue;
					}
				}
				int ni = i ^ (1 << j);
				dp[ni][1] += dp[i][1];
				int z = u[j];
				int cc = s[cnt] - '0';
				if (z == cc) {
					dp[ni][0] += dp[i][0];
				}
				else if (z < cc) {
					dp[ni][1] += dp[i][0];
				}
			}
		}
		ans+=dp[(1 << n) - 1][1];
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//while (cin >> w>>h>>n,n)solve();
	solve();
	//stop
	return 0;
}