Python. Easy.
\ndef f(n,s,e,ci,di,v):\n    if n==ci:\n        return 1\n    a=0\n    if (e,ci,v) in di:\n        return di[e,ci,v]\n    for i in range(10):\n            if e=
```\ndef f(n,s,e,ci,di,v):\n    if n==ci:\n        return 1\n    a=0\n    if (e,ci,v) in di:\n        return di[e,ci,v]\n    for i in range(10):\n            if e==0:\n                if not v>>i&1:\n                    eee=v|(1<<i)\n                    a+=f(n,s,0,ci+1,di,eee)\n            else:\n                if i>int(s[ci]):\n                    break\n                if int(s[ci])==i:\n                    if not v>>i&1:\n                        eee=v|(1<<i)\n                        a+=f(n,s,1,ci+1,di,eee)\n                    break\n                if not v>>i&1:\n                    eee=v|(1<<i)\n                    a+=f(n,s,0,ci+1,di,eee)\n    di[e,ci,v]=a\n    return a\nclass Solution:\n    def numDupDigitsAtMostN(self, n: int) -> int:\n        if n<=10:\n            return 0\n        s=str(n)\n        l=len(s)\n        ans=10\n        prev=9\n        for i in range(9,9-l+2,-1):\n            ans+= prev*i\n            prev=prev*i\n        a=0\n        di={}\n        v=0\n        for i in range(1,10):\n            if i>int(s[0]):\n                break\n            if i==int(s[0]):\n                e=1<<i\n                a+=f(l,s,1,1,di,e)\n                break\n            e=1<<i\n            a+=f(l,s,0,1,di,e)\n        return n-a-ans+1\n```
[]