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

Solution:
import java.util.Scanner;

public class NewSolution {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        char[] arr = s.next().toCharArray();
        int n = arr.length;
        if (n%2==1) {
            int x = n/2+1;
            StringBuilder ans = new StringBuilder();
            for (int i=0; i<x; i++) ans.append("4");
            for (int i=0; i<x; i++) ans.append("7");
            System.out.println(ans);
            System.exit(0);
        }
        int fours = 0, sevens = 0, x = n/2, res = -1, resf = 0, ress = 0;
        char[] result = new char[n];
        StringBuilder ans = new StringBuilder();
        for (int i=0; i<n; i++) {
            if (arr[i]<'4') {
                result[i] = '4'; ans.append("4");
                fours++;
                for (int j=0; j<x - fours; j++) ans.append("4");
                for (int j=0; j<x - sevens; j++) ans.append("7");
                System.out.println(ans);
                System.exit(0);
            } else if (arr[i]=='4') {
                fours++; result[i] = '4'; ans.append("4");
                if (sevens+1<=x) {
                    res = i; resf = fours-1; ress = sevens+1;
                }
            } else if (arr[i]>'4' && arr[i]<'7') {
                result[i] = '7'; ans.append("7");
                sevens++;
                for (int j=0; j<x - fours; j++) ans.append("4");
                for (int j=0; j<x - sevens; j++) ans.append("7");
                System.out.println(ans);
                System.exit(0);
            } else if (arr[i]=='7') {
                sevens++; result[i] = '7'; ans.append("7");
            } else {
                ans = new StringBuilder();
                if (res==-1) {
                    for (int j=0; j<=x; j++) ans.append("4");
                    for (int j=0; j<=x; j++) ans.append("7");
                } else {
                    for (int j=0; j<res; j++) ans.append(arr[j]);
                    ans.append("7");
                    for (int j=0; j<x-resf; j++) ans.append("4");
                    for (int j=0; j<x-ress; j++) ans.append("7");
                }
                System.out.println(ans); break;
            }
            if (fours==x) {
                boolean withoutchange = true;
                for (int j=i+1; j<n; j++) {
                    if (arr[j]>'7') {
                        withoutchange = false; break;
                    }
                    ans.append("7");
                }
                if (!withoutchange) {
                    ans = new StringBuilder();
                    if (res==-1) {
                        for (int j=0; j<=x; j++) ans.append("4");
                        for (int j=0; j<=x; j++) ans.append("7");
                    } else {
                        for (int j=0; j<res; j++) ans.append(arr[j]);
                        ans.append("7");
                        for (int j=0; j<x-resf; j++) ans.append("4");
                        for (int j=0; j<x-ress; j++) ans.append("7");
                    }
                }
                System.out.println(ans); break;
            }
            if (sevens==x) {
                boolean withoutchange = true;
                for (int j=i+1; j<n; j++) {
                    if (arr[j]>'4') {
                        withoutchange = false; break;
                    }
                    ans.append("4");
                }
                if (!withoutchange) {
                    ans = new StringBuilder();
                    if (res==-1) {
                        for (int j=0; j<=x; j++) ans.append("4");
                        for (int j=0; j<=x; j++) ans.append("7");
                    } else {
                        for (int j=0; j<res; j++) ans.append(arr[j]);
                        ans.append("7");
                        for (int j=0; j<x-resf; j++) ans.append("4");
                        for (int j=0; j<x-ress; j++) ans.append("7");
                    }
                }
                System.out.println(ans); break;
            }
        }
    }
}