bool reorderedPowerOf2(int N) {
string str = to_string(N);
bool flag = false;
sort(str.begin(),str.end());
do{
if(str[0]!='0'){
int num = atoi(str.c_str());
int p = log(num)/log(2);
if(pow(2,p)==num)
flag = true;
}
}while(next_permutation(str.begin(), str.end()) && !flag);
return flag;
}
vector<int> advantageCount(vector<int>& A, vector<int>& B) {
sort(A.begin(),A.end());
vector<int> res;
for(int i=0;i<B.size();i++){
auto it = upper_bound(A.begin(), A.end(), B[i]);
if(it!=A.end()){
res.push_back(*it);
A.erase(it);
}
else{
res.push_back(*A.begin());
A.erase(A.begin());
}
}
return res;
}