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

Difficulty: MEDIUM_HARD

Solutions:
n = input()
answer = ''
if len(n) % 2 == 0:
	f = len(n) // 2
	s = len(n) // 2
	for x in n:
		if x == '4':
			if f > 0:
				f -= 1
				answer += '4'
			else:
				s -= 1
				answer += '7'
				break
		elif x == '7' and s > 0:
			s -= 1
			answer += '7'
		else:
			if x in ('5', '6'):
				if s > 0:
					answer += '7'
					s -= 1
				elif f == len(n) // 2:
					f = len(n) // 2 + 1
					s = f
					answer = ''
				elif answer.rindex('4') != 0:
					answer = answer[0:answer.rindex('4')]
					f += 1
					s = len(n) - len(answer) - f
					while s == 0 and f != len(n) // 2:
						answer = answer[0:answer.rindex('4')] if answer.rindex('4') != 0 else ''
						f += 1
						s = len(n) - len(answer) - f
					if s != 0:
						answer += '7'
						s -= 1
					else:
						f = len(n) // 2 + 1
						s = f
						answer = ''
				else:
					f += 1
					s = len(n) // 2 - 1
					answer = '7'
			elif x in ('8', '9', '7'):
				if f == len(n) // 2:
					f = len(n) // 2 + 1
					s = f
					answer = ''
				elif answer.rindex('4') != 0:
					answer = answer[0:answer.rindex('4')]
					f += 1
					s = len(n) - len(answer) - f
					while s == 0 and f != len(n) // 2:
						answer = answer[0:answer.rindex('4')] if answer.rindex('4') != 0 else ''
						f += 1
						s = len(n) - len(answer) - f
					if s != 0:
						answer += '7'
						s -= 1
					else:
						f = len(n) // 2 + 1
						s = f
						answer = ''
				else:
					f += 1
					s = len(n) // 2 - 1
					answer = '7'
			break
	answer += '4' * f + '7' * s
