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:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Ahmed
 */
public class Watermelon {

    private static int mod(int x, int y) {
        int result = x % y;
        return result < 0 ? result + y : result;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner in = new Scanner(System.in);

        long n = in.nextLong();

        /*   if (isSuperLucky(n + "")) {
            System.out.println(n);
            return;
        }
         */
        if (isSuperLucky(n + "")) {
            System.out.println(n);
            return;
        }

        int length = (n + "").length();
        if (length % 2 != 0) {
            n = PlusNumber((n + ""));
        } else {

            n = check(n + "");
        }

        for (long i = n; i <= Long.MAX_VALUE; ++i) {
            //  System.out.println(i);

            if (isSuperLucky(i + "")) {
                System.out.println(i);
                return;
            }
        }
    }

    public static long check(String num) {
        int first = Integer.parseInt(num.charAt(0) + "");

        if (first < 4) {
            String snum = "";
            for (int i = 0; i < num.length(); ++i) {
                snum = snum + "4";
            }

            return Long.parseLong(snum);
        }

        if (first == 4) {
            return Long.parseLong(num);
        }

        if (first < 7) {
            String snum = "7";
            for (int i = 0; i < num.length() - 1; ++i) {
                snum = snum + "4";
            }

            return Long.parseLong(snum);
        }

        if (first == 7) {

            if (isvaild(num)) {
                return Long.parseLong(num);
            }

            long f1 = PlusNumber(num);
            long f2 = PlusNumber(f1 + "");

            return f2;

        }

        long f1 = PlusNumber(num);
        long f2 = PlusNumber(f1 + "");

        return f2;
    }

    public static boolean isvaild(String num) {
        int count7 = 0;
        for (int i = 0; i < num.length(); ++i) {
            if (num.charAt(i) == '7') {
                ++count7;
            }
        }

        if ((Integer.parseInt(num.length() + "") / 2) == count7) {
            for (int i = 0; i < num.length(); ++i) {
                int n = Integer.parseInt(num.charAt(i) + "");

                if (n != 7 && n > 4) {
                    return false;
                }
            }
            return true;
        } else {
            if (count7 > (Integer.parseInt(num.length() + "") / 2) ) {
                return false;
            } else {
                for (int i = 0; i < num.length(); ++i) {
                    int n = Integer.parseInt(num.charAt(i) + "");

                    if (n > 7 && n > 4) {
                        return false;
                    }
                }
                return true;
            }
        }
    }

    public static long PlusNumber(String num) {
        int length = (num).length();
        int a1 = (length + 1);
        num = "";
        for (int i = 0; i < a1; ++i) {
            num = num + "4";
        }

        return Long.parseLong(num);
    }

    public static boolean isSuperLucky(String s) {

        int count4 = 0, count7 = 0;

        for (int i = 0; i < s.length(); ++i) {
            char a = s.charAt(i);

            if (a != '7' && a != '4') {
                return false;
            }

            if (a == '7') {
                count7++;
            } else {
                count4++;
            }

        }

        if (count4 == count7) {
            return true;
        } else {
            return false;
        }
    }

}

class obj implements Comparable {

    public int number;
    public int index;

    @Override
    public int compareTo(Object o) {
        obj f = (obj) o;
        return this.number - f.number;
    }

}