bool comp(string a, string b) { if (a.size() != b.size()) return a.size() < b.size(); // primarily by length return a < b; //secondarily by alphabetical }