Problem: Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.

One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.

Input

The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.

Output

Output the least super lucky number that is more than or equal to n.

Examples

Input

4500


Output

4747


Input

47


Output

47

Solution (in PYTHON3):

Solution:
from collections import deque

n = int(input())

def isSuperLucky(n):
    fours = str(n).count('4') 
    sevens = str(n).count('7')
    return sevens > 0 and sevens == fours

class Node:
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None

    def find(self, target, t):
        if self.data >= target and isSuperLucky(self.data): 
            t.append(self.data)
        else:
            if self.left and self.right:
                l = self.left.find(target, t)
                if l:
                    t.append(l)
                r = self.right.find(target, t)
                if r:
                    t.append(r)

root = Node(0)
queue = deque([root])

while len(queue) > 0:
    node = queue.pop()
    node.left = Node((node.data*10) + 4)
    node.right = Node((node.data*10) + 7)

    if node.data < n:
        queue.append(node.left)
        queue.append(node.right)

t = []
root.find(n, t)
print(sorted(t)[0])