Divisible by Seven

题意翻译

# 题目描述 有一个(不含前导$0$)正整数$a$,它包含了$1,6,8,9$四个数字, 你需要将其重新排列,使排列后的数字是$7$的倍数。 a 中可以包含其它数字,但一定包含 1689 这四个数字。 # 输入输出格式 ## 输入格式 一个正整数$a$,有$k$位,其中$k$的范围 在$4$到$10^6$之间。 ## 输出格式 若能成功排列,输出重新排列后的数(不含前导$0$); 否则输出0. Translated by @wangml

题目描述

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^{6} $ characters.

输出格式


Print a number in the decimal notation without leading zeroes — the result of the permutation. If it is impossible to rearrange the digits of the number $ a $ in the required manner, print 0.

输入输出样例

输入样例 #1

1689

输出样例 #1

1869

输入样例 #2

18906

输出样例 #2

18690