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 random
def allIn(x,y):
	a=list(str(x))
	b=list(str(y))
	c=0
	for i in a:
		if i in b:
			c+=1
	if c==len(a):
		return True
	else:
		return False

def factorial(x):
	if x==1:
		return 1
	else:
		return x*factorial(x-1)


def p(n,r):
	return int(factorial(n)/factorial(n-r))

x=input()

assert 4<=len(list(x))<=10**6
assert not x.startswith('0')

x=int(x)
assert allIn(1689,x)==True

x=list(str(x))
a=[]
while len(a)!=factorial(len(str(x))):
    y=random.shuffle(x)
    y=''.join(x)
    if y not in a:
        a.append(y)

for i in range(len(a)):
    a[i]=int(a[i])
    if a[i]%7!=0:
        del a[i]

if len(a)==0:
    print(0)

else:
    print(random.choice(a))



  
    
                        

