Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/baxtli-sonmi

Happy number?

Medium 1000 ms 64 MB 47%
Share

A positive integer $n$ is given. We replace it with the sum of the squares of its digits and repeat this. If $1$ appears in the process, $n$ is called a happy number. If $4$ appears, the number will never reach $1$ (the following numbers cycle). Print YES if $n$ is happy, otherwise NO.

A chain of sums of squared digits starting from 19 and ending in 1

Input

One positive integer $n$.

Output

YES or NO.

Note

$1 \le n \le 10^{9}$

Examples

Input #1
19
Output #1
YES
Input #2
2
Output #2
NO

Sign in to submit a solution

Signing up is free and takes a minute.