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.*;
import java.math.*;

public class Main
{

	static char digits[];
	static int len;

	public static void main(String[] args)
	{
		// (546 456 160)C (298 116 218 124)B (297 251)A

		Scanner in = new Scanner(System.in);

		String str = in.next();
		digits = str.toCharArray();
		int n4=0,n7=0,v;
		len = digits.length;
		int ind=0,count4=0;
		boolean flag;

		if (len % 2 == 0)
			flag = true;
		else
			flag = false;

		for (int i=0;i < len;i++)
			if ((v = digits[i] - '0') == 4)
				n4++;
			else
			if (v == 7)
			{
				n7++;

				if (flag  && n7 == len / 2)
				{
					ind = i;
					count4 = n4;
					flag = false;
				}

			}
			else
				break;

		if (n4 == n7 && n4 + n7 == len)
		{
			System.out.println(str);
		}
		else
		if (len % 2 == 1)
		{
			int half = len / 2 + 1;

			print(half, 4);
			print(half, 7);

		}
		else
		{
			v = 0;
			if (n7 + n4 != len)
				v = digits[n4 + n7] - '0';

			int half = len / 2;

			if(n7==half && v>4 && count4==0)
			{
				print(half+1,4);
				print(half+1,7);
			}
			else
			if (n7 > half)
			{
				if (count4 == 0)
				{
					print(half + 1, 4);
					print(half + 1, 7);
				}
				else
				{
					StringBuilder sb = new StringBuilder();
					sb.append(str.substring(0, ind + 1));
					int last = sb.lastIndexOf("4");
					sb.setCharAt(last, '7');
					String res = sb.substring(0,last+1);
					
					n4 = count4-1;
					n7 = half;
					n7 -= (ind-last-1);
					
					System.out.print(res);
					print(half - n4, 4);
					print(half - n7, 7);

				}
			}
			else
			if (n4 > half)
			{
				print(half, 4);
				print(half, 7);
			}
			else
			if (v < 4)
			{
				System.out.print(str.substring(0, n4 + n7));
				print(half - n4, 4);
				print(half - n7, 7);
			}
			else
			if (v > 4 && v < 7)
			{
				System.out.print(str.substring(0, n4 + n7));
				System.out.print(7);
				n7++;
				print(half - n4, 4);
				print(half - n7, 7);
			}
			else
			{
				int must = check(n7 + n4);

				if (must + n7 >= half && n4 != 0)
				{

					if (n7 != 0)
					{
						if (str.charAt(n4 + n7 - 1) == '7')
						{
							StringBuilder sub = new StringBuilder();
							sub.append(str.substring(0, n4 + n7));

							int indl7;
							String res="";
							indl7 = sub.lastIndexOf("7");

							for (int i = indl7 - 1;i >= 0;i--)
								if (sub.charAt(i) == '7')
									n7--;
								else
								{

									sub.setCharAt(i, '7');
									sub.setCharAt(i + 1, '4');
									res = sub.substring(0, i + 2);
									break;
								}



							System.out.print(res);

							print(half - n4, 4);
							print(half - n7, 7);
						}
						else
						{
							System.out.print(str.substring(0, n4 + n7 - 1));
							n4--;
							System.out.print(7);
							n7++;
							print(half - n4, 4);
							print(half - n7, 7);

						}
					}
					else
					{
						String res = str.substring(0, n4 - 1);
						n4--;
						System.out.print(res);
						System.out.print(7);
						n7++;
						print(half - n4, 4);
						print(half - n7, 7);

					}
				}
				else
				if (n7 + must >= half)
				{
					print(half + 1, 4);
					print(half + 1, 7);
				}
				else
				{
					System.out.print(str.substring(0, n4 + n7));
					print(n7, must);
					n7 += must;
					print(half - n4, 4);
					print(half - n7, 7);

				}

			}


		}

	}

	public static void print(int freq, int num)
	{

		for (int i =1;i <= freq;i++)
			System.out.print(num);
	}

	public static int check(int ind)
	{
		int count = 0;

		for (int i =ind;i < len;i++)
			if (digits[i] - '0' > 4)
				count++;
			else
				return count;

		return count;
	}


}