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 static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new Main().run();
				} catch (Throwable e) {
					e.printStackTrace();
					exit(999);
				}
			}
		}, "1", 1 << 23).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	int stp = 0;
	int stm[] = new int[100000];
	int last7 = 0;
	void show1plus(int n){
		n++;
		for(int i = 0; i < n/2; i++)
			out.print(4);
		for(int i = 0; i < n/2; i++)
			out.print(7);
		out.println();
	}
	void show2plus(int n) throws IOException{
		out.print(44);
		for(int i = 0; i < n/2 - 1; i++)
			out.print(4);
		for(int i = 0; i < n/2 + 1; i++)
			out.print(7);
		out.println();
	}
	void show_chp(int pos, int n, int[] m){
		int k4 = 0;
		for(int i = 0; i < pos; i++)
			if(m[i] <= 4 && k4 < n/2){
				out.print(4);
				k4++;
			}
			else
				out.print(7);
		out.print(7);
		for(int i = pos + 1; i < n; i++)
			if(k4 < n/2){
				out.print(4);
				k4++;
			}
			else
				out.print(7);
				
	}
	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		char s[] = nextToken().toCharArray();
		int n = s.length;
		if((n & 1) != 0){
			show1plus(n);
			in.close();
			out.close();
			return;
		}
		int m[] = new int[n];
		for(int i = 0; i < n; i++)
			m[i] = s[i] - '0';
		int k4 = 0, k7 = 0;
		
		boolean dop = false;
		boolean ex = false;
		
		exx: for(int i = 0; i < n; i++)
			if((m[i] <= 4 || dop)&& k4 < n/2){
				if(m[i] < 4) dop = true;
				m[i] = 4;
				k4++;
				stm[stp++] = i;
			}
			else{
				if(m[i] < 7) dop = true;
				if(k7 >= n/2){
					while(stp > 0 && stm[stp - 1] > last7)
						stp--;
					if(stp == 0){
						show2plus(n);
						ex = true;
						break exx;
					}
					else{
						show_chp(stm[stp - 1], n, m);
						ex = true;
						break exx;
					}
				}
				if(dop || m[i] <= 7){
					m[i] = 7;
					k7++;
					last7 = i;
				}
				else{
					if(stp != 0){
						m[stm[--stp]] = 7;
						m[i] = 4;
						stm[stp++] = i;
						k7++;
						dop = true;
					}
					else{
						show2plus(n);
						ex = true;
						break exx;
					}
				}
			}
		if(!ex){
			for(int i = 0; i < n; i++)
				out.print(m[i]);
			out.println();
		}
		
		
		in.close();
		out.close();
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}