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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class B {
    public static void decrease(char[] s) {
        for (int i = s.length - 1; i >= 0; i--) {
            if (s[i] > '0') {
                s[i] = (char) (s[i] - 1);
                break;
            } else {
                s[i] = '9';
            }
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char[] s = br.readLine().toCharArray(), c = null;
        if(s.length>1)
        decrease(s);
        if (s[0] == '0') {
            s = new String(s).substring(1).toCharArray();
        }
        //System.out.println(s);
        if (s.length % 2 == 1) {
            c = new char[s.length + 1];
            int min = c.length / 2;
            for (int i = 0; i < min; i++)
                c[i] = '4';
            for (int i = min; i < c.length; i++)
                c[i] = '7';
        } else {
            if (s[0] < '4') {
                c = new char[s.length];
                int min = c.length / 2;
                for (int i = 0; i < min; i++)
                    c[i] = '4';
                for (int i = min; i < c.length; i++)
                    c[i] = '7';
            } else if (s[0] > '7') {
                c = new char[s.length + 2];
                int min = c.length / 2;
                for (int i = 0; i < min; i++)
                    c[i] = '4';
                for (int i = min; i < c.length; i++)
                    c[i] = '7';
            } else if (s[0] == '5' || s[0] == '6') {
                c = new char[s.length];
                int min = c.length / 2;
                c[0] = '7';
                for (int i = 1; i <= min; i++)
                    c[i] = '4';
                for (int i = min + 1; i < c.length; i++)
                    c[i] = '7';
            } else {
                if (s[0] == '4') {
                    boolean more = false;
                    c = new char[s.length];
                    int count4 = s.length / 2;
                    int count7 = count4;
                    int prevIdx = 0, prev4 = count4, prev7 = count7, idx = -1;
                    c[0] = '4';
                    count4--;
                    for (int i = 1; i < s.length; i++) {
                        if (s[i] < '4') {
                            if (count4 > 0) {
                                c[i] = '4';
                                count4--;
                                more = true;
                                idx = i + 1;
                                break;
                            } else {
                                c[i] = '7';
                                count7--;
                                more = true;
                                idx = i + 1;
                                ;
                                break;
                            }
                        } else if (s[i] > '7') {
                            break;
                        } else if (s[i] == '5'||s[i]=='6') {
                            if (count7 > 0) {
                                c[i] = '7';
                                count7--;
                                more = true;
                                idx = i + 1;
                                break;
                            } else {
                                break;
                            }
                        } else if (s[i] == '4') {
                            if (count4 > 0) {
                                c[i] = '4';
                                if (count7 > 0) {
                                    prevIdx = i;
                                    prev4 = count4;
                                    prev7 = count7;
                                }
                                count4--;
                            } else {
                                c[i] = '7';
                                count7--;
                                more = true;
                                idx = i + 1;
                                ;
                                break;
                            }
                        } else {
                            if (count7 > 0) {
                                c[i] = '7';
                                count7--;
                            } else {
                                break;
                            }
                        }
                    }
                    if (!more) {
                        c[prevIdx++] = '7';
                        prev7--;
                        for (; prev4 > 0; prevIdx++, prev4--)
                            c[prevIdx] = '4';
                        for (; prev7 > 0; prevIdx++, prev7--)
                            c[prevIdx] = '7';
                    } else {
                        for (; count4 > 0; count4--, idx++) {
                            c[idx] = '4';
                        }
                        for (; count7 > 0; count7--, idx++) {
                            c[idx] = '7';
                        }
                    }
                } else {
                    boolean more = false;
                    c = new char[s.length];
                    int count4 = s.length / 2;
                    int count7 = count4;
                    int prevIdx = -1, prev4 = -1, prev7 = -1, idx = -1;
                    c[0] = '7';
                    count7--;
                    for (int i = 1; i < s.length; i++) {
                        if (s[i] < '4') {
                            if (count4 > 0) {
                                c[i] = '4';
                                count4--;
                                more = true;
                                idx = i + 1;
                                break;
                            } else {
                                c[i] = '7';
                                count7--;
                                more = true;
                                idx = i + 1;
                                break;
                            }
                        } else if (s[i] > '7') {
                            break;
                        } else if (s[i] == '5'||s[i]=='6') {
                            if (count7 > 0) {
                                c[i] = '7';
                                count7--;
                                more = true;
                                idx = i + 1;
                                break;
                            } else {
                                break;
                            }
                        } else if (s[i] == '4') {
                            if (count4 > 0) {
                                c[i] = '4';
                                if (count7 > 0) {
                                    prevIdx = i;
                                    prev4 = count4;
                                    prev7 = count7;
                                }
                                count4--;
                            } else {
                                c[i] = '7';
                                count7--;
                                more = true;
                                idx = i + 1;
                                break;
                            }
                        } else {
                            if (count7 > 0) {
                                c[i] = '7';
                                count7--;
                            } else {
                                break;
                            }
                        }
                    }
                    if (!more) {
                        if (prevIdx == -1) {
                            c = new char[s.length + 2];
                            int min = c.length / 2;
                            for (int i = 0; i < min; i++)
                                c[i] = '4';
                            for (int i = min; i < c.length; i++)
                                c[i] = '7';
                        } else {
                            c[prevIdx++] = '7';
                            prev7--;
                            for (; prev4 > 0; prevIdx++, prev4--)
                                c[prevIdx] = '4';
                            for (; prev7 > 0; prevIdx++, prev7--)
                                c[prevIdx] = '7';
                        }
                    } else {
                        for (; count4 > 0; count4--, idx++) {
                            c[idx] = '4';
                        }
                        for (; count7 > 0; count7--, idx++) {
                            c[idx] = '7';
                        }
                    }
                }
            }
        }
        System.out.println(new String(c));
    }
}