LogiQuest

263. Perfect Squares

MediumDynamic Programming

Print the least number of perfect squares (1, 4, 9, …) that sum to n.

Input format

A single integer n.

Output format

The minimum count.

Example 1

Input

12

Output

3

Example 2

Input

13

Output

2

Constraints

1 ≤ n ≤ 10⁴

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…