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.
def fun(s,i,j):
    if(j-i<=11):
        num=int(s[i:j+1])
        return num%7
    return (fun(s,i,j-12)+(int(s[j-11:j+1]))%7)%7
s=input()
n=len(s)
one=0
six=0
eight=0
nine=0
zero=0
i=0
m=n
while(i<m):
    if(s[i]=='1' and one==0):
        one=1
        s=s[:i]+s[i+1:]
        i-=1
        m-=1
    elif(s[i]=='6' and six==0):
        six=1
        s=s[:i]+s[i+1:]
        i-=1
        m-=1
    elif(s[i]=='8' and eight==0):
        s=s[:i]+s[i+1:]
        eight=1
        i-=1
        m-=1
    elif(s[i]=='9' and nine==0):
        nine=1
        s=s[:i]+s[i+1:]
        i-=1
        m-=1
    elif(s[i]=='0'):
        zero+=1
    i+=1
n-=4
if(n==0):
    print("1869")
elif(zero==n):
    print("1869"+s)
else:
    if(s[0]=='0'):
        i=1
        while(s[i]!='0'):
            i+=1
        s[i],s[0]=s[0],s[i]
    s+='0000'
    n+=4
    rem = fun(s,0,n-1)
    if(rem==0):
        s=s[:n-4]+'1869'
    elif(rem==1):
        s=s[:n-4]+'1896'
    elif(rem==2):
        s=s[:n-4]+'1986'
    elif(rem==3):
        s=s[:n-4]+'1698'
    elif(rem==4):
        s=s[:n-4]+'6198'
    elif(rem==5):
        s=s[:n-4]+'1689'
    elif(rem==6):
        s=s[:n-4]+'1968'
    else:
        s='0'
    print(s)
