#include #include #define rep(i,n) for(int i=0;i equal(1 << 10); // less than s[0:i] vector small(1 << 10); { // init int num = s[0] - '0'; for(int x = 1; x < num; x++) small[1 << x]++; equal[1 << num]++; } for(int i = 1; i < n; i++){ vector equal_old(1 << 10); vector small_old(1 << 10); swap(equal, equal_old); swap(small, small_old); // num: i-th number int num = s[i] - '0'; rep(bit, 1 << 10){ // equal -> small // x s.t. 0 <= x < num is acceptable for(int x = 0; x < num; x++) small[bit ^ (1 << x)] += equal_old[bit]; // equal -> equal // x s.t. x = num is acceptable equal[bit ^ (1 << num)] += equal_old[bit]; // small -> small // x s.t. 0 <= x <= 9 is acceptable for(int x = 0; x <= 9; x++) small[bit ^ (1 << x)] += small_old[bit]; } // nothing -> small // 0th to (i-1)-th are all 0. i-th number is not 0. for(int x = 1; x <= 9; x++) small[(1 << x)]++; } return equal[0] + small[0]; } int main(){ string s; cin >> s; cout << solve(s).val() << "\n"; return 0; }