It is well-known that the digit sum (in base 10) preserves the remainder modulo 9.
This is easy to prove: all powers of 10 give the remainder 1 when divided by 9, and therefore \(\sum a_i\cdot 10^i\) (the value of the number whose digits are \(a_i\)) gives the same remainder as \(\sum a_i\) (the digit sum of that number).
This gives us a necessary condition for the solvability of our task: whenever two numbers \(x\) and \(y\) share the same digit sum, they must share the same remainder modulo 9, and therefore their difference \(d\) must be divisible by 9. In other words, if \(d\) isn’t a multiple of 9, the answer is NONE.
The public subtasks are both solvable by brute force: print NONE if \(d\) isn’t divisible by 9, and in all other cases iterate over all pairs \((x,x+d)\) until you find one where the digit sum matches. It turns out that for each solvable \(d\) you’ll find such a pair pretty quickly.
For the full solution we need to come up with a more clever construction. There are many possibilities how to do it, but one of them is definitely both simplest and most clever.
As \(d\) is a multiple of 9, let \(d = 9k\). Now, consider the numbers \(k\) and \(10k\). Their difference is clearly \(9k = d\). And their digit sums are clearly the same, as \(10k\) is just formed from \(k\) by appending a zero.