This page is still under construction.

Parts of this page are still being built. What you see may change.

Orange Number

Time limit1sMemory limit1024 MB

Summary
Given K between 1000 and 10000, output three distinct natural numbers N under 100000 digits, not divisible by 10, such that the digit sum of N and of N squared both equal K, or -1 if impossible.
Level

Hard8 of 10

Topics
Math, Number theory, Implementation, Brute force
Solved
No attempts yet

Problem

Do you know the story of the British mathematician Hardy and the Indian mathematician Ramanujan? Hardy told Ramanujan, "The taxi I rode here had the number 17291729, which seems like a number without any special feature." Ramanujan replied, "No, 17291729 is the smallest number that can be expressed as a sum of two cubes in two different ways." It is expressed as 1729=93+103=123+131729 = 9^3 + 10^3 = 12^3 + 1^3.

Today, Ihwan, who participated in a Codeforces round, said, "My rating became 22592259, which seems like a number without any special feature." Then Daniel replied, "No, the sum of the digits of 22592259 is 1818, and its square is 51030815103081, whose digit sum is also 1818, so they are equal." Finding this property fascinating, Ihwan named 22592259 an orange number and asked Daniel whether, for an integer KK, there exists a natural number whose digit sum is KK and whose square's digit sum is also KK. Let's help Daniel find such numbers!

Input

The first line gives an integer KK.

Output

Let S(N)S(N) be the sum of all digits of a natural number NN. S(N)S(N) is defined in base 10.

Find three natural numbers NN satisfying S(N)=S(N2)=KS(N)=S(N^2)=K, and output them one per line. If there are multiple such NN, you may output any three. However, NN must not be a multiple of 10.

If no such NN exists, you must output a single integer −1-1. If an NN satisfying the condition exists, it is guaranteed that at least three exist.

Constraints

  • 103≤K≤10410^3 \le K \le 10^4
  • For each number NN, 0<N<101050 < N < 10^{10^5} must hold. (That is, NN must have at most 100,000 digits)
  • Each number must not be a multiple of 10.
  • Each number must be distinct.

Examples2

  1. Example 1

    Input
    18
    
    Expected output
    99
    189
    2259
    
  2. Example 2

    Input
    2021
    
    Expected output
    -1