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.*;
import java.util.regex.Pattern;

import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					
					long prevTime = System.currentTimeMillis();
					new Main().run();
					System.err.println("Total time: " + (System.currentTimeMillis() - prevTime) + " ms");
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start(); 
	}

	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}
	
	void solve() throws IOException  {
		String s = nextToken();
		if (bad(s)) {
			printRepeat("4", 1 + s.length() / 2);
			printRepeat("7", 1 + s.length() / 2);
			return;
		}
		out.println(proc(s.toCharArray()));
	}

	char[] proc(char[] s) {
		int hl = s.length / 2;
		int r = 0;
		for (int c4 = 0, c7 = 0; r < s.length; r++) {
			if (s[r] <= '4') c4++; else if (s[r] <= '7') c7++;
			if (s[r] > '7' || c4 > hl || c7 > hl) break;
		}
		for (int i = 0, c4 = 0, c7 = 0; i < min(s.length, r + 1); i++) {
			if (s[i] <= '4') c4++; else if (s[i] <= '7') c7++;
			if (s[i] < '4' || '4' < s[i] && s[i] < '7')
				return up(end(s, i + 1));
		}
		for (int i = 0, c4 = 0, c7 = 0, l4 = -1; i < min(s.length, r + 1); i++) {
			if (s[i] <= '4') c4++; else if (s[i] <= '7') c7++;
			if (s[i] == '4' && c7 < hl) l4 = i;
			if (c7 > hl) {
				s[l4] = '7';
				return up(end(s, l4 + 1));
			}
		}
		if (r == s.length) return up(s);
		int l = r - 1;
		if (s[r] > '7') {
			while (l >= 0 && ++s[l] > '7') l--;
			s[l] = s[l] <= '4' ? '4' : '7';
		} else {
			for (;  l >= 0 && s[l] > '4'; l--);
			s[l] = '7';
		}
		return up(end(s, l + 1));
	}
	
	char[] up(char[] s) {
		for (int i = 0; i < s.length; i++)
			s[i] = s[i] <= '4' ? '4' : '7';
		return s;
	}

	char[] end(char[] s, int k) {
		int hl = s.length / 2, c4 = 0, c7 = 0;
		for (int i = 0; i < k; i++)
			if (s[i] <= '4') c4++; else if (s[i] <= '7') c7++;
		for (int j = hl - c4; j > 0; j--) s[k++] = '4';
		for (int j = hl - c7; j > 0; j--) s[k++] = '7';
		return s;
	}

	void proc(char[] s, int k) {
		for (; k >= 0 && ++s[k] > '7'; k--);
		for (int i = k + 1; i < s.length; i++) s[i] = '0';
	}

	boolean bad(String s) {
		int len = s.length();
		return len % 2 == 1 || matches(s, "^7*[8-9]+[0-9]*") || matches(s, String.format("^[5-7]{%d,%d}[0-4]*[5-9]+[0-9]*", len / 2, len / 2));
	}

	boolean matches(String s, String regexp) {
		return Pattern.compile(regexp).matcher(s).matches();
	}

	/*************************************************************** 
	 * Input 
	 **************************************************************/
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");
	
	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;
	}
	
	/*************************************************************** 
	 * Output 
	 **************************************************************/
	void printRepeat(String s, int count) {
		for (int i = 0; i < count; i++)
			out.print(s);
	}
	
	void printArray(int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}
	
	void printArray(long[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}
	
	void printArray(double[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}
	
	void printArray(double[] array, String spec) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
			out.printf(Locale.US, spec, array[i]);
		}
		out.println();
	}
	
	void printArray(Object[] array) {
		boolean blank = false;
		for (Object x : array) {
			if (blank) out.print(' '); else blank = true;
			out.print(x);
		}
		out.println();
	}
	
	@SuppressWarnings("rawtypes")
	void printCollection(Collection collection) {
		boolean blank = false;
		for (Object x : collection) {
			if (blank) out.print(' '); else blank = true;
			out.print(x);
		}
		out.println();
	}
	
	/*************************************************************** 
	 * Utility
	 **************************************************************/
	void checkMemory() {
		System.err.println((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() >> 20) + "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB");
	}
	
	long prevTimeStamp = Long.MIN_VALUE;
	
	void updateTimer() {
		prevTimeStamp = System.currentTimeMillis();
	}
	
	void checkTimer() {
		System.err.println((System.currentTimeMillis() - prevTimeStamp) + " ms");
	}
}