Description

Counting Sheep

Design a hardware module that implements Bleatrix Trotter's digit counting strategy. Given a starting number N, the module counts N, 2×N, 3×N, etc., tracking which digits (0-9) have been seen across all numbers. Output the last number when all 10 digits have been seen, or a special value for impossible cases.

Example: For N=0, output special "INSOMNIA" value (all zeros). For N=1692, count 1692 (digits 1,2,6,9), 3384 (adds 3,4,8), 5076 (adds 0,5,7) → output 5076.

Source: Google Code Jam 2016 Qualification Round - Problem A: Counting Sheep

Input

N

20-bit Unsigned Integer
Starting number (0 ≤ N ≤ 10^6).

Output

32-bit Unsigned Integer
Last number before sleep or 0xFFFFFFFF for INSOMNIA.