407957: GYM102948 G Food Rations
Description
Shannon and $$$6$$$ of her friends are planning an *extended* camping trip. They plan on packing rations in order to last them for the entirety of their trip. However, they don't know exactly how long they plan to remain camping so Shannon decides to concatenate a lot of randomly generated digits to make the number $$$s$$$ and pack $$$s$$$ rations.
However, she quickly realizes that $$$s$$$ isn't divisible evenly by $$$7$$$. Her friend group is highly competitive for food and refuse to split rations or allow one person to get more rations than another person. Thus, Shannon needs to pack a number that is perfectly divisible by $$$7$$$ and decides to simply rearrange the digits of $$$s$$$. Luckily, she finds that $$$s$$$ at least one of each of the following digits: 1, 6, 8, and 9. Help Shannon permute the digits of her number $$$s$$$ to figure out the number of rations to pack for the group's trip!
InputThe first and only line will contain the positive number $$$s$$$ which does not have any leading zeros and contains at least one of each of the following digits: 1, 6, 8, and 9. It is also guaranteed that $$$1689 \leq s \leq 10^{10^6}$$$ ($$$s$$$ will have at least $$$4$$$ digits and at most $$$10^{6}$$$ digits).
OutputOutput the result of the permutation aka the number of rations that Shannon should bring so that it will be divisible by $$$7$$$. The number should not contain any leading zeros but it should still use the same number of each digit as $$$s$$$.
If it is not possible to permute the digits to create a number divisible by $$$7$$$, output $$$-1$$$.
ExamplesInput1689Output
1869Input
8589157262Output
2255781689