Comments

Bro, it's TL unfortunately

I'd suggest the following solution:

First, let's observe, that if the numbers are of a different lenght, we can take $$$9..9$$$, as an anwser, where number of $$$9$$$'s is the lenght of $$$r - 1$$$.

So, now the numbers are of a equal lenght. To construct an anwser let's trace $$$from$$$ the first different digits from left to right and maintain maximal and minimal digits in prefix. Let's say current digits are $$$a, b$$$ respectively to $$$r, l$$$. Now, we try to add to our prefix either $$$a$$$ or $$$b$$$, and if $$$a \gt b + 1$$$, we can continue our string with whatever we want, with the first element of a suffix in $$$(a, b)$$$. Also, we are free to add whatever we want, if our current anwser is not a prefix of either $$$l$$$ nor $$$r$$$.

But, if we are, we may only add element from $$$[0, a]$$$, if our current anwser is the prefix of $$$r$$$, and $$$[b, 9]$$$ if it is of $$$l$$$.

$$$\mathcal{O}({2^{\mathrm{|r|}}})$$$

Solution: 200873882

It appears i misunderstood your statement. Thanks:)), it really helped indeed.

So the problem with smt like sys.setrecursionlimit(200005) is, that it apperently reserves a lot of memory

Well, yes. But then its not like a given solution for the problem. The question is, how to use recursion in Python properly?

It's actually quite confusing you can't use python for a tutorial solution of a D problem. Is it true or i just do not know how to set recursion depth limit without getting ML?

193974524