class Node:
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None
 
# Function to check if the tree is balanced or not
def is_balanced(root):
    if root is None:
        return True
    
    left_height = get_height(root.left)
    right_height = get_height(root.right)
    
    if abs(left_height - right_height) <= 1 and is_balanced(root.left) and is_balanced(root.right):
        return True
    
    return False
 
# Function to calculate the height of a given node
def get_height(node):
    if node is None:
        return 0
    
    left_height = get_height(node.left)
    right_height = get_height(node.right)
    
    return max(left_height, right_height) + 1
 
# Example tree
#         1
#       /   \
#      2     3
#     / \   / \
#    4   5 6   7
#             /
#            8
 
root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)
root.right.left = Node(6)
root.right.right = Node(7)
root.right.right.left = Node(8)
 
# Test the function
if is_balanced(root):
    print("The tree is balanced")
else:
    print("The tree is not balanced")