Given a number N find whether its a happy number or not. 
A number is called happy if it leads to 1 after a sequence of steps wherein each step, the number is replaced by the sum of squares of its digit that is if we start with Happy Number and keep replacing it with digits square sum, we reach 1.
Example 1:
Input: 
N = 19
Output: 
1
Explanation:
19 is a Happy Number,
1^2 + 9^2 = 82
8^2 + 2^2 = 68
6^2 + 8^2 = 100
1^2 + 0^2 + 0^2 = 1
As we reached to 1, 
19 is a Happy Number.
Example 2:
Input:
N = 20
Output: 
0
Explanation: 
We can never reach to 1
by repeating the mentioned
steps.
Your Task:
You don't need to read input or print anything. Your task is to complete the function isHappy() which takes an integer N as input parameter and returns 1 if N is a happy number or 0 otherwise.
 
Expected Time Complexity: O(sqrt(N))
Expected Space Complexity: O(1)
 
Constraints:
1 <= N <= 10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3
class Solution:
    def isHappy (self, N):
        # code here

Solutions:
class Solution:

	def isHappy(self, N):
		if N < 10:
			N = N * N
		while len(str(N)) > 1:
			summ = 0
			for i in str(N):
				summ += int(i) ** 2
			N = summ
		if N == 1:
			return 1
		return 0


class Solution:

	def isHappy(self, n):

		def squareSum(n):
			ans = 0
			while n:
				i = n % 10
				ans += i ** 2
				n = n // 10
			return ans
		l = []
		while True:
			ans = squareSum(n)
			if ans == 1:
				return 1
			if ans in l:
				return 0
			l.append(ans)
			n = ans


class Solution:

	def isHappy(self, n):
		s = set()
		while True:
			n = sum((int(i) ** 2 for i in str(n)))
			if n == 1:
				return 1
			elif n in s:
				return 0
			else:
				s.add(n)


arr = [1, 7, 10, 13, 19, 23, 28, 31, 32, 44]

class Solution:

	def isHappy(self, n):
		while n != 1:
			if n in arr:
				return 1
			n = sum([int(x) ** 2 for x in str(n)])
			if n == 4:
				return 0
		return 1


class Solution:

	def SumSquare(self, n):
		summ = 0
		while n != 0:
			dg = n % 10
			summ += dg * dg
			n //= 10
		return summ

	def isHappy(self, n):
		st = set()
		st.add(n)
		while True:
			if n == 1:
				return 1
			n = self.SumSquare(n)
			if n in st:
				return 0
			st.add(n)
		return 0


class Solution:

	def isHappy(self, N):
		hashset = set()
		while N not in hashset:
			hashset.add(N)
			N = self.square(N)
			if N == 1:
				return 1
		return 0

	def square(self, N):
		ans = 0
		while N:
			digit = N % 10
			digit = digit ** 2
			ans += digit
			N = N // 10
		return ans


class Solution:

	def isHappy(self, N):

		def sumOfSq(n):
			output = 0
			while n:
				digit = n % 10
				digit = digit ** 2
				output += digit
				n = n // 10
			return output
		slow = N
		fast = sumOfSq(N)
		while fast != 1 and slow != fast:
			slow = sumOfSq(slow)
			fast = sumOfSq(sumOfSq(fast))
		return 1 if fast == 1 else 0


class Solution:

	def isHappy(self, N):
		n = N
		s = 0
		k = Solution()
		while n != 0:
			r = n % 10
			s = s + r ** 2
			n = n // 10
		if s == 1 or s == 7:
			return 1
		elif s >= 2 and s <= 9:
			return 0
		else:
			return k.isHappy(s)


class Solution:

	def isHappy(self, N):
		l = [2, 3, 4, 5, 6, 8, 9]
		while N != 1:
			if N in l:
				return 0
			s = 0
			for i in str(N):
				s += int(i) ** 2
			N = s
		return 1


class Solution:

	def isHappy(self, N):
		if N == 1 or N == 7:
			return 1
		sum = N
		x = N
		while sum > 9:
			sum = 0
			while x > 0:
				d = x % 10
				sum += d * d
				x //= 10
			if sum == 1:
				return 1
			x = sum
		if sum == 7:
			return 1
		return 0


