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.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main{
    static class VeryHappy {
        private final long n;
        private int rangNumb;
        private int getRangNumb() {
            int r = 2;
            while (n / (toNum(getMaxHappyNumber(r/2,r/2))) > 0) {
                r += 2;
            }
            return r;
        }
        private List<Integer> getMinHappyNumber(int a, int b){
            List<Integer> number = new ArrayList<>();
            for(int i = 0; i < a+b; i++) {
                if(i < a){
                    number.add(4);
                } else {
                    number.add(7);
                }
            }
            return number;
        }
        private List<Integer> getMaxHappyNumber(int a, int b){
            List<Integer> number = new ArrayList<>();
            for(int i = 0; i < a+b; i++) {
                if(i < a){
                    number.add(7);
                } else {
                    number.add(4);
                }
            }
            return number;
        }
        private long toNum(List<Integer> numb){
            long result = 0;
            for(int i = 0; i < numb.size(); ++i) {
                result = result*10 + numb.get(i);
            }
            return  result;
        }
        private  List<Integer> incr(List<Integer> numb){
            int n4 = 0;
            int n7 = 0;
            for(int i = numb.size() - 1; i > 0; --i) {
                if (numb.get(i) == 7 && numb.get(i - 1) == 4) {
                    numb.set(i, 4);
                    numb.set(i - 1, 7);
                    break;
                } else if (numb.get(i) == 4) {
                    n4++;
                } else if (numb.get(i) == 7) {
                    n7++;
                }
            }
            List<Integer> result = numb.subList(0,numb.size() - n4-n7);
            result.addAll(getMinHappyNumber(n4,n7));
            return  result;
        }

        VeryHappy(long n){
            this.n = n;
        }

        public long get(){
            rangNumb = getRangNumb();
            List<Integer> number = getMinHappyNumber(rangNumb/2, rangNumb/2);

            while (n > toNum(number)) {
                number = incr(number);
            }
            return toNum(number);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        System.out.println(new VeryHappy(n).get());
    }
}