Problem p02773 (C++)

Buggy submission (status: Runtime Error):
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map<int, int>
#define Vector std::vector<int>

using std::cin;
using std::cout;
using std::endl;

typedef long long ll;
typedef unsigned long long ull;

const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = {0, 1, -1, 0, 1, -1, 1, -1};
const int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
const double PI = acos(-1);

template <class T> inline T readT() {
  T res = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      f = -1;
  for (; isdigit(ch); ch = getchar())
    res = (res << 1) + (res << 3) + ch - '0';
  return res * f;
}
#define read readT<int>

struct Edge {
  int u, v, w;
  bool operator<(const Edge &other) const { return w < other.w; }
} e[N];

std::map<String, int> map;
int end, n;
std::pair<int, String> a[N];

inline bool cmp(const std::pair<int, String> &a,
                const std::pair<int, String> &b) {
  if (a.fi != b.fi)
    return a.fi > b.fi;
  else
    return a.se < b.se;
}

int main() {
  std::ios::sync_with_stdio(false);
  // scanf("%d", &n);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    String tmp;
    cin >> tmp;
    if (!map.count(tmp)) {
      map[tmp] = ++end;
      a[map[tmp]].se = tmp;
      a[map[tmp]].fi = 1;
    } else {
      a[map[tmp]].fi++;
    }
  }
  std::sort(a + 1, a + end + 1, cmp);
  int max = a[1].fi;
  for (int i = 1; i <= end; i++) {
    if (a[i].fi != max)
      break;
    cout << a[i].se << endl;
  }
  return 0;
}

Fixed submission:
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map<int, int>
#define Vector std::vector<int>

using std::cin;
using std::cout;
using std::endl;

typedef long long ll;
typedef unsigned long long ull;

const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = {0, 1, -1, 0, 1, -1, 1, -1};
const int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
const double PI = acos(-1);

template <class T> inline T readT() {
  T res = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      f = -1;
  for (; isdigit(ch); ch = getchar())
    res = (res << 1) + (res << 3) + ch - '0';
  return res * f;
}
#define read readT<int>

struct Edge {
  int u, v, w;
  bool operator<(const Edge &other) const { return w < other.w; }
} e[N];

std::map<String, int> map;
int end, n;
std::pair<int, String> a[N * 2];

inline bool cmp(const std::pair<int, String> &a,
                const std::pair<int, String> &b) {
  if (a.fi != b.fi)
    return a.fi > b.fi;
  else
    return a.se < b.se;
}

int main() {
  std::ios::sync_with_stdio(false);
  // scanf("%d", &n);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    String tmp;
    cin >> tmp;
    if (!map.count(tmp)) {
      map[tmp] = ++end;
      a[map[tmp]].se = tmp;
      a[map[tmp]].fi = 1;
    } else {
      a[map[tmp]].fi++;
    }
  }
  std::sort(a + 1, a + end + 1, cmp);
  int max = a[1].fi;
  for (int i = 1; i <= end; i++) {
    if (a[i].fi != max)
      break;
    cout << a[i].se << endl;
  }
  return 0;
}