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.Scanner;

public class LuckyNumbers {
	static boolean b = false ;
	public static void main(String [] args){
		
		Scanner in = new Scanner(System.in);
		String s = in.next();
		char [] k = s.toCharArray();
		for(int i = k.length-1 ; i>-1; i--){
			if (k[i]<'4'){
				k[i]='4';
				validate(k, i+1);
			}
			else if(k[i]=='4'){	
			}
			else{
				if (k[i]<'8'){
					k[i]='7';
				}
				else{
					k[i]='4';
					p1(k,i-1);
					
				}
			}
		}
		
		int c4 = 0;
		for(int i = 0 ; i < k.length ; i++ ){
			if(k[i]=='4') c4++;
		}
		if(c4<k.length/2){
			b=true;
		}
		if((int)(k.length/2)*2!=k.length){
			b=true;
		}
		if(b){
			int temp = Integer.parseInt(s);
			boolean check = false;
			if((k[0]<'4'||(k[0]<'5'&& k.length>1 && k[1]<'7'))&&(int)(k.length/2)*2==k.length){
				k[0]='4';
				k[1]='7';
				int i = 2;
				for( ; i <k.length/2+1;i++){
					k[i]='4';
				}
				i++;
				for( ; i < k.length;i++){
					k[i]='7';
				}
				check = true;
				
			}
			else if(k[0]<'7'&&(int)(k.length/2)*2==k.length){
				k[0]='7';
				int i = 1;
				for( ; i <k.length/2+1;i++){
					k[i]='4';
				}
				i++;
				for( ; i < k.length;i++){
					k[i]='7';
				}
				check = true;
				
			}
			s = new String(k);
			int temp2 = Integer.parseInt(s);
			if(check && temp2 > temp && (int)(k.length/2)*2==k.length){
				for (int i = 0 ; i < k.length ; i++){
					System.out.print(k[i]);
				}
			}
			else {
				for(int i = 0 ; i <k.length/2+1;i++){
					System.out.print('4');
				}
				for(int i = 0 ; i < k.length/2+1;i++){
					System.out.print('7');
				}
			}
			
		}
		else{
		
		int half = k.length/2;
		int counter = 0 ;
		if(half * 2== k.length){
			counter = c4-half;
		}
		else{
			counter = c4-half ;
		}
		for(int i = 0 ; i<counter ; i++){
			if(k[k.length-1-i]!='7'){	
			k[k.length-1-i]='7';
			}
			else{
				counter++;
			}
		}
//		if(counter<0){
//			counter*=-1;
//			for(int i = 0 ; i<counter ; i++){
//				if(k[i]!='4'){	
//				k[i]='4';
//				}
//				else{
//					counter++;
//				}
//			}
//		}
		for(int i  = 0 ; i < k.length ; i++){
			System.out.print(k[i]);
		}
		}
	}
	public static void validate(char[] k,int m){
		if(m>0){
		int c = 0;
		for(int i = m;i<k.length;i++){
			if(k[i]=='7'){
				c++;
			}
			k[i]='4';
		}
		for(int i = 0 ; i < c ; i++){
			k[k.length-i-1]='7';
		}
		}
	}
	public static void p1(char [] k , int i ){
		if(i<0){
			b=true;
		}
		else{
			if (k[i]<'9'){
				k[i]++;
				validate(k, i+1);
			}
			else{
				k[i]='4';
				p1(k,i-1);
			}
		}
	}
}