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.util.*;





public class B {
	String s = null;


	
	public void run() throws Exception{

		BufferedReader br = null;
		File file = new File("input.txt");
		if(file.exists()){
			br = new BufferedReader(new FileReader("input.txt"));
		}
		else{
			br = new BufferedReader(new InputStreamReader(System.in));
		}
	
		s = br.readLine();
		int keta = s.length();
		if(keta % 2 != 0){
			keta++;
			String ans = mins(keta);
			System.out.println(ans);
			return;
		}
		
		String mins = mins(keta);
		String maxs = maxs(keta);
		if(s.compareTo(mins) < 0){
			System.out.println(mins);
			return;
		}
		if(s.compareTo(maxs) > 0){
			String ans = mins(keta+2);
			System.out.println(ans);
			return;
		}
	
		int n4 = keta/2;
		int n7 = keta/2;
		
		StringBuilder ans = new StringBuilder();
		int breakpos = -1;
		for(int i = 0; i < s.length(); i++){
			if(s.charAt(i) <= '3'){
				ans.append(brk(n4, n7));
				System.out.println(ans);
				return;
			}
			else if(s.charAt(i) == '4'){
				if(n4 > 0){
					ans.append("4");
					n4--;
				}
				else{
					ans.append(brk(n4, n7));
					System.out.println(ans);
					return;
				}
			}
			else if(s.charAt(i) <= '6'){
				if(n7 > 0){
					ans.append("7");
					n7--;
					ans.append(brk(n4, n7));
					System.out.println(ans);
					return;
				}
				else{
					breakpos = i;
					ans.append(brk(n4, n7));
					break;
				}
			}
			else if(s.charAt(i) == '7'){
				if(n7 > 0){
					ans.append("7");
					n7--;
				}
				else{
					breakpos = i;
					ans.append(brk(n4, n7));
					break;
				}
			}
			else{
				breakpos = i;
				ans.append(brk(n4, n7));
				break;
			}
		}
		
		if(breakpos == -1){
			System.out.println(ans);
			return;
		}
		
		
		
		int p4 = -1;
		for(int i = breakpos-1; i >= 0; i--){
			if(ans.charAt(i) == '4'){
				p4 = i;
				break;
			}
		}
		
		int p7 = -1;
		for(int i = p4+1; i < ans.length(); i++){
			if(ans.charAt(i) == '7'){
				p7 = i;
				break;
			}
		}
		if(p7 >= 0){
			String ans1 = ans.substring(0, p4);
			String ans2 = ans.substring(p4);
			
			int nn4 = 0;
			int nn7 = 0;
			for(int i = 0; i< ans2.length(); i++){
				if(ans2.charAt(i) == '4'){
					nn4++;
				}
				else{
					nn7++;
				}
			}
			nn7--;
			String ret = ans1 + "7" + brk(nn4, nn7);
			System.out.println(ret);
			return;
		}
		else{
			int pp4 = -1;
			boolean f7 = false;
			for(int i = p4; i >= 0; i--){
				if(s.charAt(i) == '7'){
					f7 = true;
				}
				else if(f7 && s.charAt(i) == '4'){
					pp4 = i;
					break;
				}
			}
			String ans1 = ans.substring(0, pp4);
			String ans2 = ans.substring(pp4);
			int nn4 = 0;
			int nn7 = 0;
			for(int i = 0; i< ans2.length(); i++){
				if(ans2.charAt(i) == '4'){
					nn4++;
				}
				else{
					nn7++;
				}
			}
			nn7--;
			String ret = ans1 + "7" + brk(nn4, nn7);
			System.out.println(ret);
			return;
		}
	}
	
	String brk(int n4, int n7){
		StringBuilder ans = new StringBuilder();
		for(int i = 0; i < n4; i++){
			ans.append("4");
		}
		for(int i = 0; i < n7; i++){
			ans.append("7");
		}
		return ans.toString();
	}
	
	String mins(int keta){
		StringBuilder ans = new StringBuilder();
		StringBuilder tmp = new StringBuilder();
	
		for(int i = 0; i < keta/2; i++){
			ans.append("4");
			tmp.append("7");
		}
		return ans.toString()+tmp.toString();
	}
	String maxs(int keta){
		StringBuilder ans = new StringBuilder();
		StringBuilder tmp = new StringBuilder();
	
		for(int i = 0; i < keta/2; i++){
			ans.append("4");
			tmp.append("7");
		}
		return tmp.toString() + ans.toString();
	}

	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		B t = new B();
		t.run();

	}

}