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:
import math
from collections import defaultdict, Counter

R = lambda: map(int, input().split())
org = input()
num = [x for x in org]
n = len(num)
mi, mx = '4' * ((n + 1) // 2) + '7' * ((n + 1) // 2),  '7' * ((n + 1) // 2) + '4' * ((n + 1) // 2)
if n % 2:
    print(mi)
    exit(0)
if ''.join(num) > mx:
    print('4' + mi + '7')
    exit(0)
b, sc, fc = -1, 0, 0
for i in range(n):
    if num[i] != '4' and num[i] != '7':
        b = i
        break
    sc += num[i] == '7'
    fc += num[i] == '4'
    if sc > n // 2 or fc > n // 2:
        b = i
        break
if b == -1:
    if sc != n // 2 or fc != n // 2:
        print('1 ' + str(sc) + ' ' + str(fc))
    else:
        print(org)
elif num[b] < '4':
    res = ''.join(num[:b]) + '4' * (n // 2 - fc) + '7' * (n // 2 - sc)
    if res < ''.join(num) or res.count('4') != res.count('7'):
        print('2 ' + str(sc) + ' ' + str(fc))
    else:
        print(res)
elif num[b] < '7':
    res = ''.join(num[:b]) + '7' + '4' * (n // 2 - fc) + '7' * (n // 2 - sc - 1)
    if res < ''.join(num) or res.count('4') != res.count('7'):
        print('3 ' + str(sc) + ' ' + str(fc))
    else:
        print(res)
else:
    sc -= num[b] == '7'
    while num[b - 1] != '4' or n // 2 - sc <= 0:
        sc -= num[b - 1] == '7'
        fc -= num[b - 1] == '4'
        b -= 1
    b -= 1
    fc -= 1
    res = ''.join(num[:b]) + '7' + '4' * (n // 2 - fc) + '7' * (n // 2 - sc - 1)
    if res < ''.join(num) or res.count('4') != res.count('7'):
        print('4 ' + str(sc) + ' ' + str(fc) + ' ' + str(res.count('4')) + ' ' + str(res.count('7')) + ' ' + str(n))
    else:
        print(res)