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.util.*;

public class Main {


    void solve() throws IOException {

        char[] s=nextToken().toCharArray();

        if(s.length%2!=0){
            int k=s.length+1;
            s=new char[k];
            for(int i=0;i<k/2;i++)
                s[i]='4';
            for(int i=0;i<k/2;i++)
                s[i+k/2]='7';
            out.print(new String(s));
        }
        else{
            boolean more=false;
            int fores=0;
            int sevens=0;
            int count=0;
            int wanted=s.length/2;
            int prev=-1;
            boolean good=true;
            for(int i=0;i<s.length;i++){
                if(more){
                    if(fores<wanted){
                        s[i]='4';
                        fores++;
                    }
                    else{
                        s[i]='7';
                        sevens++;
                    }
                }
                else{
                    if(s[i]=='4'){
                        if(fores==wanted){
                            s[i]='7';
                            sevens++;
                            more=true;
                        }
                        else{
                            prev=i;
                            count=sevens;
                            fores++;
                        }
                    }
                    else{
                        if(s[i]=='7'){
                            if(sevens==wanted){
                                good=false;
                                break;
                            }
                            else{
                                sevens++;
                            }
                        }
                        else{
                            if(s[i]<'4'){
                                if(fores==wanted){
                                    s[i]='7';
                                    sevens++;

                                }
                                else{
                                    s[i]='4';
                                    fores++;
                                }
                                more=true;
                            }
                            else{
                                if(s[i]<'7'){
                                    if(sevens==wanted){
                                        good=false;
                                        break;
                                    }
                                    else{
                                        s[i]='7';
                                        sevens++;
                                        more=true;
                                    }
                                }
                                else{
                                    good=false;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            if(!good){
                
                while(count==wanted||(prev>=0&&s[prev]!='4')){if(s[prev]=='7')count--;prev--;}
                if(prev==-1){
                    wanted++;
                    s=new char[wanted*2];
                    for(int i=0;i<wanted;i++)
                        s[i]='4';
                    for(int j=0;j<wanted;j++)
                        s[j+wanted]='7';
                    out.print(new String(s));
                }
                else{
                    fores=0;
                    sevens=0;
                    for(int i=0;i<prev;i++)
                        if(s[i]=='4')
                            fores++;
                        else
                            sevens++;
                    s[prev]='7';
                    sevens++;
                    for(int i=prev+1;i<s.length;i++)
                        if(fores<wanted){
                            s[i]='4';
                            fores++;
                        }
                        else{
                            s[i]='7';
                            sevens++;
                        }
                    out.print(new String(s));

                }
            }
            else{
                out.print(new String(s));

            }

        }

    }

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


   void run() throws IOException {
       reader = new BufferedReader(new InputStreamReader(System.in));
       tokenizer = null;
       out=new PrintWriter(new OutputStreamWriter(System.out));
       solve();
       reader.close();
       out.flush();

    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

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

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

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

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}