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
#input = sys.stdin.readline
for _ in range(1):
    arr={}
    def helper(curr,v):
        if len(str(curr))==4:
            arr[curr%7]=curr
        for i in [1,6,8,9]:
            if i not in v:
                v.add(i)
                helper(curr*10+i,v)
                v.remove(i)
        return 
    helper(0,set())
    #print(arr)
    s=input()
    d={}
    for i in s:
        if int(i) not in d:
            d[int(i)]=1
        else:
            d[int(i)]+=1
    #print(arr)
    d[1]-=1
    d[8]-=1
    d[6]-=1
    d[9]-=1
    rem=0
    curr=0
    ans=''
    for i in d:
        if i!=0:
            for j in range(d[i]):
                curr=rem*10+i
                rem=curr%7
                ans+=str(i)
    for i in arr:
        curr=rem
        now=curr*10000+arr[i]
        if now%7==0:
            ans+=str(arr[i])
            break
    if 0 in d:
        for i in range(d[0]):
            ans+='0'
    print(ans)
    #print(arr)
    #print(int(ans)%7)