class Solution:

	def isHappy(self, N):
		if N < 10:
			N = N ** 2
		while N >= 10:
			res = 0
			temp = N
			while temp:
				res += temp % 10 * (temp % 10)
				temp = temp // 10
			N = res
		if N == 1:
			return 1
		else:
			return 0


class Solution:

	def isHappy(self, N):
		seen = set()
		while N not in seen:
			seen.add(N)
			N = sum([int(x) ** 2 for x in str(N)])
		if N == 1:
			return 1
		else:
			return 0


class Solution:

	def isHappy(self, N):
		visited = set()
		while True:
			N = self.sumOfSquares(N)
			if N == 1:
				return 1
			elif N in visited:
				return 0
			visited.add(N)

	def sumOfSquares(self, x):
		ans = 0
		while x:
			ans += (x % 10) ** 2
			x //= 10
		return ans


class Solution:

	def isHappy(self, N):
		n = N
		sum = 0
		while n > 0:
			r = n % 10
			sum = sum + r * r
			n = n // 10
		if sum == 1 or sum == 7:
			return 1
		if sum < 10:
			return 0
		else:
			return self.isHappy(sum)


class Solution:

	def isHappy(self, n, l=[]):
		if n in l:
			return int(n == 1)
		q = sum([int(x) ** 2 for x in str(n)])
		return self.isHappy(q, [*l, n])


class Solution(object):

	def isHappy(self, n):
		temp = sum([pow(int(x), 2) for x in str(n)])
		d = {}
		d[temp] = 1
		if temp == 1:
			return 1
		while True:
			temp = sum([pow(int(x), 2) for x in str(temp)])
			if d.get(temp) == None:
				d[temp] = 1
			else:
				return 0
			if temp == 1:
				return 1
		return 0


class Solution:

	def isHappy(self, n):
		slow = sum([int(i) ** 2 for i in str(n)])
		fast = sum([int(i) ** 2 for i in str(n)])
		fast = sum([int(i) ** 2 for i in str(fast)])
		while slow != fast:
			slow = sum([int(i) ** 2 for i in str(slow)])
			fast = sum([int(i) ** 2 for i in str(fast)])
			fast = sum([int(i) ** 2 for i in str(fast)])
		if slow == 1:
			return 1
		return 0


class Solution:

	def isHappy(self, n):
		set_ = set()
		while True:
			if n == 1:
				return 1
			curr_sum = 0
			while n:
				(n, rem) = divmod(n, 10)
				curr_sum += rem ** 2
			if curr_sum in set_:
				return 0
			set_.add(curr_sum)
			n = curr_sum


class Solution:

	def isHappy(self, N):

		def sqnum(num):
			result = 0
			while num > 0:
				r = num % 10
				result += r * r
				num = num // 10
			return result
		seen = set()
		while sqnum(N) not in seen:
			sum1 = sqnum(N)
			if sum1 == 1:
				return 1
			else:
				seen.add(sum1)
				N = sum1
		return 0


class Solution:

	def summ(self, num):
		s = 0
		while num > 0:
			digit = num % 10
			s += digit * digit
			num = num // 10
		return s

	def isHappy(self, n):
		(fast, slow) = (n, n)
		while True:
			fast = self.summ(self.summ(fast))
			slow = self.summ(slow)
			if fast == slow:
				break
		if slow == 1:
			return 1
		else:
			return 0


class Solution:

	def isHappy(self, N):

		def reduce(num):
			sums = 0
			while num > 0:
				rem = num % 10
				sums += rem * rem
				num = num // 10
			return sums

		def Happy_found(num):
			while num != 1 and num != 4:
				num = reduce(num)
			return num
		result = Happy_found(N)
		if result == 1:
			return 1
		else:
			return 0


class Solution:

	def isHappy(self, n):
		while n > 9:
			ans = 0
			while n > 0:
				rem = n % 10
				ans = ans + rem ** 2
				n = n // 10
			n = ans
		if n == 1 or n == 7:
			return 1
		else:
			return 0


class Solution:

	def isHappy(self, N):
		s = N
		while s > 9:
			s = 0
			while N > 0:
				r = N % 10
				s += r ** 2
				N //= 10
			if s > 9:
				N = s
		if s == 1 or s == 7:
			return 1
		else:
			return 0


