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 itertools import permutations
n=input()
z=[x for x in n]

z1=[a for a in permutations(z)]

n_z1=list(set(z1))
num=[]
for i in range (0,len(n_z1)):
    str1=""
    for j in range (0,len(n)):
        str1+=n_z1[i][j]
    num.append(str1)

num_l=[int(q) for q in num]

ans=[]
for k in range (0,len(num_l)):
    if (num_l[k]%7==0):
        ans.append(num_l[k])
    else:
        continue

if (len(ans)==0):
    print (0)
else:
    print (ans[0])
