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

public class B implements Runnable {
    private Scanner in;
    private PrintWriter out;

    private void solve() {
        char[] num = in.next().toCharArray();
        int len = num.length;
        if (len % 2 == 1) {
            char[] min = new char[len + 1];
            for (int i = 0; i < (len + 1) / 2; ++i) {
                min[i] = '4';
                min[i + (len + 1) / 2] = '7';
            }
            out.println(new String(min));
            return;
        }
        char[] max = new char[len];
        for (int i = 0; i < len / 2; ++i) {
            max[i] = '7';
            max[i + len / 2] = '4';
        }
        boolean maxIsLess = false;
        for (int i = 0; i < len; ++i) {
            if (max[i] < num[i]) {
                maxIsLess = true;
                break;
            } else if (max[i] > num[i]) {
                break;
            }
        }
        if (maxIsLess) {
            char[] min = new char[len + 2];
            for (int i = 0; i < (len + 2) / 2; ++i) {
                min[i] = '4';
                min[i + (len + 2) / 2] = '7';
            }
            out.println(new String(min));
            return;
        }
        int n4 = 0, n7 = 0;
        int last4 = -1;
        for (int i = 0; i < len; ++i) {
            if (num[i] < '4') {
                max[i] = '4';
                ++n4;
                for (int j = i + 1; j < len; ++j) {
                    max[j] = '4';
                    ++n4;
                }
                break;
            } else if (num[i] == '4') {
                max[i] = '4';
                ++n4;
                last4 = i;
            } else if (num[i] < '7') {
                max[i] = '7';
                ++n7;
                for (int j = i + 1; j < len; ++j) {
                    max[j] = '4';
                    ++n4;
                }
                break;
            } else if (num[i] == '7') {
                max[i] = '7';
                ++n7;
            } else {
                max[last4] = '7';
                ++n7;
                max[i] = '4';
                for (int j = i + 1; j < len; ++j) {
                    max[j] = '4';
                    ++n4;
                }
                break;
            }
        }
        if (n7 > n4) {
            for (int i = len - 1; i >= 0; --i) {
                if (max[i] == '4') {
                    --n4;
                } else {
                    --n7;
                }
                if (max[i] == '4' && n7 + 1 <= n4 + (len - 1 - i)) {
                    max[i] = '7';
                    ++n7;
                    for (int j = i + 1; j < len; ++j) {
                        max[j] = '4';
                        ++n4;
                    }
                    break;
                }
            }
        }
        if (n4 > n7) {
            for (int i = len - 1; i >= 0; --i) {
                if (max[i] == '4') {
                    max[i] = '7';
                    --n4;
                    ++n7;
                }
                if (n4 == n7) {
                    break;
                }
            }
        } 
        out.println(new String(max));
    }

    @Override
    public void run() {
        in = new Scanner(System.in);
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

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