class Solution:

	def find(self, N):
		rem = 0
		rev = 0
		while N > 0:
			rev = N % 10
			rem = rem + rev ** 2
			N = N // 10
		return rem

	def isHappy(self, N):
		num = set()
		result = N
		while self.find(result) not in num:
			result = self.find(result)
			if result == 1:
				return 1
			else:
				num.add(result)
		if result == 1:
			return 1
		else:
			return 0


class Solution:

	def isHappy(self, n):

		def f(n):
			res = 0
			while n:
				res += (n % 10) ** 2
				n //= 10
			return res
		m = n
		s = {n}
		while n:
			n = f(n)
			if n in s:
				return 0
			s.add(n)
			if n == 1:
				return 1
		return 0


class Solution:

	def isHappy(self, n):

		def f(n):
			res = 0
			while n:
				res += (n % 10) ** 2
				n //= 10
			return res
		m = n
		while n:
			n = f(n)
			if n == 1:
				return 1
			if n == 89:
				return 0
		return 0


class Solution:

	def isHappy(self, N):
		a = 0
		while N != 0:
			r = N % 10
			s = r * r
			a = a + s
			N = N // 10
		if a // 10 == 0 and a != 1:
			return 0
		if a != 1:
			return self.isHappy(a)
		if a == 1:
			return 1
		else:
			return 0


class Solution:

	def isHappy(self, N):

		def fun(n):
			if n < 10:
				if n == 1 or n == 7:
					return 1
				else:
					return 0
			else:
				m = n
				s = 0
				while m != 0:
					k = m % 10
					s = s + k * k
					m = m // 10
				return fun(s)
		return fun(N)


class Solution:

	def isHappy(self, n):

		def sq(n):
			s = 0
			while n > 0:
				k = n % 10
				s = s + k * k
				n = n // 10
			return s
		while n > 9:
			n = sq(n)
		if n == 1 or n == 7:
			return 1
		else:
			return 0


class Solution:

	def isHappy(self, n):
		while n > 10:
			sum = 0
			while n > 0:
				x = n % 10
				n = n // 10
				sum = sum + x * x
			n = sum
		if n == 1 or n == 10 or n == 7:
			return 1
		else:
			return 0


class Solution:

	def isHappy(self, N):
		d = {}
		k = N
		while True:
			s = 0
			while k:
				s += (k % 10) ** 2
				k = k // 10
			if s == 1:
				return 1
			try:
				d[s]
				return 0
			except:
				d[s] = 1
			k = s


class Solution(object):

	def isHappy(self, n, prev=[]):
		nums = sum([int(x) ** 2 for x in list(str(n))])
		if nums in prev:
			return 0
		return self.isHappy(nums, prev + [nums]) if nums != 1 else 1


class Solution:

	def isHappy(self, N):

		def getNext(number):
			target = 0
			while number != 0:
				rem = number % 10
				number = int(number / 10)
				target = target + rem ** 2
			return target
		seen = set()
		n = N
		while n != 1 and n not in seen:
			seen.add(n)
			n = getNext(n)
		if n == 1:
			return 1
		else:
			return 0


class Solution:

	def isHappy(self, N):
		visit = set()
		while N not in visit:
			visit.add(N)
			N = self.sumofsquares(N)
			if N == 1:
				return 1
		return 0

	def sumofsquares(self, N):
		s = 0
		while N > 0:
			a = N % 10
			s += a * a
			N = N // 10
		return s


class Solution:

	def sum_squares(self, N):
		sum = 0
		while N:
			digit = N % 10
			sum += digit * digit
			N //= 10
		return sum

	def isHappy(self, N):
		set1 = set()
		while N != 1:
			N = self.sum_squares(N)
			if N in set1:
				break
			else:
				set1.add(N)
		if N == 1:
			return 1
		else:
			return 0


class Solution:

	def sumOfSquares(self, N):
		output = 0
		while N != 0:
			digits = N % 10
			digits = digits ** 2
			output += digits
			N = N // 10
		return output

	def isHappy(self, N):
		visit = set()
		while N not in visit:
			visit.add(N)
			N = self.sumOfSquares(N)
			if N == 1:
				return 1
		return 0


