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.*;
import java.math.*;
import java.text.DecimalFormat;
import java.util.*;


public class Main {

    private static char [] S;

    private static boolean valid(int c4,int c7) {
        int need = Math.abs(c4 - c7);
        int m = c4 + c7 + need;
        if (m > S.length) return false;
        int r = S.length - m;
        if (r%2 == 1) return false;
        return true;
    }
    private static String  build(){
        int n = S.length + 1;
        if (n%2 == 1) n++;
        char [] O = new char[n];
        for (int i = 0;i < n/2;i++)
            O[i] = '4';
        for (int i = 0;i < n/2;i++)
            O[i + n/2] = '7';
        return new String(O);
    }

    private static String work(){
        int n = S.length;
        if (n%2 == 1) return null;
        int c4 = 0,c7 = 0,i = 0,left = -1;
        while (i < n){
            if (S[i] > '7') {
                if (left == -1) return null;
                S[left] = '7';
                c4 = c7 = 0;
                for (int j = 0;j <= left;j++) {
                    if (S[j] == '4') c4++;
                    else c7++;
                }
                i = left+1;
                break;
            }
            if (S[i] == '7' || S[i] == '4') {
                if (S[i] == '4') {
                    c4++;
                    left = i;
                }
                else c7++;
                i++;
            }
            else {
                if (S[i] > '4') {
                    S[i] = '7';
                    i++;
                    c7++;
                }
                else {
                    S[i] = '4';
                    i++;
                    c4++;
                }
                break;
            }
        }
        int t4 = 0,t7 = 0;
        if (c4 < c7) t4 = c7 - c4;
        if (c4 > c7) t7 = c4 - c7;
        int r = n - t4 - t7 - c4 - c7;
//        System.err.println(c4 + " " + c7);
//        System.err.println(t4 + " " + t7);
//        System.err.println("i = " + i);

        if (r < 0 || r%2 == 1) {
            i = 0;
            c4 = c7 = 0;
            int lst = -1;
            while (i < n) {
                if (S[i] == '4' && valid(c4,c7+1))
                    lst = i;
                if (S[i] == '4') c4++;
                else c7++;
                i++;
            }
            if (lst == -1) return null;
            i = c4 = c7 = 0;
            while (i < lst){
                if (S[i] == '4') c4++;
                else c7++;
                i++;
            }
            S[i++] = '7';
            c7++;
            t4 = t7 = 0;
            if (c4 < c7) t4 = c7 - c4;
            if (c4 > c7) t7 = c4 - c7;
            r = n - t4 - t7 - c4 - c7;
        }
        t4 += r/2;
        t7 += r/2;
        while (t4 > 0){
            S[i] = '4';
            i++;
            t4--;
        }
        while (t7 > 0){
            S[i] = '7';
            i++;
            t7--;
        }
        return new String(S);
    }
    public static void main(String[] args) throws Exception{
        IO io = new IO(null,null);
        S = io.getNext().toCharArray();
        String O = work();
        if (O == null) O = build();
        io.println(O);
        io.close();
    }
}

class point{
    private static DecimalFormat df = new DecimalFormat("#.###");
    double x,y;
    public point(double x,double y){
        this.x = x;
        this.y = y;
    }
    point vec(point to) {
        return new point(to.x - x,to.y - y);
    }
    public double length(){
        return Math.sqrt(x*x + y*y);
    }
    @Override
    public String toString(){
        return "(" + df.format(x) + ", " + df.format(y) + ")";
    }
    double dot(point p) {
        return x*p.x + y*p.y;
    }
    double cross(point p) {
        return x*p.y - y*p.x;
    }
}


class IO{
    private BufferedReader br;
    private StringTokenizer st;
    private PrintWriter writer;
    private String inputFile,outputFile;

    public boolean hasMore() throws IOException{
        if(st != null && st.hasMoreTokens()) return true;
        if(br != null && br.ready()) return true;
        return false;
    }
    public String getNext() throws FileNotFoundException, IOException{
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public String getNextLine() throws FileNotFoundException, IOException{
        return br.readLine().trim();
    }

    public int getNextInt() throws FileNotFoundException, IOException{
        return Integer.parseInt(getNext());
    }
    public long getNextLong() throws FileNotFoundException, IOException{
        return Long.parseLong(getNext());
    }

    public void print(double x,int num_digits) throws  IOException{
        writer.printf("%." + num_digits + "f" ,x);
    }
    public void println(double x,int num_digits) throws  IOException{
        writer.printf("%." + num_digits + "f\n" ,x);
    }
    public void print(Object o) throws  IOException{
        writer.print(o.toString());
    }

    public void println(Object o) throws  IOException{
        writer.println(o.toString());
    }
    public IO(String x,String y) throws FileNotFoundException, IOException{
        inputFile = x;
        outputFile = y;
        if(x != null) br = new BufferedReader(new FileReader(inputFile));
        else br = new BufferedReader(new InputStreamReader(System.in));
        if(y != null) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));
        else writer = new PrintWriter(new OutputStreamWriter(System.out));
    }

    protected void close() throws IOException{
        br.close();
        writer.close();
    }
    public void outputArr(Object [] A) throws IOException{
        int L = A.length;
        for (int i = 0;i < L;i++) {
            if(i > 0) writer.print(" ");
            writer.print(A[i]);
        }
        writer.print("\n");
    }
}