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.
from sys import stdin
from itertools import permutations
from collections import defaultdict
# t = int(input())
for _ in range(1):
    c=[1,6,8,9]
    perm=[0 for i in range(6)]
    d=defaultdict(lambda:0)
    x=list(permutations(c))
    for i in x:
        s=0
        for j in i:
            s=10*s+j
        d[s%7]=str(s)
        if(len(d)==7): break
    s=input()
    d1=defaultdict(lambda:0)
    for i in s:
        d1[int(i)]+=1
    ans=""
    for i in range(1,10):
        if i in c:
            for j in range(d1[i]-1): ans+=str(i)
        else: 
            for j in range(d1[i]): ans+=str(i)
    mod=0
    n=len(ans)
    for i in range(n):
        mod=(10*mod+int(ans[i]))%7
    if(mod==0): ans+=d[0]
    else: ans+=d[7-mod]
    for i in range(d1[0]):
        ans+='0'
    print(ans)