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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int[] number = readNumber(in);

            if (checkNewBigger(number)) {
                int nextLen = number.length + 1;
                if (nextLen % 2 == 1) {
                    ++nextLen;
                }
                for (int i = 0; i < nextLen / 2; ++i) {
                    out.print('4');
                }
                for (int i = 0; i < nextLen / 2; ++i) {
                    out.print('7');
                }
                return;
            }
            number = transformToFirstBigger(number);
            int[] sum4 = new int[number.length];
            for (int i = 0; i < number.length; ++i) {
                if (i == 0) {
                    sum4[i] = (number[i] == 4 ? 1 : 0);
                } else {
                    sum4[i] = (number[i] == 4 ? 1 : 0) + sum4[i - 1];
                }
            }

            if (sum4[number.length - 1] == number.length - sum4[number.length - 1]) {
                for (int i = 0; i < number.length; ++i) {
                    out.print(number[i]);
                }
                out.println();
                return;
            }
            for (int i = number.length - 2; i >= 0; --i) {
                int spots = number.length - 1 - i;
                int am4 = sum4[i];
                int am7 = i + 1 - sum4[i];


                if (number[i + 1] == 4) {
                    number[i + 1] = 7;
                    ++am7;
                    int delta = Math.abs(am4 - am7);
                    --spots;
                    ++i;
                    if (delta <= spots) {
                        spots -= delta;
                        if (spots % 2 == 0) {
                            for (int j = 0; j <= i; ++j) {
                                out.print(number[j]);
                            }
                            while (am4 < am7) {
                                out.print(4);
                                ++am4;
                            }
                            spots /= 2;
                            for (int j = 0; j < spots; ++j) {
                                out.print(4);
                            }
                            for (int j = 0; j < spots; ++j) {
                                out.print(7);
                            }
                            while (am4 > am7) {
                                out.print(7);
                                ++am7;
                            }
                            out.println();
                            return;
                        }
                    }
                    --i;
                    number[i + 1] = 4;

                }
            }
            if (number[0] == 4) {
                if (number.length % 2 == 0) {
                    out.print(7);
                    int len = number.length / 2;
                    for (int i = 0; i < len; ++i) {
                        out.print(4);
                    }
                    --len;
                    for (int i = 0; i < len; ++i) {
                        out.print(7);
                    }
                    return;
                }
            }
            int nextLen = number.length + 1;
            if (nextLen % 2 == 1) {
                ++nextLen;
            }
            for (int i = 0; i < nextLen / 2; ++i) {
                out.print('4');
            }
            for (int i = 0; i < nextLen / 2; ++i) {
                out.print('7');
            }
        }

        private boolean checkNewBigger(int[] number) {
            for (int i = 0; i < number.length; ++i) {
                if (number[i] < 7) {
                    return false;
                } else if (number[i] > 7) {
                    return true;
                }
            }
            return false;
        }

        private int[] transformToFirstBigger(int[] number) {
            if (number.length % 2 == 1) {
                number = new int[number.length + 1];
                for (int i = 0; i < number.length; ++i) {
                    number[i] = 4;
                }
                return number;
            }
            int id = -1;
            for (int i = 0; i < number.length; ++i) {
                if (number[i] < 4) {
                    number[i] = 4;
                    for (int j = i + 1; j < number.length; ++j) {
                        number[j] = 4;
                    }
                    return number;
                }
                if (number[i] == 4) {
                    id = i;
                }
                if (number[i] > 4 && number[i] < 7) {
                    number[i] = 7;
                    for (int j = i + 1; j < number.length; ++j) {
                        number[j] = 4;
                    }
                    return number;
                }
                if (number[i] > 7) {
                    number[id] = 7;
                    for (int j = id + 1; j < number.length; ++j) {
                        number[j] = 4;
                    }
                    return number;
                }
            }
            return number;
        }

        private int[] readNumber(InputReader in) {
            char[] s = in.next().toCharArray();
            int[] r = new int[s.length];
            for (int i = 0; i < s.length; ++i) {
                r[i] = s[i] - '0';
            }
            return r;
        }

    }

    static class InputReader {
        private StringTokenizer tokenizer;
        private BufferedReader reader;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private void fillTokenizer() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        public String next() {
            fillTokenizer();
            return tokenizer.nextToken();
        }

    }
}