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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println(new Main().superNumber(sc.next()));
    }

    public String superNumber(String inputStr){
        if(inputStr.length() % 2 > 0){
            int half = 1 + inputStr.length() / 2;
            return lowest(half, half);
        }
        List<Integer> fourPositions = new ArrayList<>();
        List<Integer> remainingSevens = new ArrayList<>();
        int sevenRemaining = inputStr.length() / 2;
        int fourRemaining = sevenRemaining;
        StringBuilder soFar = new StringBuilder();
        char[] digits = inputStr.toCharArray();
        for (int i = 0; i < digits.length; i++) {
            char digit = digits[i];
            if(digit > '4' && digit <= '7'){
                if(sevenRemaining == 0){
                    return getResult(fourPositions, remainingSevens, soFar, digits.length);
                } else {
                    sevenRemaining--;
                    soFar.append('7');
                    if(digit != '7') {
                        return soFar.toString() + lowest(fourRemaining, sevenRemaining);
                    }
                }
            } else if(digit <= '4'){
                if(fourRemaining == 0){
                    return soFar.toString() + lowest(0, sevenRemaining);
                } else {
                    fourRemaining--;
                    soFar.append('4');
                    if(digit != '4'){
                        return soFar.toString() + lowest(fourRemaining, sevenRemaining);
                    }
                    fourPositions.add(i);
                    remainingSevens.add(sevenRemaining);
                }
            } else {
                return getResult(fourPositions, remainingSevens, soFar, digits.length);
            }
        }
        return soFar.toString();
    }

    private String getResult(List<Integer> fourPositions, List<Integer> remainingSevens,
                             StringBuilder soFar, int totalLength) {
        for (int j = fourPositions.size() - 1; j >= 0; j--) {
            if(remainingSevens.get(j) > 0){
                int sevens = remainingSevens.get(j) - 1;
                int fours = totalLength - fourPositions.get(j) - 1 - sevens;
                return soFar.toString().substring(0, fourPositions.get(j)) + "7" + lowest(fours, sevens);
            }
        }
        // extend the length of number
        int half = 1 + totalLength / 2;
        return lowest(half, half);
    }

    private String lowest(int numFours, int numSevens){
        char[] fours = new char[numFours];
        char[] sevens = new char[numSevens];
        Arrays.fill(fours, '4');
        Arrays.fill(sevens, '7');
        return new String(fours) + new String(sevens);
    }
}