~/algor $ cat problems/dp-eng-kam-kvadratlar
Fewest squares
Medium
1000 ms
128 MB
49%
A positive integer $n$ must be written as a sum of several perfect squares ($1, 4, 9, 16, \ldots$); the same square may be used several times. What is the smallest number of terms needed? For example, $12 = 4 + 4 + 4$.
Input
One positive integer $n$.
Output
One integer — the smallest number of terms.
Note
$1 \le n \le 10^{4}$
Examples
Input #1
12
Output #1
3
Input #2
13
Output #2
2