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 javax.lang.model.type.ArrayType;

import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Short.parseShort;
import static java.lang.Byte.parseByte;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;

public class Contest {

    static int nextInt() throws IOException {
        return parseInt(next());
    }

    static long nextLong() throws IOException {
        return parseLong(next());
    }

    static short nextShort() throws IOException {
        return parseShort(next());
    }

    static byte nextByte() throws IOException {
        return parseByte(next());
    }

    static String next() throws IOException {
        while (tok == null || !tok.hasMoreTokens())
            tok = new StringTokenizer(in.readLine());
        return tok.nextToken();
    }

    static String nextLine() throws IOException {
        return in.readLine();
    }

    private static BufferedReader in;
    private static StringTokenizer tok;
    private static PrintWriter out = new PrintWriter(System.out);
    static int f[] = new int[5];

    public static void main(String[] args) throws Exception {
        in = new BufferedReader(new InputStreamReader(System.in));

        /*--------------------SolutionStarted-------------------*/
        solve();
        /*--------------------SolutionEnded--------------------*/

        in.close();
        out.close();
    }
    static ArrayList<Integer> permutations= new ArrayList<>(100000);
    static void solve() throws IOException {
        int n = nextInt(), digits;
        String s = n+"";
        digits = s.length();
        if (digits%2==1){
            for (int i = 0; i <=(digits/2) ; i++) {
                out.print(4);
            }
            for (int i = 0; i <=(digits/2) ; i++) {
                out.print(7);
            }
        }else if(n==1000000000){
            out.print("4444477777");
        }else{
            s = "";
            for (int i = 0; i <digits/2 ; i++) {
                s+="4";
            }
            for (int i = 0; i < digits/2; i++) {
                s+="7";
            }
            permutations(s,"");
            Collections.sort(permutations);
            int size = permutations.size();
            for (int i = 0; i < size; i++) {
                if(n<=permutations.get(i)){
                    out.print(permutations.get(i));
                    return;
                }
            }
            if(s.length()>=8){
                out.print("4444477777");
                return;
            }
            s = "";
            for (int i = 0; i <=digits/2 ; i++) {
                s+="4";
            }
            for (int i = 0; i <=digits/2; i++) {
                s+="7";
            }
            permutations.clear();
            permutations(s,"");
            Collections.sort(permutations);
            size = permutations.size();
            for (int i = 0; i < size; i++) {
                if(n<=permutations.get(i)){
                    out.print(permutations.get(i));
                    return;
                }
            }
        }
    }
    static void permutations(String str, String ans)
    {
        if (str.length() == 0) {
            permutations.add(Integer.parseInt(ans));
            return;
        }

        for (int i = 0; i < str.length(); i++) {

            char ch = str.charAt(i);
            String ros = str.substring(0, i) +
                    str.substring(i + 1);
            permutations(ros, ans + ch);
        }
    }
}
class Pair implements Comparable<Pair> {
    int key, value, size;
    Pair(){}
    Pair(int key, int value) {
        this.key = key;
        this.value = value;
    }
    @Override
    public int compareTo(Pair o) {
        return key - o.key;
    }
    public String toString(){
        return key+" "+value+" "+ size;
    }
}