Under construction

Still being built. Things may change

Squares

Time limit2sMemory limit512 MB

Summary
Given n up to 10^18, find the smallest possible largest base k(n) in a sum of distinct squares equal to n, and count the overgrown integers up to n.
Level

Hard8 of 10

Topics
Dynamic programming, Math, Number theory
Solved
No attempts yet

Problem

We call a decomposition of a positive integer any way to write it as a sum of distinct squares of positive integers. For example, 30 has two decompositions: 30=12+22+52=12+22+32+4230 = 1^2 + 2^2 + 5^2 = 1^2 + 2^2 + 3^2 + 4^2. The number 8 has none.

Let k(n)k(n) be the minimum, over all decompositions of nn, of the largest integer whose square appears in the decomposition. If nn has no decomposition, then k(n)=∞k(n) = \infty. For example, k(1)=1k(1) = 1, k(8)=∞k(8) = \infty, k(30)=4k(30) = 4, k(378)=12k(378) = 12, and k(380)=10k(380) = 10.

An integer xx is overgrown if there is an integer y>xy > x with k(y)<k(x)k(y) < k(x). In the example above, 378 is overgrown.

For a given nn, find k(n)k(n) and the number of overgrown integers from 1 to nn, inclusive.

Input

The first and only line contains a single integer nn (1≤n≤10181 \le n \le 10^{18}). Tests worth 45% of the score satisfy n≤50 000 000n \le 50\,000\,000. A subset worth 30% satisfies n≤1 000 000n \le 1\,000\,000, and a smaller subset worth 20% satisfies n≤1000n \le 1000.

Output

Print two integers separated by a single space: first k(n)k(n), then the number of overgrown integers from 1 to nn. If k(n)=∞k(n) = \infty, print a minus sign (-) instead of the first number.

Examples2

  1. Example 1

    Input
    30
    
    Expected output
    4 15
    
  2. Example 2

    Input
    8
    
    Expected output
    - 5