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 Solution {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
    
        String n=in.next();
        
        if (n.length()%2==1)
        {
            String t="";
            for (int i=0;i<(n.length()+1)/2;i++)
                t+="4";
            for (int i=0;i<(n.length()+1)/2;i++)
                t+="7";
            out.print(t);
        }
        else
        {
            int sev=0;
            int fr=0;
            boolean tt=true;
            int k=0;
            while(tt)
            {   
                
                char te=n.charAt(k);
                if (te=='4')
                    {
                        fr++;
                        if (fr>n.length()/2)
                            break;
                        k++;
                        
                    }
                else
                if (te=='7')
                    {
                        sev++;
                        if (sev>n.length()/2)
                            break;
                        k++;
            
                    }
                else
                    tt=false;
                if (k==n.length())
                {
                    out.print(n);
                    break;
                }
                
            }
            
            if (k!=n.length())
            {
            char tr=n.charAt(k);
            
            if (sev>n.length()/2)
            {
                if (fr==0)
                {
                    String t="";
                    for (int i=0;i<(n.length()+2)/2;i++)
                        t+="4";
                    for (int i=0;i<(n.length()+2)/2;i++)
                        t+="7";
                    out.print(t);
                }
                else
                {
                    String t="";
                    while (tr!='4')
                    {
                        k--;
                        tr=n.charAt(k);
                    }
                    
                    for (int i=0;i<k;i++)
                        t+=n.charAt(i);
                    t+='7';
                    fr--;
                    for (int i=0;i<(n.length()/2-fr);i++)
                        t+='4';
                    int ts=t.length();
                    for (int i=0;i<(n.length()-ts);i++)
                        t+='7';
                    out.print(t);
                }
            }
            else
            if (fr>n.length()/2)
            {
                String t="";
                    for (int i=0;i<k;i++)
                        t+=n.charAt(i);
                    int ts=t.length();
                    for (int i=0;i<(n.length()-ts);i++)
                        t+='7';
                    out.print(t);
                }
            else
            {
            
                if (sev==n.length()/2)
                {
                    if (tr>'4')
                    {
                        String t="";
                        for (int i=0;i<(n.length()+2)/2;i++)
                            t+="4";
                        for (int i=0;i<(n.length()+2)/2;i++)
                            t+="7";
                        out.print(t);
                    }
                    else{
                        String t="";
                        for (int i=0;i<k;i++)
                            t+=n.charAt(i);
                    int ts=t.length();
                    for (int i=0;i<(n.length()-ts);i++)
                        t+='4';
                    out.print(t);
                    }
                }
                else
                    if (fr==n.length()/2)
                    {
                        if (tr>'7')
                        {
                            if (fr==0)
                            {
                                String t="";
                                for (int i=0;i<(n.length()+2)/2;i++)
                                    t+="4";
                                for (int i=0;i<(n.length()+2)/2;i++)
                                    t+="7";
                                out.print(t);
                            }
                            else
                            {
                            String t="";
                            
                            while (tr!='4')
                            {
                                k--;
                                tr=n.charAt(k);
                            }
                            
                            for (int i=0;i<k;i++)
                                t+=n.charAt(i);
                            t+='7';
                            fr--;
                            for (int i=0;i<(n.length()/2-fr);i++)
                                t+='4';
                            int ts=t.length();
                            for (int i=0;i<(n.length()-ts);i++)
                                t+='7';
                            out.print(t);
                            }
                        }
                        else
                        {
                            String t="";
                            for (int i=0;i<k;i++)
                                t+=n.charAt(i);
                        int ts=t.length();
                        for (int i=0;i<(n.length()-ts);i++)
                            t+='7';
                        out.print(t);
                        }
                    }
                    else
                    {
                        String t="";
                        boolean ket=true;
                if (tr>'4')
                    {if (tr>'7'){
                        if (fr==0)
                        {
                        
                            for (int i=0;i<(n.length()+2)/2;i++)
                                t+="4";
                            for (int i=0;i<(n.length()+2)/2;i++)
                                t+="7";
                            out.print(t);
                            ket=false;
                        }
                        else
                        {
                    while (tr!='4')
                    {
                        k--;
                        tr=n.charAt(k);
                    }
                    
                    for (int i=0;i<k;i++)
                        t+=n.charAt(i);
                    t+='7';
                    fr--;
                    for (int i=0;i<(n.length()/2-fr);i++)
                        t+='4';
                    int ts=t.length();
                    for (int i=0;i<(n.length()-ts);i++)
                        t+='7';
                    out.print(t);ket=false;}}else{
                    for (int i=0;i<k;i++)
                        t+=n.charAt(i); t+='7';sev++;}}
                else
                    {
                    for (int i=0;i<k;i++)
                        t+=n.charAt(i);
                    fr++;t+='4';}
                if (ket){
                    
                for (int i=0;i<(n.length()/2-fr);i++)
                    t+='4';
                int ts=t.length();
                for (int i=0;i<(n.length()-ts);i++)
                    t+='7';
                out.print(t);
                    }
                    }
            }
            }
            
        }
        
        
        out.close();
        in.close();
    }

}