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 static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import java.util.*;
import java.math.*;
import java.io.*;

public class B implements Runnable
{
    String file = "input";
    
    boolean TEST = false;
    
    void solve() throws IOException
    {
        char[] cs = next().toCharArray();
        n = cs.length;
        if(n % 2 == 1)
        {
            int m = (n + 1) / 2;
            for(int i = 0; i < m; i++) out.print('4');
            for(int i = 0; i < m; i++) out.print('7');
            out.println();
            return;
        }
        as = new char[n];
        if(can(cs, 0, false, as, 0, 0)) out.println(as);
        else
        {
            int m = (n + 2) / 2;
            for(int i = 0; i < m; i++) out.print('4');
            for(int i = 0; i < m; i++) out.print('7');
            out.println();
            return;
        } 
    }
    int n;
    char[] as;
    
    boolean can(char[] cs, int i, boolean larger, char[] as, int four, int seven)
    {
        if(i == n) return true;
        
        if(larger)
        {
            int j;
            for(j = i; four < n / 2; j++, four++) as[j] = '4';
            for( ; j < n; j++) as[j] = '7';
            return true;
        }
        if(cs[i] >= '0' && cs[i] <= '3')
        {
            if(four >= n / 2) 
            {
                for(int j = i; j < n; j++) as[j] = '7';
                return true;
            }
            else
            {
                int j;
                for(j = i; four < n / 2; j++, four++) as[j] = '4';
                for( ; j < n; j++) as[j] = '7';
                return true;                
            }
        }
        else if(cs[i] >= '5' && cs[i] <= '6')
        {
            if(seven < n / 2)
            {
                as[i] = '7';
                return can(cs, i + 1, true, as, four, seven + 1);
            }
            return false;
        }
        else if(cs[i] >= '8' && cs[i] <= '9') return false;
        else if(cs[i] == '4')
        {
            if(four < n / 2)
            {
                as[i] = '4';
                if(can(cs, i + 1, larger, as, four + 1, seven)) return true;
            }
            if(seven < n / 2)
            {
                as[i] = '7';
                return can(cs, i + 1, true, as, four, seven + 1);
            }
            return false;
        }
        else //cs[i] == '7'
        {
            if(seven < n / 2)
            {
                as[i] = '7';
                if(can(cs, i + 1, larger, as, four, seven + 1)) return true;
            }
            return false;
        }
    }
    
    String next() throws IOException
    {
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());
        return st.nextToken();
    }
    
    int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }
    
    long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }
    
    double nextDouble() throws IOException
    {
        return Double.parseDouble(next());
    }
    
    void print(Object... o)
    {
        System.out.println(deepToString(o));
    }
    
    void gcj(Object o)
    {
        String s = String.valueOf(o);
        out.println("Case #" + test + ": " + s);
        System.out.println("Case #" + test + ": " + s);
    }
    
    BufferedReader input;
    PrintWriter out;
    StringTokenizer st;
    int test;
    
    void init() throws IOException
    {
        if(TEST) input = new BufferedReader(new FileReader(file + ".in")); 
        else input = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedOutputStream(System.out));
    }
    
    public static void main(String[] args) throws IOException
    {
        new Thread(null, new B(), "", 1 << 23).start();
    }
    
    public void run()
    {
        try
        {
            init();
            if(TEST) 
            {
                int runs = nextInt();
                for(int i = 0; i < runs; i++) solve();
            }
            else solve();
            out.close();        
        }
        catch(Exception e)
        {
            e.printStackTrace();
            System.exit(1);
        }
    }
}