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 P95B {

    static String str;
    static String ans;
    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        str = scanner.nextLine();
        int length = str.length();
        int num = length/2;
        if (length % 2 !=0) { 
            ans = smallest(num+1, num+1);
        } else {
            if (!nomore(str, largest(num, num))) {
                ans = smallest(num+1, num+1);
            } else {
                ans = buildAns(num, num);
            }
        }
        System.out.println(ans);
    }
    
    static private String buildAns(int n4, int n7) {
        int i = 0;
        StringBuilder sb = new StringBuilder();
        int j = -1;
        int tn4 = -1;
        int tn7 = -1;
        while (true) {
            if (i>=str.length()) {
                if (nomore(str, sb.toString())) {
                    return sb.toString();
                }
                return sb.substring(0, j)+ '7' + smallest(tn4, tn7);
            } else {
                int x = str.charAt(i) - '0';
                if (x<4) {
                    return sb.toString() + smallest(n4, n7);
                } else if (x>4 && x<=7 && n7>0) {
                    sb.append('7');
                    --n7;
                    if (x<7) {
                        return sb.toString() + smallest(n4,n7);
                    }
                } else if (x>7 || (x>4 && n7<=0)) {
                    return sb.substring(0, j)+ '7' + smallest(tn4, tn7);
                } else if (n4<=0) {
                    sb.append('7');
                    --n7;
                    return sb.toString() + smallest(n4, n7);
                } else {
                    sb.append('4');
                    --n4;
                    if (n7>0) {
                        j = i;
                        tn4 = n4+1;
                        tn7 = n7-1;
                    }
                }
                ++i;
            }
        }
    }
    
    static private String smallest(int n4, int n7) {
        StringBuilder sb = new StringBuilder();
        for (int i=0; i<n4; ++i) {
            sb.append('4');
        }
        for (int i=0; i<n7; ++i) {
            sb.append('7');
        }
        return sb.toString();
    }
    
    static private String largest(int n4, int n7) {
        StringBuilder sb = new StringBuilder();
        for (int i=0; i<n7; ++i) {
            sb.append('7');
        }
        for (int i=0; i<n4; ++i) {
            sb.append('4');
        }
        return sb.toString();
    }
    
    static private boolean nomore(String s1, String s2) {
        if (s1.length() < s2.length())
            return true;
        if (s1.length() > s2.length())
            return false;
        return s1.compareTo(s2)<=0;
    }

    
}