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:



number = list(input())

new_number = []

if len(number) % 2 == 0:

    already_bigger = False

    for digit in number:
        digit = int(digit)

        if already_bigger:
            new_number += [4]
        else:

            if digit == 4 or digit == 7:
                new_number += [digit]
            else:
                already_bigger = True
                if digit < 4:
                    new_number += [4]
                elif digit < 7:
                    new_number += [7]
                else:
                    if 4 in new_number:
                        new_number.reverse()
                        first_4 = new_number.index(4)
                        new_number = [4] * (len(new_number) - (len(new_number[first_4+1:]))) + [7] + new_number[first_4+1:]
                        new_number.reverse()
                    else:
                        new_number = [4] * (len(number) + 2)
                    break

else:
    new_number = [4] * (len(number) + 1)

of_4, of_7 = new_number.count(4), new_number.count(7)


if of_4 > of_7:
    new_number.reverse()
    missing = (of_4 - of_7)//2
    i = 0
    while i < len(new_number) and missing != 0:
        if new_number[i] == 4:
            new_number[i] = 7
            missing -= 1
        i += 1
    new_number.reverse()
elif of_7 > of_4:
    missing = (of_7 - of_4)//2 + 1
    if 4 in new_number and new_number.index(4) < len(new_number)//2:

        new_number.reverse()
        i = 0
        amount_of_7 = 0
        while amount_of_7 < missing:
            if new_number[i] == 7:
                amount_of_7 += 1
            i += 1
        while new_number[i] != 4:
            i += 1
        new_number[i] = 7
        i -= 1
        while missing != 0:
            if new_number[i] == 7:
                missing -= 1
                new_number[i] = 4
            i -= 1

    else:
        new_number = [7] * (len(new_number)//2 + 1) + [4] * (len(new_number)//2 + 1)
    
    new_number.reverse()

print(''.join(map(str,new_number)))