Skip to main content
LIVE CONTEST: ALGOR Contest: Round #4 (Special Challenge) is live now!

~/algor $ cat problems/dp-eng-kam-kvadratlar

Fewest squares

Medium 1000 ms 128 MB 49%
Share

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$.

A number split into a sum of perfect squares: a shape made of squares

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

Sign in to submit a solution

Signing up is free and takes a minute.