Under construction

Still being built. Things may change

Free Desserts

Time limit2sMemory limit512 MB

Summary
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.
Level

Hard8 of 10

Topics
Bit manipulation, Brute force, Math, Implementation
Solved
No attempts yet

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 (1≤P<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.

Examples3

  1. Example 1

    Input
    37
    
    Expected output
    4
    8 29
    9 28
    11 26
    15 22
    
  2. Example 2

    Input
    30014
    
    Expected output
    7
    85 29929
    88 29926
    785 29229
    788 29226
    7785 22229
    7788 22226
    7789 22225
    
  3. Example 3

    Input
    202020202020202058
    
    Expected output
    3
    7676767676767667 194343434343434391
    37373737373737397 164646464646464661
    67676767676767667 134343434343434391