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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    static ArrayList<Long> possibilities = new ArrayList<>();

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        String n = fs.next();
        long ans = 0;
        if (n.length() % 2 == 1) {
            //print 444777
            ans = fourfoursevenseven(n.length()+1);

        } else {
            recursione(4, 1, 0, n.length());
            recursione(7, 0, 1, n.length());
            Collections.sort(possibilities);
            for (int i = 0; i<possibilities.size(); i++) {
                if (possibilities.get(i) >= Long.valueOf(n)) {
                    ans = possibilities.get(i);
                    break;
                }
            }
            if (ans == 0) {
                ans = fourfoursevenseven(n.length()+2);
            }

        }
        System.out.println(ans);


    }
    public static long fourfoursevenseven(int len) {
        String anss = "";
        for (int i = 0; i<len/2; i++) {
            anss += "4";
        }
        for (int i = 0; i<len/2; i++) {
            anss+="7";
        }
        return Long.valueOf(anss);
    }
    public static void recursione(long num, long fours, long sevens, long limit) {
        if (fours + sevens == limit) {
            if (fours == sevens) possibilities.add(num);
        } else {
            String temp1 = String.valueOf(num);
            String num1 = temp1 + "4";
            String num2 = temp1 + "7";
            long n1 = Long.valueOf(num1);
            long n2 = Long.valueOf(num2);
            recursione(n1, fours+1, sevens, limit);
            recursione(n2, fours, sevens+1, limit);
        }
    }


    public static void arrayPrinter(ArrayList[] a) {
        for (int i = 0; i<a.length; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println();
    }


    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

}