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.
#include"bits/stdc++.h"
using namespace std;
int main(){
	string s;
	cin>>s;
	vector<int> ct(10);
	for(auto i:s)ct[i-'0']++;

	ct[1]--;ct[6]--;ct[8]--;ct[9]--;

	int rem=0;
	for(int i=1;i<10;i++){
		while(ct[i]>0){
			cout<<i;
			rem*=10;rem+=i;rem%=7;
			ct[i]--;
		}
	}
	rem*=1000;rem%=7;
	string t="1689";
	do{
		int x=stoll(t);
		if((rem+(x%7))%7==0){cout<<x;break;}

	}while(next_permutation(t.begin(),t.end()));

	while(ct[0]>0){cout<<0;ct[0]--;}
	puts("");
}
