Happy Number

Decide whether repeatedly summing the squares of a number's decimal digits ever reaches 1.

Easy3SimulationHash mapMathNo attempts yetTime limit0.2sMemory limit512 MB

Problem

For a natural number nn, define the function ff as follows.

f(n)f(n) is the sum of the squares of the digits of nn written in base ten.

For example, if n=19n = 19, then f(19)=82f(19) = 82 because 12+92=821^2 + 9^2 = 82.

Applying ff over and over, some natural numbers eventually reach 1. Such a number is called a happy number. 19 is one of them.

  • f(19)=12+92=82f(19) = 1^2 + 9^2 = 82
  • f(82)=82+22=68f(82) = 8^2 + 2^2 = 68
  • f(68)=62+82=100f(68) = 6^2 + 8^2 = 100
  • f(100)=12+02+02=1f(100) = 1^2 + 0^2 + 0^2 = 1

Not every natural number is happy. Work 5 out by hand and you will see that 5 is not a happy number. Mathematicians proved that when nn is not a happy number, repeated application of ff always falls into this cycle.

416375889145422044 \to 16 \to 37 \to 58 \to 89 \to 145 \to 42 \to 20 \to 4

Write a program that decides whether a given natural number nn is a happy number.

Input

Your program reads from standard input. The input is a single line holding one integer nn (1n1,000,000,0001 \le n \le 1{,}000{,}000{,}000).

Output

Your program writes to standard output. Print exactly one line. If nn is a happy number, print HAPPY. Otherwise print UNHAPPY.