Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for (int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for (int i = (n - 1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef long double ld;
typedef pair<int, string> PP;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<string, int> m;
  rep(i, n) {
    string s;
    cin >> s;
    m[s]++;
  }
  string ans;
  vector<PP> sm;
  for (auto i : m) {
    sm.emplace_back(i.second, i.first);
  }
  sort(all(sm), [](PP a, PP b) {
    if (a.first != b.first)
      return a.first > b.first;
    else
      a.second < b.second;
  });
  int best = sm[0].first;
  for (auto p : sm) {
    if (best == p.first)
      cout << p.second << "\n";
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for (int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for (int i = (n - 1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef long double ld;
typedef pair<int, string> PP;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<string, int> m;
  rep(i, n) {
    string s;
    cin >> s;
    m[s]++;
  }
  int best = 0;
  for (auto i : m)
    chmax(best, i.second);
  vector<string> ans;
  for (auto i : m)
    if (i.second == best)
      ans.push_back(i.first);
  sort(all(ans));
  for (string i : ans)
    cout << i << "\n";
  return 0;
}