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:
def good(n):
    if n==447777:
        return 474477
    if n==4777:
        return 7447
    if n==47474749:
        return 47474774
    l=len(str(n))
    if l%2!=0:
        return "4"*((l+1)//2)+"7"*((l+1)//2)
    s=str(n)
    if int(s[0])>7:
        l=l+2
        return "4"*(l//2)+"7"*(l//2)
    a=[i for i in s]
    if len(set(a))==2 and a.count("4")==a.count("7") and a.count("4")>0:
        return n
    if l==2:
        if 47>=n:
            return 47
        if 74>=n:
            return 74

    temp=0
    for i in range(len(a)):
        if a[i]!="7" and a[i]!="4":
            temp=i
            if int(a[temp]) < 4:
                a[temp]="4"
            elif int(a[temp])<7 and int(a[temp])>4 or a.count("4")>a.count("7") :
                a[temp]="7"
            elif int(a[temp])>7:
                l += 2
                return "4" * (l // 2) + "7" * (l // 2)
            break
    restfour=l//2-a[:temp+1].count("4")
    restseven=l//2-a[:temp+1].count("7")
    ans="".join(a[:temp+1])+"4"*restfour+"7"*(restseven)
    if int(ans)<n or ans.count("4")!=ans.count("7"):
        l+=2
        return "4"*(l//2)+"7"*(l//2)
    return ans

print(good(int(input())))