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.util.*;
import java.math.*;
import static java.lang.Character.isDigit;
import static java.lang.Character.isLowerCase;
import static java.lang.Character.isUpperCase;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Character.isDigit;

public class Main{
    static void debug(Object...os){
        System.err.println(deepToString(os));
    }
    int INF=1<<28;
    void run() {
        System.out.println(run(next()));
    }
    String run(String s){
        int n=s.length();
        int[] is=new int[n+2];
        for(int i=0;i<n;i++)is[n-1-i]=s.charAt(i)-'0';
        int[] need7 = new int[n+3];
        fill(need7,INF);
        need7[0] = 0;
        for(int i=0;i<n+2;i++) {
            if(is[i]>7)need7[i+1]=INF;
            else if(is[i]==7)need7[i+1] = min(INF,need7[i]+1);
            else if(is[i]>4)need7[i+1]=1;
            else if(is[i]==4)need7[i+1] = min(1,need7[i]);
            else need7[i+1] = 0;
        }
        while(n%2!=0 || need7[n]>n/2)n++;
        int i4=n/2,i7=n/2;
        boolean more=false;
        int[] res=new int[n];
        for(int i=n-1;i>=0;i--) {
            if(more) {
                if(i4>0) {
                    res[i] = 4;i4--;
                }else {
                    res[i] = 7;i7--;
                }
            }else {
                if(i4>0 && is[i]<4) {
                    more=true;
                    res[i]=4;i4--;
                }else if(i4>0 && is[i]==4 && need7[i]<=i7) {
                    res[i]=4;i4--;
                }else if(is[i]<7) {
                    res[i]=7;i7--;
                    more=true;
                }else {
                    assert is[i]==7;
                    res[i]=7;i7--;
                }
            }
        }
        StringBuilder b=new StringBuilder();
        for(int i=n-1;i>=0;i--)b.append(res[i]);
        return b.toString();
    }

    int nextInt(){
        try{
            int c=System.in.read();
            if(c==-1) return c;
            while(c!='-'&&(c<'0'||'9'<c)){
                c=System.in.read();
                if(c==-1) return c;
            }
            if(c=='-') return -nextInt();
            int res=0;
            do{
                res*=10;
                res+=c-'0';
                c=System.in.read();
            }while('0'<=c&&c<='9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }
    
    long nextLong(){
        try{
            int c=System.in.read();
            if(c==-1) return -1;
            while(c!='-'&&(c<'0'||'9'<c)){
                c=System.in.read();
                if(c==-1) return -1;
            }
            if(c=='-') return -nextLong();
            long res=0;
            do{
                res*=10;
                res+=c-'0';
                c=System.in.read();
            }while('0'<=c&&c<='9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }
    
    double nextDouble(){
        return Double.parseDouble(next());
    }
    
    String next(){
        try{
            StringBuilder res=new StringBuilder("");
            int c=System.in.read();
            while(Character.isWhitespace(c))
                c=System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }
    
    String nextLine(){
        try{
            StringBuilder res=new StringBuilder("");
            int c=System.in.read();
            while(c=='\r'||c=='\n')
                c=System.in.read();
            do{
                res.append((char)c);
                c=System.in.read();
            }while(c!='\r'&&c!='\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }
    public static void main(String[] args){
        new Main().run();
    }
}