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 math

num = input()
rem = [ 1869, 1968, 1689,6198,1698, 1986,  1896]
one = False
six = False
eig = False
nin = False
sec = ""
if int(num) % 7 == 0:
    print(num)
    exit()
else:
    for i in range(0,len(num)):
        if num[i] == '1' and one is False:
            one = True
        elif num[i] =='9' and nin is False:
            nin = True
        elif num[i] == '8' and eig is False:
            eig = True
        elif num[i] == '6' and six is False:
            six = True
        else :
            sec += num[i]

    res = ''.join(sorted(sec, reverse = True))
    if len(sec) == 0:
        print(1869)
    elif res[0] == '0':
        ans = ''
        ans += '1869'
        for i in range(0,len(res)):
            ans += res[i]
        print(ans)
    else :
        res += '0'
        res += '0'
        res += '0'
        res += '0'
        if int(res) % 7 == 0:
            ans_1 = 0
            ans_1 += int(res)
            ans_1 += rem[0]
            print(ans_1)
        else :
            ans_2 = 0
            ans_2 += int(res)
            ans_2 += rem[6 - int(res) % 7 + 1]
            print(ans_2)
