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 l{
    static class pair implements Comparable<pair>{
        long num,id;
        pair(int a ,int b){
            num=a;
            id=b;
        }

        @Override
        public int compareTo(pair pair) {
            return (int) (pair.id-id);
        }
    }
    static long min=Long.MAX_VALUE;
    static void  bf(int n,long val,int rem){
        if (rem==0){
            if (val>=n){
                long x=val;
                int f=0;
                int se=0;
                while (x>0){
                    if (x%10==4)f++;
                    else se++;
                    x/=10;
                }
                if (se==f)
                min=Math.min(val,min);
            }
            return;
        }
        bf(n,val*10l+7,rem-1);
        bf(n,val*10l+4,rem-1);
    }

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int t =n;
        int rem=0;
        while (t>0){
            rem++;
            t/=10;
        }
        //pw.println(rem);
        bf(n,0,rem);
        bf(n,0,rem+1);
        bf(n,0,rem+2);
        pw.println(min);
        pw.flush();
    }

    static class Scanner
    {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(FileReader r){
            br= new BufferedReader(r);
        }
        public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {return br.readLine();}

        public double nextDouble() throws IOException
        {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if(x.charAt(0) == '-')
            {
                neg = true;
                start++;
            }
            for(int i = start; i < x.length(); i++)
                if(x.charAt(i) == '.')
                {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                }
                else
                {
                    sb.append(x.charAt(i));
                    if(dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg?-1:1);
        }

        public boolean ready() throws IOException {return br.ready();}


    }
}