else:
	answer = '4' * ((len(n) + 1) // 2) + '7' * ((len(n) + 1) // 2)
print(answer)


import math
from collections import defaultdict, Counter
R = lambda : map(int, input().split())
org = input()
num = [x for x in org]
n = len(num)
(mi, mx) = ('4' * ((n + 1) // 2) + '7' * ((n + 1) // 2), '7' * ((n + 1) // 2) + '4' * ((n + 1) // 2))
if n % 2:
	print(mi)
	exit(0)
if ''.join(num) > mx:
	print('4' + mi + '7')
	exit(0)
(b, sc, fc) = (-1, 0, 0)
for i in range(n):
	if num[i] != '4' and num[i] != '7':
		b = i
		break
	sc += num[i] == '7'
	fc += num[i] == '4'
	if sc > n // 2 or fc > n // 2:
		b = i
		break
if b == -1:
	if sc != n // 2 or fc != n // 2:
		print('1 ' + str(sc) + ' ' + str(fc))
	else:
		print(org)
elif num[b] < '4':
	res = ''.join(num[:b]) + '4' * (n // 2 - fc) + '7' * (n // 2 - sc)
	if res < ''.join(num) or res.count('4') != res.count('7'):
		print('2 ' + str(sc) + ' ' + str(fc))
	else:
		print(res)
elif num[b] < '7':
	res = ''.join(num[:b]) + '7' + '4' * (n // 2 - fc) + '7' * (n // 2 - sc - 1)
	if res < ''.join(num) or res.count('4') != res.count('7'):
		print('3 ' + str(sc) + ' ' + str(fc))
	else:
		print(res)
else:
	sc -= num[b] == '7'
	while num[b - 1] != '4' or n // 2 - sc <= 0:
		sc -= num[b - 1] == '7'
		fc -= num[b - 1] == '4'
		b -= 1
	b -= 1
	fc -= 1
	res = ''.join(num[:b]) + '7' + '4' * (n // 2 - fc) + '7' * (n // 2 - sc - 1)
	if res < ''.join(num) or res.count('4') != res.count('7'):
		print('4 ' + str(sc) + ' ' + str(fc) + ' ' + str(res.count('4')) + ' ' + str(res.count('7')) + ' ' + str(n))
	else:
		print(res)


n = input()
length = len(n)
if length % 2 == 1:
	result = '4' * ((length + 1) // 2) + '7' * ((length + 1) // 2)
else:
	half = length // 2
	if n > half * '7' + half * '4':
		result = (half + 1) * '4' + (half + 1) * '7'
	elif n < half * '4' + half * '7':
		result = half * '4' + half * '7'
	else:
		four_count = seven_count = half
		for i in range(length):
			digit = n[i]
			if digit < '4':
				result = n[:i] + '4' * four_count + '7' * seven_count
				break
			if digit < '7' and digit != '4':
				if seven_count == 0:
					result = n[:nearest_four] + '7' + '4' * (four_count + 1)
					result += '7' * (length - len(result))
				else:
					result = n[:i] + '7' + '4' * four_count + '7' * (seven_count - 1)
				break
			if digit > '7':
				result = n[:nearest_four] + '7' + '4' * (four_count + 1)
				result += '7' * (length - len(result))
				break
			if digit == '4':
				nearest_four = i
				four_count -= 1
				if four_count < 0:
					result = n[:i] + '7' * seven_count
					break
			if digit == '7':
				seven_count -= 1
				if seven_count < 0:
					result = n[:nearest_four] + '7' + '4' * (four_count + 1)
					result += '7' * (length - len(result))
					break
			if four_count == 0 and seven_count == 0:
				result = n
				break
print(result)


def nextLuckyNumber(digits: str) -> str:
	n = len(digits)
	halfLen = n >> 1
	if n & 1 or digits > f"{'7' * halfLen}{'4' * halfLen}":
		halfLen += 1
		return f"{'4' * halfLen}{'7' * halfLen}"
	result = [0 for i in range(n)]
	remaining = [halfLen, halfLen]
	for i in range(n):
		add4 = False
		if remaining[0]:
			if digits[i] < '4':
				add4 = True
			elif digits[i] == '4':
				lastIdx = i + remaining[1]
				for j in range(i + 1, n):
					d = '7' if j <= lastIdx else '4'
					if digits[j] < d:
						add4 = True
						break
					elif digits[j] > d:
						add4 = False
						break
					elif j == n - 1:
						add4 = True
		if add4:
			result[i] = '4'
			remaining[0] -= 1
		else:
			result[i] = '7'
			remaining[1] -= 1
		if result[i] > digits[i] or remaining[1] == 0:
			for k in range(i + 1, i + 1 + remaining[0]):
				result[k] = '4'
			for k in range(i + 1 + remaining[0], i + 1 + remaining[0] + remaining[1]):
				result[k] = '7'
			break
	return ''.join(result)
print(nextLuckyNumber(input()))


n = input()
k = len(n) / 2
k1 = k
r1 = -1
r2 = -1
s1 = ''
p = False
g = -1
s = ''

def anis():
	if g == -1:
		print('4' * int((len(n) + 2) / 2) + '7' * int((len(n) + 2) / 2))
	else:
		print(s1 + '4' * int(r) + '7' * int(r1))
	exit()
i = -1
if len(n) % 2 != 0:
	anis()
while True:
	i += 1
	if i == len(n):
		break
	if int(n[i]) < 4:
		if k > 0:
			s += '4'
			k -= 1
		else:
			s += '7'
			k1 -= 1
		break
	if int(n[i]) == 4:
		if k > 0:
			if k1 > 0:
				s1 = s + '7'
				r = k
				r1 = k1 - 1
				g = i
			s += '4'
			k -= 1
		else:
			k1 -= 1
			s += '7'
			break
		continue
	if int(n[i]) < 7:
		if k1 > 0:
			k1 -= 1
			s += '7'
			break
		else:
			anis()
		continue
	if int(n[i]) == 7:
		if k1 > 0:
			k1 -= 1
			s += '7'
		else:
			anis()
		continue
	if int(n[i]) > 7:
		anis()
print(s + '4' * int(k) + '7' * int(k1))


x = input()
sz = (len(x) + 1) // 2
if len(x) % 2 == 1:
	print('4' * sz + '7' * sz)
elif int(x) > int('7' * sz + '4' * sz):
	print('4' * (sz + 1) + '7' * (sz + 1))
else:
	ans = ''
	(left_4, left_7) = (sz, sz)
	for i in range(len(x)):
		if int(x) > int(ans + '4' + '7' * left_7 + '4' * (left_4 - 1)) or left_4 == 0:
			ans += '7'
			left_7 -= 1
		else:
			ans += '4'
			left_4 -= 1
	print(ans)


def gen(n):
	return '4' * (n // 2) + '7' * (n // 2)
DS = (4, 7)

def solve(n):
	if len(n) % 2 == 0:
		k = len(n) // 2
		i = 0
		c = [0] * 10
		while i < len(n):
			d = int(n[i])
			if d not in DS or (d in DS and c[d] == k):
				break
			c[d] += 1
			i += 1
		if i == len(n):
			return n
		for d in DS:
			if c[d] < k and int(n[i]) < d:
				c[d] += 1
				return n[:i] + str(d) + '4' * (k - c[4]) + '7' * (k - c[7])
		while True:
			i -= 1
			if i < 0:
				break
			d = int(n[i])
			c[d] -= 1
			if d == 4 and c[7] < k:
				c[7] += 1
				return n[:i] + '7' + '4' * (k - c[4]) + '7' * (k - c[7])
	return gen((len(n) + 2) // 2 * 2)
n = input()
print(solve(n))


b = input()
a = [int(i) for i in b]
l = len(a)
flag = 0
s = 0
f = 0
if l % 2 == 1:
	flag = 1
else:
	for i in range(l):
		if a[i] > 7:
			flag = 1
			if s == l // 2 or s == i + 1:
				break
			for j in range(i, -1, -1):
				if a[j] == 4:
					a[j] = 7
					f -= 1
					s += 1
					flag = 0
					i = j
					break
			break
		elif a[i] == 7:
			s += 1
		elif a[i] > 4:
			a[i] = 7
			s += 1
			if s <= l // 2:
				break
		elif a[i] == 4:
			f += 1
		else:
			a[i] = 4
			f += 1
			if f <= l // 2:
				break
		if s > l // 2:
			flag = 1
			for j in range(i - 1, -1, -1):
				f -= 1
				if a[j] == 7:
					f += 1
					if a[j - 1] == 4:
						a[j - 1] = 7
						f -= 1
						s += 1
						flag = 0
						i = j - 1
						break
					s -= 1
			break
		elif f > l // 2:
			a[i] = 7
			s += 1
			f -= 1
			break
if flag:
	for i in range(l // 2 + 1):
		print(4, end='')
	for i in range(l // 2 + 1):
		print(7, end='')
else:
	for j in range(i + 1):
		print(a[j], end='')
	for j in range(i + 1, l):
		if f < l // 2:
			print(4, end='')
			f += 1
		else:
			print(7, end='')


import sys
line = sys.stdin.readline().strip()

def run(i, nFour, nSeven, s, added):
	n = len(line)
	if i == n:
		print(s)
		return True
	v = ord(line[i]) - ord('0')
	if (added or v <= 4) and nFour > 0:
		if run(i + 1, nFour - 1, nSeven, s + '4', added or v < 4):
			return True
	if (added or v <= 7) and nSeven > 0:
		if run(i + 1, nFour, nSeven - 1, s + '7', added or v < 7):
			return True
	return False
while True:
	n = len(line)
	if n % 2 == 1:
		line = '1' + line
		n = n + 1
	v = ord(line[0]) - ord('0')
	if v <= 4:
		if run(1, n / 2 - 1, n / 2, '4', v < 4):
			break
	if v <= 7:
		if run(1, n / 2, n / 2 - 1, '7', v < 7):
			break
	line = '1' + line


from sys import stdin, stdout
from collections import deque
MOD = 10 ** 9 + 7
INF = float('inf')
sze = 10 ** 4 + 1
EPS = 10 ** (-6)
s = stdin.readline().strip()
challenger = []
for i in range(len(s)):
	if s[i] in '47':
		challenger.append(s[i])
	elif s[i] in '89':
		update = []
		for j in range(1, len(challenger) + 1):
			if challenger[-j] == '4':
				update += ['7'] + challenger[:-j][::-1]
				break
			else:
				update.append('4')
		else:
			update.append('4')
		challenger = update[::-1] + ['4' for j in range(len(s[i:]))]
		break
	elif s[i] < '4':
		challenger += ['4' for j in range(len(s[i:]))]
		break
	else:
		challenger += ['7'] + ['4' for j in range(len(s[i:]) - 1)]
		break
while True:
	if challenger.count('4') == challenger.count('7'):
		break
	if len(challenger) % 2:
		challenger = ['4' for i in range((len(challenger) + 1) // 2)] + ['7' for i in range((len(challenger) + 1) // 2)]
	elif challenger.count('4') > challenger.count('7'):
		cnt = challenger.count('4') - challenger.count('7')
		for i in range(len(challenger) - 1, -1, -1):
			if challenger[i] == '4':
				challenger[i] = '7'
				cnt -= 2
			if not cnt:
				break
	else:
		cnt = [0 for i in range(len(challenger))]
		cnt[-1] = challenger[-1] == '7'
		for i in range(2, len(challenger) + 1):
			cnt[-i] = cnt[-i + 1] + (challenger[-i] == '7')
		if not challenger[:len(challenger) // 2].count('4'):
			challenger = ['4' for i in range((len(challenger) + 2) // 2)] + ['7' for i in range((len(challenger) + 2) // 2)]
		else:
			(first, second) = (challenger.count('4'), challenger.count('7'))
			for j in range(len(challenger) - 2, -1, -1):
				if challenger[j] == '4' and cnt[j + 1] * 2 + first >= second:
					challenger[j] = '7'
					for z in range(j + 1, len(challenger)):
						challenger[z] = '4'
					break
stdout.write(''.join(challenger))


def run(n):
	l = len(n)
	if l % 2 == 1:
		result = '4' * (l // 2 + 1) + '7' * (l // 2 + 1)
		print(result)
		return result
	if n > '7' * (l // 2) + '4' * (l // 2):
		result = '4' * (l // 2 + 1) + '7' * (l // 2 + 1)
		print(result)
		return result

	def set_range(p, start, end, num):
		for i in range(start, end):
			p[i] = num
	result = [None] * l
	for i in range(l):
		d = int(n[i])
		if d < 4:
			set_range(result, i, l, '4')
			break
		elif d == 4:
			result[i] = '4'
		elif d < 7:
			result[i] = '7'
			set_range(result, i + 1, l, '4')
			break
		elif d == 7:
			result[i] = '7'
		else:
			k = i - 1
			while result[k] == '7':
				k -= 1
			result[k] = '7'
			set_range(result, k + 1, l, '4')
			break
	diff = (result.count('7') - result.count('4')) // 2
	if diff > 0:
		count = 0
		last_4 = -1
		for k in range(l):
			if result[k] == '7':
				count += 1
			if result[k] == '4':
				last_4 = k
			if count == l // 2:
				result[last_4] = '7'
				u = l // 2 - result[:last_4].count('4')
				set_range(result, last_4 + 1, last_4 + u + 1, '4')
				set_range(result, last_4 + u + 1, l, '7')
				break
	elif diff < 0:
		k = l - 1
		while diff != 0:
			if result[k] == '4':
				result[k] = '7'
				diff += 1
			k -= 1
	s = ''.join(result)
	print(s)
	return s
n = input()
run(n)