class Solution:

	def isHappy(self, N):
		k = len(str(N))
		m = int(N)
		l = []
		while True:
			p = 0
			while m > 0:
				a = m % 10
				p = p + a * a
				m = m // 10
			if p == 1:
				return 1
			elif p not in l:
				l.append(p)
				m = p
			else:
				return 0


class Solution:

	def isHappy(self, N):
		s = set()
		while True:
			ss = 0
			while N:
				ss = ss + N % 10 * (N % 10)
				N = N // 10
			if ss == 1:
				return 1
			if ss in s:
				return 0
			N = ss
			s.add(N)


class Solution:

	def isHappy(self, N):
		k = int(N ** 0.5) + 10
		while k != 0:
			s = 0
			while N != 0:
				s += (N % 10) ** 2
				N = N // 10
			if s == 1:
				return 1
			N = s
			k -= 1
		return 0


class Solution:

	def isHappy(self, n):

		def func(n):
			s = 0
			while n != 0:
				v = n % 10
				n = n // 10
				s += v ** 2
			return s
		s = n
		f = n
		f = func(func(f))
		s = func(s)
		while f != s:
			f = func(func(f))
			s = func(s)
		if s == 1:
			return 1
		return 0


class Solution:

	def isHappy(self, N):

		def ret_val(N, ans):
			if N == 0:
				return ans
			ans += (N % 10) ** 2
			return ret_val(N // 10, ans)
		if ret_val(N, 0) == 1:
			return 1
		if ret_val(N, 0) == 89:
			return 0
		return self.isHappy(ret_val(N, 0))


class Solution:

	def isHappy(self, n):
		while n:
			n = sum(map(lambda x: int(x) * int(x), str(n)))
			if n == 1:
				return 1
			elif n == 4:
				return 0


class Solution:

	def isHappy(self, n):
		if n == 1:
			return 1
		if n < 6:
			return 0
		sumx = 0
		for i in str(n):
			sumx = sumx + int(i) * int(i)
		return self.isHappy(sumx)


class Solution:

	def isHappy(self, N):

		def h(n):
			ans = 0
			for i in str(n):
				if i == '0':
					ans += 0
				else:
					ans += int(i) ** 2
			return ans
		x = []
		x.append(h(N))
		for i in range(100):
			a = h(x[-1])
			if a == 1:
				return 1
			else:
				x.append(a)
		return 0


class Solution:

	def isHappy(self, n):
		ls = []
		while 1:
			val = 0
			while n:
				t = n % 10
				n = n // 10
				val += t * t
			if val == 1:
				return 1
			elif val in ls:
				return 0
			else:
				n = val
				ls.append(val)
		return 0


class Solution:

	def isHappy(self, N):
		for j in range(N):
			n = str(N)
			x = 0
			for i in n:
				x = x + int(i) ** 2
			N = x
			if N == 1:
				return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isHappy(N))


class Solution:

	def isHappy(self, N):
		seen = set()
		while N != 1:
			curr = N
			sum = 0
			while curr != 0:
				sum += (curr % 10) ** 2
				curr //= 10
			if sum in seen:
				return 0
			seen.add(sum)
			N = sum
		return 1
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isHappy(N))


class Solution:

	def isHappy(self, N):
		visited = set()
		while N not in visited:
			visited.add(N)
			N = self.sumOfSquares(N)
			if N == 1:
				return 1
		return 0

	def sumOfSquares(self, n):
		sum_ = 0
		while n > 0:
			sum_ += n % 10 * (n % 10)
			n //= 10
		return sum_
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isHappy(N))


class Solution:

	def isHappy(self, N):
		if N == 1:
			return 1
		while N != 1 and N != 4:
			k = N
			sum = 0
			while k != 0:
				m = k % 10
				k = k // 10
				sum = sum + m * m
			N = sum
			if N == 1:
				return 1
			if N == 4:
				return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.isHappy(N))


class Solution:

	def isHappy(self, N):
		t = N
		while t > 0:
			Sum = 0
			while t:
				d = t % 10
				Sum += d * d
				t = t // 10
			t = Sum
			if t == 1 or t == 7:
				return 1
			if len(str(t)) == 1 and t != 1:
				return 0


