Count pairs a, b with a < b, a + b = P, and no decimal digit repeats across a, b, and P, listing up to 5000 of them.
Hard8Bit manipulationBrute forceMathImplementationNo attempts yetTime limit2sMemory limit512 MBQuido eats lunch at Hugo's restaurant every day. Every price in the restaurant is an integer, and for every positive integer price the menu has at least one beverage and at least one main dish at that price.
Each day the bill shows three numbers: the beverage price, the main dish price, and the total price. Hugo knows that Quido likes computational problems, so he gives Quido a free dessert whenever the bill meets all three conditions below.
Quido keeps to a budget, so he pays the same total every day. Count how many free desserts he can get.
The input is one line with the integer P, the total price Quido pays for every lunch (1≤P<1018).
On the first line print the largest number of free desserts Quido can get when his total is always P.
Then print the bills that earn a free dessert in increasing order of the beverage price, one bill per line. Each line holds the beverage price, a space, and the main dish price. The total P is the same on every bill, so it is not printed again.
If more than 5000 bills earn a free dessert, print only the first 5000 of them. The count on the first line is still the full count.