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;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {

    public static void main(String[] args) throws IOException {
        new B().solve();
    }

    private void solve() throws IOException {
        MyScanner in = new MyScanner(new BufferedReader(new InputStreamReader(System.in)));
        Bigi bigi = new Bigi(in.nextToken());
        in.close();
        String veryHappy = bigi.findVeryHappy();
        PrintWriter pw = new PrintWriter(System.out);
        pw.println(veryHappy);
        pw.close();
    }

    static class Container {
        final int n;
        int rest4;
        int rest7;
        int[] a;
        int pos;

        Container(int cntOfSingleDigit) {
            this.n = cntOfSingleDigit * 2;
            this.a = new int[n];
            rest4 = cntOfSingleDigit;
            rest7 = cntOfSingleDigit;
            pos = 0;
        }

        boolean add4() {
            if (rest4 > 0) {
                rest4--;
                a[pos++] = 4;
                return true;
            }
            return false;
        }

        boolean add7() {
            if (rest7 > 0) {
                rest7--;
                a[pos++] = 7;
                return true;
            }
            return false;
        }

        String fillAny() {
            while (add4()) {}
            while (add7()) {}
            return asStr();
        }

        String asStr() {
            StringBuilder st = new StringBuilder();
            for (int i = 0; i < n; i++) {
                st.append((char) (a[i] + '0'));
            }
            return st.toString();
        }

        boolean upLast4() {
            for (int i = pos - 1; i >= 0; i--) {
                if (a[i] == 7) {
                    rest7++;
                } else {
                    rest4++;
                    if (rest7 > 0) {
                        pos = i;
                        return add7();
                    }
                }
            }
            return false;
        }
    }

    private class Bigi {
        final int[] d;
        final int n;

        public Bigi(String s) {
            n = s.length();
            d = new int[n];
            for (int i = 0; i < n; i++) {
                d[i] = s.charAt(i) - '0';
            }
        }

        public String findVeryHappy() {
            if (n % 2 != 0) {
                return veryHappyAndBigger();
            }
            Container c = new Container(n / 2);
            for (int i = 0; i < n; i++) {
                int digit = d[i];
                if (digit < 4) {
                    break;
                } else if (digit == 4) {
                    if (!c.add4()) {
                        c.add7();
                        break;
                    }
                } else if (digit <= 7) {
                    if (c.add7()) {
                        if (digit < 7) {
                            break;
                        }
                    } else if (c.upLast4()) {
                        break;
                    } else {
                        return veryHappyAndBigger();
                    }
                } else {
                    if (c.upLast4()) {
                        break;
                    } else {
                        return veryHappyAndBigger();
                    }
                }
            }
            return c.fillAny();
        }

        String veryHappyAndBigger() {
            Container c = new Container((n + 2) / 2);
            return c.fillAny();
        }
    }

    static class MyScanner {
        BufferedReader myBr;
        StringTokenizer st = new StringTokenizer("");

        MyScanner(BufferedReader br) {
            myBr = br;
        }

        public void close() throws IOException {
            myBr.close();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(nextToken());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(nextToken());
        }

        long nextLong() throws IOException {
            return Long.parseLong(nextToken());
        }

        String nextToken() throws IOException {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(myBr.readLine());
            }
            return st.nextToken();
        }
    }

}