class Solution:

	def happyNum(self, n: int, e: int) -> int:
		x = str(n)
		a = 0
		for i in x:
			a += int(i) ** 2
		if e == 200:
			return 0
		if a == 1:
			return 1
		else:
			e += 1
			return self.happyNum(a, e)

	def isHappy(self, n: int) -> int:
		a = 0
		x = self.happyNum(n, a)
		return x


class Solution:

	def isHappy(self, N):
		summ = 0
		while N > 0:
			r = N % 10
			summ += r * r
			N = N // 10
		if summ == 1:
			return 1
		if summ < 10:
			return 0
		return self.isHappy(summ)


class Solution:

	def find(self, n):
		t = 0
		n = str(n)
		for i in n:
			t += int(i) ** 2
		return t

	def isHappy(self, N):
		num = set()
		result = N
		while self.find(result) not in num:
			result = self.find(result)
			if result == 1:
				return 1
			else:
				num.add(result)
		if result == 1:
			return 1
		else:
			return 0


class Solution:

	def happy(self, N):
		summ = 0
		for x in str(N):
			summ += int(x) ** 2
		return summ

	def isHappy(self, N):
		res = N
		flag = True
		while flag:
			res = Solution.happy(self, res)
			if res == 1:
				return 1
			if res < 10:
				return 0
				flag = False


class Solution:

	def isHappy(self, N):
		memo = {}
		return self.happyNumber(N, memo)

	def happyNumber(self, n, memo):
		if n == 1:
			return 1
		if n in memo:
			return 0
		memo[n] = 1
		s = str(n)
		lst = list(s)
		lst = list(map(int, lst))
		temp = 0
		for i in range(len(lst)):
			temp = temp + lst[i] ** 2
		return self.happyNumber(temp, memo)


class Solution:

	def isHappy(self, N):
		prev = {}
		if N == 1:
			return 1
		while N > 1:
			nstr = str(N)
			total = 0
			for i in nstr:
				total += int(i) ** 2
			if total == 1:
				return 1
			else:
				N = total
			if total in prev:
				break
			else:
				prev[total] = 1
		return 0


class Solution:

	def isHappy(self, N):
		slow = N
		fast = N
		while True:
			slow = self.sumofsquares(slow)
			fast = self.sumofsquares(self.sumofsquares(fast))
			if slow != fast:
				continue
			else:
				break
		if slow == 1:
			return 1
		else:
			return 0

	def sumofsquares(self, n):
		s = 0
		while n > 0:
			s += n % 10 * (n % 10)
			n = n // 10
		return s


class Solution:

	def isHappy(self, N):

		def happy(n):
			temp = n
			a = 0
			while temp:
				rem = temp % 10
				temp = temp // 10
				a += rem * rem
			if a > 9:
				return happy(a)
			if a == 1:
				return 1
			return 0
		return happy(N)


class Solution:

	def isHappy(self, N):

		def square(N):
			sum = 0
			while N:
				digit = N % 10
				sum += digit * digit
				N //= 10
			return sum
		fast = square(square(N))
		slow = square(N)
		while fast != slow:
			fast = square(square(fast))
			slow = square(slow)
		return 1 if fast == 1 else 0


def square_sum(num):
	s = 0
	while num > 0:
		d = num % 10
		s += d * d
		num = num // 10
	return s

class Solution:

	def isHappy(self, N):
		fast = slow = N
		while True:
			slow = square_sum(slow)
			fast = square_sum(square_sum(fast))
			if slow == fast:
				break
		if slow == 1:
			return 1
		return 0


class Solution:

	def isHappy(self, N):
		m = set()
		while N != 1:
			N = sum([int(i) ** 2 for i in str(N)])
			if N not in m:
				m.add(N)
			else:
				return 0
		return 1


class Solution:

	def isHappy(self, N):

		def hpnum(n):
			m = 0
			while n:
				k = n % 10
				n = n // 10
				m = m + k * k
			if m < 10 and (m == 1 or m == 7):
				return 1
			if m < 10:
				return 0
			a = hpnum(m)
			return a
		if N == 1 or N == 7:
			return 1
		else:
			return hpnum(N)


