You have number *a*, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.

Number *a* doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resulting number also mustn't contain any leading zeroes.
The first line contains positive integer *a* in the decimal record. It is guaranteed that the record of number *a* contains digits: 1, 6, 8, 9. Number *a* doesn't contain any leading zeroes. The decimal representation of number *a* contains at least 4 and at most 10<sup class="upper-index">6</sup> characters.
import sys
import math
from collections import defaultdict
from itertools import permutations

def sin():
	return int(sys.stdin.readline())

def array():
	return list(map(int, sys.stdin.readline().strip().split()))

def two():
	return map(int, sys.stdin.readline().strip().split())

def multiple():
	return [int(x) for x in sys.stdin.readline().split()]

def string():
	return sys.stdin.readline().strip()

n = string()

arr = [0] * 10

for i in n:
	arr[int(i)] += 1

arr[1] -= 1
arr[6] -= 1
arr[8] -= 1
arr[9] -= 1

temp = [1869 , 6891 , 1896 , 1689 , 1986 , 1968 , 1698]

rem = 0
res = ""

for i in range(1 , 10):
	while arr[i] > 0:
		res += str(i)
		rem = (rem * 10) + i
		rem %= 7
		arr[i] -= 1
		print(res)


res += str(temp[rem])

while arr[0]:
	res += "0"
	arr[0] -= 1


print(res)




