Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

//π M_PI
//deg = rad*180/M_PI

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main() {
    ll n;
    cin >> n;
    string s[n];
    std::vector<string> v;
    rep(i, n) {
        cin >> s[i];
        v.push_back(s[i]);
    }
    Sort(v);

    vector<pair<string, ll> > pairs;
    string temp = v[0];
    ll count = 0;
    rep(i, n) {
        if ( i != 0 ) {
            if ( temp == v[i] ) {
                count++;
            } else {
                pairs.push_back( make_pair(temp, count) );
                count = 1;
                temp = v[i];
            }
        }
    }
    pairs.push_back( make_pair(temp, count) );
    sort(ALL(pairs), compare_by_b);
    reverse(ALL(pairs));
    ll num = pairs[0].second;
    std::vector<string> v2;
    rep(i, n) {
        v2.push_back(pairs[i].first);
        if ( num != pairs[i+1].second ) {
            break;
        }
    }
    Sort(v2);
    rep(i, v2.size()) {
        cout << v2[i] << endl;
    }
    return 0;
}


Compiler output:
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<std::pair<std::__cxx11::basic_string<char>, long long int>*, std::vector<std::pair<std::__cxx11::basic_string<char>, long long int> > >; _Iterator2 = __gnu_cxx::__normal_iterator<std::pair<std::__cxx11::basic_string<char>, long long int>*, std::vector<std::pair<std::__cxx11::basic_string<char>, long long int> > >; _Compare = bool (*)(std::pair<int, int>, std::pair<int, int>)]':
/usr/include/c++/14/bits/stl_algo.h:1777:14:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<__cxx11::basic_string<char>, long long int>*, vector<pair<__cxx11::basic_string<char>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<int, int>, pair<int, int>)>]'
 1777 |           if (__comp(__i, __first))
      |               ~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<__cxx11::basic_string<char>, long long int>*, vector<pair<__cxx11::basic_string<char>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<int, int>, pair<int, int>)>]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<__cxx11::basic_string<char>, long long int>*, vector<pair<__cxx11::basic_string<char>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<int, int>, pair<int, int>)>]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pair<__cxx11::basic_string<char>, long long int>*, vector<pair<__cxx11::basic_string<char>, long long int> > >; _Compare = bool (*)(pair<int, int>, pair<int, int>)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:49:9:   required from here
   49 |     sort(ALL(pairs), compare_by_b);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:158:30: error: could not convert '__it1.__gnu_cxx::__normal_iterator<std::pair<std::__cxx11::basic_string<char>, long long int>*, std::vector<std::pair<std::__cxx11::basic_string<char>, long long int> > >::operator*()' from 'pair<std::__cxx11::basic_string<char>,long long int>' to 'pair<int,int>'
  158 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~
      |                              |
      |                              pair<std::__cxx11::basic_string<char>,long long int>
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = std::pair<std::__cxx11::basic_string<char>, long long int>; _Iterator = __gnu_cxx::__normal_iterator<std::pair<std::__cxx11::basic_string<char>, long long int>*, std::vector<std::pair<std::__cxx11::basic_string<char>, long long int> > >; _Compare = bool (*)(std::pair<int, int>, std::pair<int, int>)]':
/usr/include/c++/14/bits/stl_algo.h:1757:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<__cxx11::basic_string<char>, long long int>*, vector<pair<__cxx11::basic_string<char>, long long int> > >; _Compare = __gnu_cxx::__ops::_Val_comp_iter<bool (*)(pair<int, int>, pair<int, int>)>]'
 1757 |       while (__comp(__val, __next))
      |              ~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1785:36:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<__cxx11::basic_string<char>, long long int>*, vector<pair<__cxx11::basic_string<char>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<int, int>, pair<int, int>)>]'
 1785 |             std::__unguarded_linear_insert(__i,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
 1786 |                                 __gnu_cxx::__ops::__val_comp_iter(__comp));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<__cxx11::basic_string<char>, long long int>*, vector<pair<__cxx11::basic_string<char>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<int, int>, pair<int, int>)>]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<__cxx11::basic_string<char>, long long int>*, vector<pair<__cxx11::basic_string<char>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<int, int>, pair<int, int>)>]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4805:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pair<__cxx11::basic_string<char>, long long int>*, vector<pair<__cxx11::basic_string<char>, long long int> > >; _Compare = bool (*)(pair<int, int>, pair<int, int>)]'
 4805 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:49:9:   required from here
   49 |     sort(ALL(pairs), compare_by_b);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:240:30: error: could not convert '__val' from 'pair<std::__cxx11::basic_string<char>,long long int>' to 'pair<int,int>'
  240 |         { return bool(_M_comp(__val, *__it)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~
      |                              |
      |                              pair<std::__cxx11::basic_string<char>,long long int>
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<std::pair<std::__cxx11::basic_string<char>, long long int>*, std::vector<std::pair<std::__cxx11::basic_string<char>, long long int> > >; _Value = std::pair<std::__cxx11::basic_string<char>, long long int>; _Compare = bool (*)(std::pair<int, int>, std::pair<int, int>)]':
/usr/include/c++/14/bits/stl_heap.h:140:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<__cxx11::basic_string<char>, long long int>*, vector<pair<__cxx11::basic_string<char>, long long int> > >; _Distance = long int; _Tp = pair<__cxx11::basic_string<char>, long long int>; _Compare = __gnu_cxx::__ops::_Iter_comp_val<bool (*)(pair<int, int>, pair<int, int>)>]'
  140 |       while (__holeIndex > __topIndex && __comp(__first + __parent, __value))
      |                                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:247:23:   required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<__cxx11::basic_string<char>, long long int>*, vector<pair<__cxx11::basic_string<char>, long long int> > >; _Distance = long int; _Tp = pair<__cxx11::basic_string<char>, long long int>; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<int, int>, pair<int, int>)>]'
  247 |       std::__push_heap(__first, __holeIndex, __topIndex,
      |       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  248 |                        _GLIBCXX_MOVE(__value), __cmp);
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:356:22:   required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<__cxx11::basic_string<char>, long long int>*, vector<pair<__cxx11::basic_string<char>, long long int> > >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(pair<int, int>, pair<int, int>)>]'
  356 |           std::__adjust_heap(__first, __parent, __len, _GLIBCXX_MOVE(__value),
      |           ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  357 |                              __comp);
      |                              ~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1593:23:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<__cxx11::basic_string<char>, long long int>*, vector<pair<__cxx11::basic_string<char>, long long int> > >; _Compare = _