Under construction

Still being built. Things may change

NNN-numbers

Time limit1sMemory limit1024 MB

Summary
Given N, list all N-digit base-N numbers where each digit equals how many times its position's digit value appears, in increasing order.
Level

Medium6 of 10

Topics
Backtracking, Math, Implementation
Solved
No attempts yet

Problem

We are used to writing numbers in decimal. When we write 123, it actually stands for 1⋅102+2⋅10+31 \cdot 10^2 + 2 \cdot 10 + 3.

In general, a base-NN number uses digits from 00 to N−1N-1, and abcabc stands for a⋅N2+b⋅N+ca \cdot N^2 + b \cdot N + c. When N>10N > 10, the digits after 99 are uppercase Latin letters in ASCII order (A = 10, B = 11, …\dots, Z = 35). For example, the base-16 number F1 stands for 15⋅16+115 \cdot 16 + 1, which is 241241 in decimal.

An NN-digit NNN-number is a base-NN number with exactly NN digits in which the units digit equals the number of times digit 1 appears in it, the tens digit equals the number of times digit 2 appears, and so on. The leftmost digit equals the number of zeros in the number.

Input

The only line of the text file contains a decimal integer NN (2≤N≤362 \le N \le 36).

Output

Write all NN-digit NNN-numbers to the text file in increasing order, one per line. If there are none, the only line of the file contains EI OLE.

Examples2

  1. Example 1

    Input
    5
    
    Expected output
    20021
    
  2. Example 2

    Input
    2
    
    Expected output
    EI OLE