class Solution:

	def isHappy(self, N):

		def happy(num):
			sum_squ = 0
			while num != 0:
				r = num % 10
				sum_squ += r * r
				num //= 10
			if sum_squ < 10 and (sum_squ == 1 or sum_squ == 7):
				return 1
			if sum_squ < 10:
				return 0
			a = happy(sum_squ)
			return a
		if N == 1 or N == 7:
			return 1
		final = happy(N)
		return final


class Solution:

	def isHappy(self, N):
		x = N
		if x == 7:
			return 1
		elif x <= 6 and x >= 1 or x == 8:
			return 0
		while x > 9:
			i = 0
			x = 0
			N = str(N)
			while i < len(N):
				x = x + int(N[i]) ** 2
				i = i + 1
			N = x
		if x == 1:
			return 1
		return 0


from functools import reduce

class Solution:

	def isHappy(self, N):

		def square(n):
			arr = list(map(int, str(n).strip()))
			temp = list(map(lambda x: x ** 2, arr))
			x = reduce(lambda x, y: x + y, temp)
			return x
		n = N
		arr = [N]
		while True:
			n = square(n)
			if n == 1:
				return 1
			if n in arr:
				return 0
			arr.append(n)


class Solution:

	def find_sum(self, num):
		sum_v = 0
		while num > 0:
			n = num % 10
			sum_v += n * n
			num = num // 10
		return sum_v

	def isHappy(self, N):
		slow = fast = N
		while 1:
			slow = self.find_sum(slow)
			fast = self.find_sum(self.find_sum(fast))
			if slow == fast:
				break
		if slow == 1:
			return 1
		return 0


class Solution:

	def isHappy(self, N):

		def sqsum(num):
			total = 0
			while num > 0:
				r = num % 10
				total = total + r ** 2
				num = num // 10
			return total
		ans = set()
		while sqsum(N) not in ans:
			res = sqsum(N)
			if res == 1:
				return 1
			else:
				ans.add(res)
				N = res
		return 0


class Solution:

	def isHappy(self, n):
		if n == 1 or n == 7:
			return 1
		su = n
		x = n
		while su > 9:
			su = 0
			while x > 0:
				d = x % 10
				su += d * d
				x //= 10
			if su == 1:
				return 1
			x = su
		if su == 7:
			return 1
		return 0


class Solution:

	def squareOfNumber(self, num):
		ans = 0
		while num > 0:
			rem = num % 10
			ans += rem * rem
			num //= 10
		return ans

	def isHappy(self, n):
		slow = n
		fast = n
		slow = self.squareOfNumber(slow)
		fast = self.squareOfNumber(self.squareOfNumber(fast))
		while slow != fast:
			slow = self.squareOfNumber(slow)
			fast = self.squareOfNumber(self.squareOfNumber(fast))
		if slow == 1:
			return 1
		return 0


class Solution:

	def isHappy(self, N):
		a = []
		while N not in a:
			a.append(N)
			N = str(N)
			c = 0
			for i in N:
				c += int(i) ** 2
			if c == 1:
				return 1
			N = c
		return 0


class Solution:

	def isHappy(self, N):
		x = N
		x = str(x)
		x = list(x)
		my = []
		while True:
			s = 0
			for value in x:
				s = s + int(value) ** 2
			if s == 1:
				return 1
			if s not in my:
				my.append(s)
			else:
				return 0
			x = list(str(s))


class Solution:

	def sumsq(self, n):
		s = 0
		while n > 0:
			d = n % 10
			s += d * d
			n = n // 10
		return s

	def isHappy(self, N):
		(p, q) = (N, N)
		while True:
			p = self.sumsq(self.sumsq(p))
			q = self.sumsq(q)
			if p == q:
				break
		if q == 1:
			return 1
		else:
			return 0


class Solution:

	def isHappy(self, N):
		solves = []
		summ = N
		num = N
		while summ not in solves:
			solves.append(summ)
			digits = []
			while summ > 0:
				r = summ % 10
				summ = summ // 10
				digits.append(r)
			summ = sum(map(lambda x: x * x, digits))
			if summ == 1:
				return 1
		return 0


class Solution:

	def isHappy(self, N):
		sum1 = 0
		while True:
			rem = N % 10
			N = N // 10
			sum1 = sum1 + rem * rem
			if N == 0:
				N = sum1
				sum1 = 0
				if N >= 1 and N <= 9:
					break
		if N == 1:
			return 1
		else:
			return 0