Under construction

Still being built. Things may change

Bus Numbers

Interview

Time limit2sMemory limit512 MB

Summary
Find the largest number up to m that can be written as a sum of two positive cubes in at least two distinct ways, or report none.
Level

Medium4 of 10

Topics
Brute force, Math, Hash map, Implementation
Solved
No attempts yet

Problem

A famous story about the mathematicians G.H. Hardy and Srinivasa Ramanujan goes as follows (as told by Hardy):

I remember once going to see him (Ramanujan) when he was lying ill at Putney. I had ridden in taxicab No. 1729, and remarked that the number seemed to be rather a dull one, and that I hoped it was not an unfavourable omen. "No", he replied, "it is a very interesting number; it is the smallest number expressible as the sum of two [positive] cubes in two different ways."

It is from this story that the taxicab numbers got their name. The nn'th taxicab number is defined to be the smallest number that can be expressed as a sum of two positive cube numbers in nn distinct ways.

It turns out that these numbers grow rather quickly. This makes them very hard to compute, which is not very fun. A variation of the concept is to consider what we will call the bus numbers: all the numbers which can be expressed as the sum of two positive cube numbers in at least 22 distinct ways. Note that according to this definition, all taxicab numbers (except the first) are also bus numbers.

Your task is to write a program that generates bus numbers; in particular, the largest bus number that is at most equal to some limit mm.

Input

The input consists of:

  • one line with an integer mm (1≤m≤400 0001 \le m \le 400\,000), the upper bound of the bus number.

Output

Output the largest bus number xx which does not exceed mm. If there is no such number, output none.

Examples2

  1. Example 1

    Input
    1730
    
    Expected output
    1729
    
  2. Example 2

    Input
    100
    
    Expected output
    none