n=int(input());original=n;ansset=set()#出了大麻煩
while True:
Time=[];ans=0
while True:
#print("n",n)
Time.append(n%10)
n=n//10 # end while
if n<1:break
for i in range(len(Time)):
ans+=Time[i]**2
if ans in ansset:print(str(original)+" is an unhappy number");break
ansset.add(ans)#;print(ansset)
if ans==1:print(str(original)+" is a happy number");break
#如果ans在SET中,開始循環了,跳出
n=ans