#include <iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int num_max(string,string);
int main()
{
int n;
string str;
cout<<"Enter number of non-negative numbers to be arranged : ";
cin>>n;
cout<<"\nEnter the numbers to be arranged : ";
vector <string> vec;
for(int k=0;k<n;k++)
{
cin>>str;
vec.push_back(str);
}
sort(vec.begin(),vec.end(),num_max);
cout<<"\nTheĀ largest number formed combining entered numbers is ";
for(int I=0;I<vec.size();I++)
cout<<vec[I];
return 0;
}
int num_max(string A,string B)
{
string AB=A.append(B);
string BA=B.append(A);
if(AB.compare(BA)>0)
return 1;
else
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZTxhbGdvcml0aG0+CiNpbmNsdWRlPHZlY3Rvcj4KI2luY2x1ZGU8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgbnVtX21heChzdHJpbmcsc3RyaW5nKTsKaW50IG1haW4oKQp7CmludCBuOwpzdHJpbmcgc3RyOwpjb3V0PDwiRW50ZXIgbnVtYmVyIG9mIG5vbi1uZWdhdGl2ZSBudW1iZXJzIHRvIGJlIGFycmFuZ2VkIDogIjsKY2luPj5uOwpjb3V0PDwiXG5FbnRlciB0aGUgbnVtYmVycyB0byBiZSBhcnJhbmdlZCA6ICI7CnZlY3RvciA8c3RyaW5nPiB2ZWM7CmZvcihpbnQgaz0wO2s8bjtrKyspCnsKY2luPj5zdHI7CnZlYy5wdXNoX2JhY2soc3RyKTsKfQpzb3J0KHZlYy5iZWdpbigpLHZlYy5lbmQoKSxudW1fbWF4KTsKY291dDw8IlxuVGhlwqAgbGFyZ2VzdCBudW1iZXIgZm9ybWVkIGNvbWJpbmluZyBlbnRlcmVkIG51bWJlcnMgaXMgIjsKCmZvcihpbnQgST0wO0k8dmVjLnNpemUoKTtJKyspCmNvdXQ8PHZlY1tJXTsKcmV0dXJuIDA7Cn0KaW50IG51bV9tYXgoc3RyaW5nIEEsc3RyaW5nIEIpCnsKc3RyaW5nIEFCPUEuYXBwZW5kKEIpOwpzdHJpbmcgQkE9Qi5hcHBlbmQoQSk7CmlmKEFCLmNvbXBhcmUoQkEpPjApCnJldHVybiAxOwplbHNlCnJldHVybiAwOwoKfQ==