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.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.util.StringTokenizer;

public class CF {

	static InputReader in = new InputReader(System.in);

	public static void main(String[] args) throws IOException, ParseException {

		String s = in.next();

		int length = s.length() % 2 == 0 ? s.length() : s.length() + 1;

		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < length / 2; i++)
			sb.append("44");

		while (true) {

			if (verif(sb.toString())
					&& Long.parseLong(sb.toString()) >= Long.parseLong(s)) {
				System.out.println(sb);
				break;
			}

			if (sb.charAt(sb.length() - 1) == '4')
				sb.setCharAt(sb.length() - 1, '7');
			else if (allSeven(sb.toString()))
				sb = increase(sb);
			else {
				sb.setCharAt(sb.length() - 1, '4');
				int reminder = 1;

				for (int i = sb.length() - 2; i >= 0 && reminder == 1; i--) {
					if (sb.charAt(i) == '4') {
						sb.setCharAt(i, '7');
						reminder = 0;
					} else
						sb.setCharAt(i, '4');
				}
			}
		}

	}

	private static boolean allSeven(String string) {
		for (int i = 0; i < string.length(); i++)
			if (string.charAt(i) == '4')
				return false;
		return true;
	}

	private static StringBuilder increase(StringBuilder sb) {
		for (int i = 0; i < sb.length(); i++)
			sb.setCharAt(i, '4');

		sb.insert(0, "44");

		return sb;
	}

	private static boolean verif(String string) {

		int fourCount = 0;
		int sevenCount = 0;

		for (int i = 0; i < string.length(); i++)
			if (string.charAt(i) == '4')
				fourCount++;
			else
				sevenCount++;

		return fourCount == sevenCount;
	}
}

class InputReader {
	private BufferedReader reader;
	private StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

	public String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String readLine() {
		try {
			return reader.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public char nextChar() {
		return next().charAt(0);
	}

}