Free Desserts

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 MB

Problem

Quido 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.

  • The bill is different from every bill Quido has had before.
  • The beverage price is smaller than the main dish price.
  • No digit appears in more than one of the three numbers. A digit that occurs in the beverage price, in the main dish price, or in the total price must not occur in either of the other two numbers.

Quido keeps to a budget, so he pays the same total every day. Count how many free desserts he can get.

Input

The input is one line with the integer PP, the total price Quido pays for every lunch (1P<10181 \le P < 10^{18}).

Output

On the first line print the largest number of free desserts Quido can get when his total is always PP.

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 PP 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.