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.util.InputMismatchException;
import java.math.BigInteger;
import java.io.*;
import java.util.Arrays;

/**
 * Generated by Contest helper plug-in
 * Actual solution is at the bottom
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new StreamInputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		run(in, out);
	}

	public static void run(InputReader in, PrintWriter out) {
		Solver solver = new TaskB();
		solver.solve(1, in, out);
		Exit.exit(in, out);
	}
}

abstract class InputReader {
	private boolean finished = false;

	public abstract int read();

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public void setFinished(boolean finished) {
		this.finished = finished;
	}

	public abstract void close();
}

class StreamInputReader extends InputReader {
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar, numChars;

	public StreamInputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public void close() {
		try {
			stream.close();
		} catch (IOException ignored) {
		}
	}
}

class Exit {
	private Exit() {
	}

	public static void exit(InputReader in, PrintWriter out) {
		in.setFinished(true);
		in.close();
		out.close();
	}
}

interface Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out);
}

class TaskB implements Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out) {
		char[] number = in.readString().toCharArray();
		if (number.length % 2 == 1) {
			char[] temp = new char[number.length + 1];
			System.arraycopy(number, 0, temp, 1, number.length);
			temp[0] = '0';
			number = temp;
		}
		char[] result = new char[number.length];
		Arrays.fill(result, '4');
		for (int i = 0; i < number.length; i++) {
			if (number[i] > '7') {
				i--;
				while (i >= 0) {
					if (result[i] == '7')
						result[i] = '4';
					else {
						result[i] = '7';
						break;
					}
					i--;
				}
				if (i < 0) {
					for (int j = 0; j <= number.length / 2; j++)
						out.print('4');
					for (int j = 0; j <= number.length / 2; j++)
						out.print('7');
					out.println();
					return;
				}
				break;
			} else if (number[i] == '7')
				result[i] = '7';
			else if (number[i] > '4') {
				result[i] = '7';
				break;
			} else if (number[i] < '4')
				break;
		}
		int foursCount = 0;
		int sevenCount = 0;
		for (char digit : result) {
			if (digit == '4')
				foursCount++;
			else
				sevenCount++;
		}
		if (foursCount > sevenCount) {
			int replace = (foursCount - sevenCount) / 2;
			for (int i = result.length - 1; i >= 0 && replace != 0; i--) {
				if (result[i] == '4') {
					result[i] = '7';
					replace--;
				}
			}
		} else if (sevenCount > foursCount) {
			boolean fixed = false;
			for (int i = result.length - 1; i >= 0; i--) {
				if (result[i] == '7') {
					sevenCount--;
					result[i] = '4';
				} else if ((sevenCount + 1) * 2 <= result.length) {
					int sevens = -sevenCount - 1 + result.length / 2;
					result[i] = '7';
					Arrays.fill(result, result.length - sevens, result.length, '7');
					fixed = true;
					break;
				}
			}
			if (!fixed) {
				for (int j = 0; j <= number.length / 2; j++)
					out.print('4');
				for (int j = 0; j <= number.length / 2; j++)
					out.print('7');
				out.println();
				return;
			}
		}
		out.println(result);
	}
}