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 PYTHON):

Solution:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: d555_
# @Date:   2014-03-04 10:28:40
# @Last Modified by:   d555_
# @Last Modified time: 2014-03-17 22:32:24



def solve(n):
    s =str(n) # ver a n com una lista
    lenS = len(s)

    if lenS&1 : return '4'*((lenS+1)/2) + '7'*((lenS+1)/2) # O(len(n))
    if int(s[0]) < 4:   return '4'*(lenS/2) + '7'*(lenS/2) # O(len(n))
    if int(s[0]) > 7:   return '4'*(lenS/2 + 1) + '7'*(lenS/2 + 1) # O(len(n))

    # O(len(n))
    i = 0
    while i < lenS and (int(s[i]) == 7 or int(s[i]) == 4): i = i + 1
    if i > 0: s = s[:i] + '4'*len(s[i:])

    global b

    # O(1)
    b = [0] * lenS
    for j in range(i+1, lenS):
        if int(s[i]) > 4 :
            b[i] = 1
            break
    # return b
    # print "b1", b

    # O(len(n))
    def valorB():
        s, a = 0, 1
        i = len(b) - 1
        while i >= 0:
            s += 4*a if b[i] is 0 else 7*a
            a = a * 10
            i = i - 1
        return s

    # O(len(n))
    def incB(a):
        if len(a) <= len(b):
            a = [0]*(len(b) - len(a)) + a
        else:
            for i in range(len(a) - len(b)): b.insert(0,0)

        suma, carry, i = 0, 0, len(b) - 1

        while i >= 0:
            suma = b[i] + carry + a[i]
            carry = suma / 2
            b[i] = suma % 2
            i = i - 1
        if carry > 0: b.insert(0,1)
        return b

    # O(len(n))
    def aLista(n): return list(int(i) for i in str(n))
    # o(log(len(n)))
    def aBin(n, s = ''): return str(n) + s if n <= 1 else aBin(n/2) + str(n%2)

    while True:
        # print "b2", b
        # O(*len(n))
        if valorB() < n: incB([1]) # genera un O(n - 4*10**log_10 n)
        # O(len(n))
        elif len(b) > lenS: return '4'*(lenS/2 + 1) + '7'*(lenS/2 + 1)
        # O(len(n))
        elif b.count(0) == lenS: return '4'*(lenS/2) + '7'*(lenS/2)
        elif 2*sum(b) != lenS: # O(*len@n)
            unos = b.count(1) # O(len@n)
            ceros = lenS - unos
            if ceros > unos: d = (ceros - unos)/2
            else: d = (unos - ceros)/2
            # print j, sum(b),  "->", b
            d = max(1, d)
            incB([1]*d) # O(len@n)
        else: break

    return valorB()

a = int(raw_input())
print solve(a)