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.*;
import java.math.*;
import java.util.*;
import java.lang.*;

public class Main {
	private static BufferedReader br;
	private static StringTokenizer tk;
	private static int MN=0;
	private static TreeSet<String> map;

	public static void main(String[] args)throws java.lang.Exception{
		br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		tk = new StringTokenizer(s);
		map = new TreeSet<String>();
		long N = Long.parseLong(tk.nextToken());
		int len = s.length();
		
		if(len%2!=0){
			len++;
			int i;
			for(i=0; i<len/2; i++){
				System.out.print("4");
			}
			for(; i<len; i++){
				System.out.print("7");
			}
			System.out.println();
		}else{
			MN = len;
			generatePerm("", 0);
			boolean flag = true;
			for(String ss : map){
				if(Long.parseLong(ss)>=N){
					System.out.println(Long.parseLong(ss));
					flag = false;
					break;
				}
			}
			if(flag){
				len+=2;
				int i;
				for(i=0; i<len/2; i++){
					System.out.print("4");
				}
				for(; i<len; i++){
					System.out.print("7");
				}
				System.out.println();
			}
		}
	}
	
	private static void generatePerm(String cur, int ind){
		if(ind >= MN){
			if(cnt(cur)){
				map.add(cur);
			}
		}else{
			generatePerm(cur+"4", ind+1);
			generatePerm(cur+"7", ind+1);
		}
	}
	
	private static boolean cnt(String cur){
		int a=0;
		int b=0;
		for(int i=0; i<cur.length(); i++){
			if(cur.charAt(i)=='4'){
				a++;
			}else{
				b++;
			}
		}
		return a==b;
	}
}