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.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class Main {
	private static final String TASKNAME = "b";

	private void solve() throws Exception {
		char[] s = nextToken().toCharArray();
		if (s.length % 2 == 1) {
			int n = (s.length + 1) / 2;
			printA(n);
			return;
		}
		char[] ans = new char[s.length];
		Arrays.fill(ans, '4');
		int seven = ans.length / 2;
		for (int i = 0; i < ans.length; ++i) {
			if (s[i] > '4') {
				if (s[i] > '7') {
					boolean found = false;
					for (int j = i - 1; j >= 0; --j) {
						if (ans[j] == '4') {
							if (seven > 0) {
								ans[j] = '7';
								--seven;
								found = true;
								break;
							}
						} else if (ans[j] == '7') {
							ans[j] = '4';
							++seven;
						}
					}
					if (!found) {
						printA(s.length / 2 + 1);
						return;
					}
					break;
				} else {
					if (seven > 0) {
						--seven;
						ans[i] = '7';
						if (s[i] < '7') {
							break;
						}
					} else {
						boolean found = false;
						for (int j = i - 1; j >= 0; --j) {
							if (ans[j] == '4') {
								if (seven > 0) {
									ans[j] = '7';
									--seven;
									found = true;
									break;
								}
							} else if (ans[j] == '7') {
								ans[j] = '4';
								++seven;
							}
						}
						if (!found) {
							printA(s.length / 2 + 1);
							return;
						}
						break;
					}
				}
			} else if (s[i] < '4') {
				break;
			}
		}
		
		for (int i = ans.length - 1; i >= 0; --i) {
			if (seven > 0 && ans[i] == '4') {
				--seven;
				ans[i] = '7';
			}
		}
		
		println(new String(ans));
	}

	private void printA(int n) {
		for (int i = 0; i < n; ++i) {
			print('4');
		}
		for (int i = 0; i < n; ++i) {
			print('7');
		}
		println("");
	}

	private void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(new OutputStreamWriter(System.out));
//			reader = new BufferedReader(new FileReader(TASKNAME + ".in"));
//			writer = new PrintWriter(new File(TASKNAME + ".out"));

			solve();

			reader.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(13);
		}
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		new Main().run();
		System.err.printf("%.3f\n", (System.currentTimeMillis() - time) * 1e-3);
	}

	private StringTokenizer tokenizer;
	private PrintWriter writer;
	private BufferedReader reader;

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private void print(Object o) {
		writer.print(o);
	}

	private void println(Object o) {
		writer.println(o);
	}

	private void printf(String format, Object... args) {
		writer.printf(format, args);
	}
}