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.HashSet;
import java.util.*; 
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.text.DecimalFormat;
import java.lang.Math;
public class Main{
    public static int valid(int n){
        int c4 = 0;
        int c7 = 0;
        while(n>0){
            if(n%10==4){
                c4++;
            }
            else{
                c7++;
            }
            n = n/10;
        }
        return c4==c7?1:0;
    }
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n > 77774444){
		    System.out.println("4444477777");
		}
    	else{
    	    ArrayList<ArrayList<Integer> > A =  new ArrayList<ArrayList<Integer> >(8); 
    		ArrayList<Integer> AA = new ArrayList<Integer>();
    		ArrayList<Integer> temp1 = new ArrayList<Integer>();
    		temp1.add(4);
    		AA.add(4);
    		temp1.add(7);
    		AA.add(7);
    		A.add(temp1);
    		for(int i = 1 ; i <= 8; i++){
    		    ArrayList<Integer> temp = new ArrayList<Integer>();
    	        for(int j = 0; j< A.get(i-1).size(); j++){
    	            temp.add(10*(A.get(i-1).get(j))+4);
    	            temp.add(10*(A.get(i-1).get(j))+7);
    	            AA.add(10*(A.get(i-1).get(j))+4);
    	            AA.add(10*(A.get(i-1).get(j))+7);
    	        }
    	        A.add(temp);
    		}
    		ArrayList<Integer> BB = new ArrayList<Integer>();
    		for(int i = 0; i < AA.size(); i++){
    		    if(valid(AA.get(i))==1){
    		        BB.add(AA.get(i));
    		    }
    		}
    		int flag = 0;
    		int s = 0;
    		int e = BB.size()-1;
    		while(s<=e){
    		    int m = s+(e-s)/2;
    		    if(BB.get(m)==n){
    		        System.out.println(n);
    		        flag = 1;
    		        break;
    		    }
    		    else if(BB.get(m)>n){
    		        e = m-1;
    		    }
    		    else{
    		        s = m+1;
    		    }
    		}
    		if(flag==0){
    		    System.out.println(BB.get(s));
    		}
    	}	
	}
}