prithivMLmods/Coder-Stat huggingface dataset:
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  string s[200000], a[20000];
  int num[200000];

  for (int i = 0; i < n; i++) {
    cin >> s[i];
    num[i] = 0;
  }
  sort(s, s + n);
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      a[j] = s[i];
      num[j] += 1;
    } else if (s[i] == s[i - 1]) {
      num[j] += 1;
    } else {
      j++;
      a[j] = s[i];
      num[j] += 1;
    }
  }
  j++;
  // cout<<j;
  int max = *max_element(num, num + j);

  for (int i = 0; i < j; i++) {
    // cout<<num[i]<<a[i];
    if (num[i] == max) {
      cout << a[i] << endl;
    }
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  string s[200000], a[200000];
  int num[200000];

  for (int i = 0; i < n; i++) {
    cin >> s[i];
    num[i] = 0;
  }
  sort(s, s + n);
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      a[j] = s[i];
      num[j] += 1;
    } else if (s[i] == s[i - 1]) {
      num[j] += 1;
    } else {
      j++;
      a[j] = s[i];
      num[j] += 1;
    }
  }
  j++;
  // cout<<j;
  int max = *max_element(num, num + j);

  for (int i = 0; i < j; i++) {
    // cout<<num[i]<<a[i];
    if (num[i] == max) {
      cout << a[i] << endl;
    }
  }

  return 0;
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
using namespace std;
typedef long long ll;
ll ans;
ll N;
string S[20005];
vector<ll> A;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  sort(S, S + N);
  int cnt = 1;
  int cntm = 0;
  string a = S[0];
  for (int i = 1; i < N; i++) {
    if (S[i] == a) {
      cnt += 1;
    } else {
      if (cnt > cntm) {
        A = {i - 1};
        cntm = cnt;
      } else if (cnt == cntm) {
        A.push_back(i - 1);
      }
      a = S[i];
      cnt = 1;
    }
  }
  if (cnt > cntm) {
    A = {N - 1};
    cntm = cnt;
  } else if (cnt == cntm) {
    A.push_back(N - 1);
  }

  int M = A.size();
  for (int i = 0; i < M; i++) {
    cout << S[A[i]] << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
using namespace std;
typedef long long ll;
ll ans;
ll N;
string S[200005];
vector<ll> A;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  sort(S, S + N);
  int cnt = 1;
  int cntm = 0;
  string a = S[0];
  for (int i = 1; i < N; i++) {
    if (S[i] == a) {
      cnt += 1;
    } else {
      if (cnt > cntm) {
        A = {i - 1};
        cntm = cnt;
      } else if (cnt == cntm) {
        A.push_back(i - 1);
      }
      a = S[i];
      cnt = 1;
    }
  }
  if (cnt > cntm) {
    A = {N - 1};
    cntm = cnt;
  } else if (cnt == cntm) {
    A.push_back(N - 1);
  }

  int M = A.size();
  for (int i = 0; i < M; i++) {
    cout << S[A[i]] << endl;
  }
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
map<string, int> d;
string a[100010];
set<string> q;
int n, j, maxn;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    string x;
    cin >> x;
    if (q.count(x) == 0)
      a[++j] = x;
    q.insert(a[j]);
    d[x]++;
    maxn = max(d[x], maxn);
  }
  sort(a + 1, a + j + 1);
  for (int i = 1; i <= j; i++) {
    if (d[a[i]] == maxn) {
      cout << a[i] << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
map<string, int> d;
string a[1000010];
set<string> q;
int n, j, maxn;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    string x;
    cin >> x;
    if (q.count(x) == 0)
      a[++j] = x;
    q.insert(a[j]);
    d[x]++;
    maxn = max(d[x], maxn);
  }
  sort(a + 1, a + j + 1);
  for (int i = 1; i <= j; i++) {
    if (d[a[i]] == maxn) {
      cout << a[i] << endl;
    }
  }
  return 0;
}
Problem p02773 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

void sort(int n, string *a) {
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] > a[j]) {
        string temp;
        temp = a[j];
        a[j] = a[i];
        a[i] = temp;
      }
    }
  }
  return;
}

int main() {
  int n;
  cin >> n;
  string a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  sort(n, a);
  int counter = 1;
  int temp_counter = 1;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == a[i + 1]) {
      temp_counter++;
      if (i == n - 2 && temp_counter > counter) {
        counter = temp_counter;
      }
    } else {
      if (temp_counter > counter) {
        counter = temp_counter;
      }
      temp_counter = 1;
    }
  }
  temp_counter = 1;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == a[i + 1]) {
      temp_counter++;
    } else {
      temp_counter = 1;
    }
    if (temp_counter == counter) {
      cout << a[i] << endl;
    }
  }
  if (counter == 1) {
    cout << a[n - 1] << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

void sort(int n, string *a) {
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] > a[j]) {
        string temp;
        temp = a[j];
        a[j] = a[i];
        a[i] = temp;
      }
    }
  }
  return;
}

int main() {
  int n;
  cin >> n;
  string a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  std::sort(a, a + n);
  int counter = 1;
  int temp_counter = 1;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == a[i + 1]) {
      temp_counter++;
      if (i == n - 2 && temp_counter > counter) {
        counter = temp_counter;
      }
    } else {
      if (temp_counter > counter) {
        counter = temp_counter;
      }
      temp_counter = 1;
    }
  }
  temp_counter = 1;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == a[i + 1]) {
      temp_counter++;
    } else {
      temp_counter = 1;
    }
    if (temp_counter == counter) {
      cout << a[i] << endl;
    }
  }
  if (counter == 1) {
    cout << a[n - 1] << endl;
  }
  return 0;
}
Problem p02773 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <deque>
#include <iostream>
#include <string>
#include <unordered_map>

int main(void) {
  int n;
  std::cin >> n;

  std::unordered_map<std::string, int> mapCount;
  std::string name;
  int maxNumber = 0;
  for (int count = 0; n > count; ++n) {
    std::cin >> name;
    int &c = mapCount[name];
    c += 1;
    maxNumber = (std::max)(maxNumber, c);
  }

  std::deque<std::string> nameList;
  for (const std::pair<const std::string, int> &nameToCount : mapCount) {
    if (maxNumber != nameToCount.second) {
      continue;
    }
    nameList.emplace_back(nameToCount.first);
  }
  std::sort(nameList.begin(), nameList.end());
  for (const std::string &s : nameList) {
    std::cout << s << std::endl;
  }
}

Fixed submission:
#include <algorithm>
#include <deque>
#include <iostream>
#include <string>
#include <unordered_map>

int main(void) {
  int n;
  std::cin >> n;

  std::unordered_map<std::string, int> mapCount;
  std::string name;
  int maxNumber = 0;
  for (int count = 0; n > count; ++count) {
    std::cin >> name;
    int &c = mapCount[name];
    c += 1;
    maxNumber = (std::max)(maxNumber, c);
  }

  std::deque<std::string> nameList;
  for (const std::pair<const std::string, int> &nameToCount : mapCount) {
    if (maxNumber != nameToCount.second) {
      continue;
    }
    nameList.emplace_back(nameToCount.first);
  }
  std::sort(nameList.begin(), nameList.end());
  for (const std::string &s : nameList) {
    std::cout << s << std::endl;
  }
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
const int maxn = 1e5 + 10;
string ans[maxn];
int let = 0, rigt = 0;
int main() {
  int n, m = 0;
  cin >> n;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (!mp[s])
      mp[s] = 1;
    else
      mp[s]++;
    if (mp[s] > m) {
      m = mp[s];
      ans[rigt] = s;
      let = rigt;
      rigt++;
    } else if (mp[s] == m) {
      ans[rigt] = s;
      rigt++;
    }
    //		cout<<s<<" "<<mp[s]<<endl;
  }
  sort(ans + let, ans + rigt);
  for (int i = let; i < rigt; i++)
    cout << ans[i] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
const int maxn = 2e5 + 10;
string ans[maxn];
int let = 0, rigt = 0;
int main() {
  int n, m = 0;
  cin >> n;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (!mp[s])
      mp[s] = 1;
    else
      mp[s]++;
    if (mp[s] > m) {
      m = mp[s];
      ans[rigt] = s;
      let = rigt;
      rigt++;
    } else if (mp[s] == m) {
      ans[rigt] = s;
      rigt++;
    }
    //		cout<<s<<" "<<mp[s]<<endl;
  }
  sort(ans + let, ans + rigt);
  for (int i = let; i < rigt; i++)
    cout << ans[i] << endl;
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <map>

using namespace std;

int main() {
  int N;
  cin >> N;
  string S[N];
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  std::map<string, int> map;
  for (int i = 0; i < N; i++) {
    auto iter = map.find((S[i]));
    if (iter != map.end()) {
      iter->second = iter->second + 1;
    } else {
      map.insert(make_pair(S[i], 1));
    }
  }

  int max = 0;

  for (auto iter = map.begin(); iter != map.end(); iter++) {
    max = std::max(max, iter->second);
  }

  for (auto iter = map.begin(); iter != map.end(); iter++) {
    if (iter->second == max) {
      cout << iter->first << endl;
    }
  }
  return 1;
}

Fixed submission:
#include <iostream>
#include <map>

using namespace std;

int main() {
  int N;
  cin >> N;
  string S[N];
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  std::map<string, int> map;
  for (int i = 0; i < N; i++) {
    auto iter = map.find((S[i]));
    if (iter != map.end()) {
      iter->second = iter->second + 1;
    } else {
      map.insert(make_pair(S[i], 1));
    }
  }

  int max = 0;

  for (auto iter = map.begin(); iter != map.end(); iter++) {
    max = std::max(max, iter->second);
  }

  for (auto iter = map.begin(); iter != map.end(); iter++) {
    if (iter->second == max) {
      cout << iter->first << endl;
    }
  }
  return 0;
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  int mx = 1, cnt = 1;
  for (int i = 1; i < n; i++) {
    if (s[i].compare(s[i - 1]) == 0) {
      cnt++;
    } else {
      mx = max(cnt, mx);
      cnt = 1;
    }
  }
  mx = max(cnt, mx);
  cnt = 0;
  for (int i = 0; i < n; i++) {
    if (s[i].compare(s[i - 1]) == 0 || i == 0) {
      cnt++;
    } else {
      mx = max(cnt, mx);
      cnt = 1;
    }
    if (cnt == mx) {
      cout << s[i] << "\n";
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  int mx = 1, cnt = 1;
  for (int i = 1; i < n; i++) {
    if (s[i].compare(s[i - 1]) == 0) {
      cnt++;
    } else {
      mx = max(cnt, mx);
      cnt = 1;
    }
  }
  mx = max(cnt, mx);
  cnt = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0 || s[i].compare(s[i - 1]) == 0) {
      cnt++;
    } else {
      mx = max(cnt, mx);
      cnt = 1;
    }
    if (cnt == mx) {
      cout << s[i] << "\n";
    }
  }
  return 0;
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
//

#include <iostream>
#include <list>
#include <map>
using namespace std;

int main(int argc, const char *argv[]) {

  int N = 0;
  int count = 0;
  int resultCount = 0;
  int nameSaveCount = 0;
  string nameSave[1000] = {};
  list<string> list = {};
  string s = "";
  map<string, int> result;

  // 入力
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> s;
    list.push_front(s);
  }
  list.push_front("zzzzzzzzzzzzzzzzz");
  list.sort();
  string monitoringS = list.front();

  // カウント処理
  for (int i = 0; i < N + 1; i++) {
    s = list.front();
    list.pop_front();

    if (monitoringS == s) {
      count++;
    } else {
      nameSave[nameSaveCount] = monitoringS;
      nameSaveCount++;
      result[monitoringS] = count;
      if (resultCount < count) {
        resultCount = count;
      }
      count = 1;
      monitoringS = s;
    }
  }

  // 書かれた回数が多いものを出力する処理。
  for (int i = 0; i < nameSaveCount; i++) {
    if (resultCount == result[nameSave[i]]) {
      cout << nameSave[i] + "\n";
    }
  }

  return 0;
}


Fixed submission:
//

#include <iostream>
#include <list>
#include <map>
using namespace std;

int main(int argc, const char *argv[]) {

  int N = 0;
  int count = 0;
  int resultCount = 0;
  int nameSaveCount = 0;
  string nameSave[200000] = {};
  list<string> list = {};
  string s = "";
  map<string, int> result;

  // 入力
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> s;
    list.push_front(s);
  }
  list.push_front("zzzzzzzzzzzzzzzzz");
  list.sort();
  string monitoringS = list.front();

  // カウント処理
  for (int i = 0; i < N + 1; i++) {
    s = list.front();
    list.pop_front();

    if (monitoringS == s) {
      count++;
    } else {
      nameSave[nameSaveCount] = monitoringS;
      nameSaveCount++;
      result[monitoringS] = count;
      if (resultCount < count) {
        resultCount = count;
      }
      count = 1;
      monitoringS = s;
    }
  }

  // 書かれた回数が多いものを出力する処理。
  for (int i = 0; i < nameSaveCount; i++) {
    if (resultCount == result[nameSave[i]]) {
      cout << nameSave[i] + "\n";
    }
  }

  return 0;
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include "algorithm"
#include "cmath"
#include "cstring"
#include "iostream"
#include "math.h"
#include "queue"
#include "set"
#include "stack"
#include "string"
#include "vector"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> mat;

int main() {
  int n;
  cin >> n;
  string s[2100];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s + n);
  vector<pair<string, int>> p(0);
  int check = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] == s[i - 1]) {
      check++;
    } else {
      p.push_back(make_pair(s[i - 1], check));
      check = 1;
    }
  }
  p.push_back(make_pair(s[n - 1], check));
  int MAX = 0;
  for (pair<string, int> q : p) {
    MAX = max(MAX, q.second);
  }
  for (pair<string, int> q : p) {
    if (q.second == MAX) {
      cout << q.first << "\n";
    }
  }
}

Fixed submission:
#include "algorithm"
#include "cmath"
#include "cstring"
#include "iostream"
#include "math.h"
#include "queue"
#include "set"
#include "stack"
#include "string"
#include "vector"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> mat;

int main() {
  int n;
  cin >> n;
  string s[200100];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s + n);
  vector<pair<string, int>> p(0);
  int check = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] == s[i - 1]) {
      check++;
    } else {
      p.push_back(make_pair(s[i - 1], check));
      check = 1;
    }
  }
  p.push_back(make_pair(s[n - 1], check));
  int MAX = 0;
  for (pair<string, int> q : p) {
    MAX = max(MAX, q.second);
  }
  for (pair<string, int> q : p) {
    if (q.second == MAX) {
      cout << q.first << "\n";
    }
  }
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
#define vector2(a, b, c)                                                       \
  vector<vector<int>> a(b /*縦！w*/, vector<int>(c /*横！w*/))
#define INF 1e10
#define MOD 1e9 + 7
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<int>>;
signed main() {
  int a;
  cin >> a;
  vector<string> b(a), g(a);
  vector<pair<int, string>> c(a);
  rep(i, a) cin >> b[i];
  sort(all(b));
  b.push_back(" ");
  int d = 0;
  int f = 0;
  rep(i, a) {
    d++;
    if (b[i] != b[i + 1]) {
      c[f].second = b[i];
      c[f].first = d;
      f++;
      d = 0;
    }
  }
  sort(all(c));
  reverse(all(c));
  int e = c[0].first;
  int t = 0;
  rep(i, a) {
    if (c[i].first == e)
      g[t] = c[i].second;
    t++;
  }
  sort(all(g));
  rep(i, t + 1) {
    if (g[i] != "")
      cout << g[i] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
#define vector2(a, b, c)                                                       \
  vector<vector<int>> a(b /*縦！w*/, vector<int>(c /*横！w*/))
#define INF 1e10
#define MOD 1e9 + 7
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<int>>;
signed main() {
  int a;
  cin >> a;
  vector<string> b(a), g(a);
  vector<pair<int, string>> c(a);
  rep(i, a) cin >> b[i];
  sort(all(b));
  b.push_back(" ");
  int d = 0;
  int f = 0;
  rep(i, a) {
    d++;
    if (b[i] != b[i + 1]) {
      c[f].second = b[i];
      c[f].first = d;
      f++;
      d = 0;
    }
  }
  sort(all(c));
  reverse(all(c));
  int e = c[0].first;
  int t = 0;
  rep(i, a) {
    if (c[i].first == e)
      g[t] = c[i].second;
    t++;
  }
  sort(all(g));
  rep(i, t) {
    if (g[i] != "")
      cout << g[i] << endl;
  }
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
int main() {
  int n;
  cin >> n;
  string a;
  vector<string> v;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  int co[n];
  co[0] = 0;
  int p = -1;
  rep1(i, n) {
    if (v[i - 1] == v[i]) {
      co[i] = 1 + co[i - 1];
    } else {
      co[i] = 0;
    }
    p = max(co[i], p);
  }

  rep(i, n) {
    if (co[i] == p) {
      cout << string(v[i]) << endl;
    }
  }
  return 0;
}

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

#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
int main() {
  int n;
  cin >> n;
  string a;
  vector<string> v;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  int co[n];
  co[0] = 0;
  int p = -1;
  rep11(i, n) {
    if (v[i - 1] == v[i]) {
      co[i] = 1 + co[i - 1];
    } else {
      co[i] = 0;
    }
    p = max(co[i], p);
  }

  rep(i, n) {
    if (co[i] == p) {
      cout << string(v[i]) << endl;
    }
  }
  return 0;
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

  int N;
  cin >> N;
  map<string, int> m;
  m["fa"] = 0;
  string s;
  rep(i, N) {
    cin >> s;
    m[s]++;
  }
  priority_queue<pair<int, string>> pq;
  pair<int, string> q;
  for (auto p : m) {
    auto k = p.first;
    auto v = p.second;
    q = make_pair(v, k);
    pq.push(q);
  }
  q = pq.top();
  pq.pop();
  int w = pq.top().first;
  stack<string> v;
  v.push(q.second);
  while (q.first == w) {
    v.push(pq.top().second);
    pq.pop();
    w = pq.top().first;
  }
  string g;
  while (v.empty() == 0) {
    cout << v.top() << endl;
    v.pop();
  }
}

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

int main() {
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

  int N;
  cin >> N;
  map<string, int> m;
  m["fahigigiyfghgjhkjghfgdhgj"] = 0;
  string s;
  rep(i, N) {
    cin >> s;
    m[s]++;
  }
  priority_queue<pair<int, string>> pq;
  pair<int, string> q;
  for (auto p : m) {
    auto k = p.first;
    auto v = p.second;
    q = make_pair(v, k);
    pq.push(q);
  }
  q = pq.top();
  pq.pop();
  int w = pq.top().first;
  stack<string> v;
  v.push(q.second);
  while (q.first == w) {
    v.push(pq.top().second);
    pq.pop();
    w = pq.top().first;
  }
  string g;
  while (v.empty() == 0) {
    cout << v.top() << endl;
    v.pop();
  }
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
// #pragma  GCC optimize("Ofast")

// #ifdef  DEBUG
// #define _GLIBCXX_DEBUG
// #endif

// -Ofast
// -O3
// -O2
// -fsanitize=address
// -fsanitize=undefined

// add_compile_options()

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <random>
#include <unordered_map>
using namespace std;
// using namesparsace __gnu_pbds;

mt19937 rnd;

int solve();

int main() {
  srand(time(0));
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif
  solve();
  return 0;
}

int max(int a, int b) { return a > b ? a : b; }

const int maxN = 2e5 + 10;

int n, mx;
map<string, int> ma;
vector<string> a;

int solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    ma[s]++;
    mx = max(mx, ma[s]);
  }
  for (auto it = ma.begin(); it != ma.end(); it++) {
    if (it->second == mx) {
      a.push_back(it->first);
    }
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    cout << a[i] << '\n';
  }
}

Fixed submission:
// #pragma  GCC optimize("Ofast")

// #ifdef  DEBUG
// #define _GLIBCXX_DEBUG
// #endif

// -Ofast
// -O3
// -O2
// -fsanitize=address
// -fsanitize=undefined

// add_compile_options()

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <random>
#include <unordered_map>
using namespace std;
// using namesparsace __gnu_pbds;

mt19937 rnd;

int solve();

int main() {
  srand(time(0));
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif
  solve();
  return 0;
}

int max(int a, int b) { return a > b ? a : b; }

const int maxN = 2e5 + 10;

int n, mx;
map<string, int> ma;
vector<string> a;

int solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    ma[s]++;
    mx = max(mx, ma[s]);
  }
  for (auto it = ma.begin(); it != ma.end(); it++) {
    if (it->second == mx) {
      a.push_back(it->first);
    }
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < a.size(); i++) {
    cout << a[i] << '\n';
  }
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define f(i, x, n) for (i = x; i < n; i++)
#define fr(i, x, n) for (i = x; i >= n; i--)
#define pu push_back
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SP(x) fixed << setprecision(x)
#define IOS()                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

const long long MOD = 1e9 + 7;
const long double PI = acos(-1);
const long long INF = INT_MAX;
const long long LINF = LLONG_MAX;
const long long N = 2e5 + 1;

typedef long long ll;
typedef long double ld;

void test_case() {
  ll n, i, j;
  cin >> n;
  map<string, ll> m;
  f(i, 0, n) {
    string s;
    cin >> s;
    m[s]++;
  }
  vector<string> v;
  ll mx = 0;
  for (auto u : m) {
    mx = max(mx, u.S);
  }
  for (auto u : m) {
    if (u.S == mx)
      v.pu(u.F);
  }
  sort(all(v));
  f(i, 0, n) { cout << v[i] << '\n'; }
}
int main() {
  IOS();

  int tc = 1;
  while (tc--)
    test_case();
  return 0;
}

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

#define f(i, x, n) for (i = x; i < n; i++)
#define fr(i, x, n) for (i = x; i >= n; i--)
#define pu push_back
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SP(x) fixed << setprecision(x)
#define IOS()                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

const long long MOD = 1e9 + 7;
const long double PI = acos(-1);
const long long INF = INT_MAX;
const long long LINF = LLONG_MAX;
const long long N = 2e5 + 1;

typedef long long ll;
typedef long double ld;

void test_case() {
  ll n, i, j;
  cin >> n;
  map<string, ll> m;
  f(i, 0, n) {
    string s;
    cin >> s;
    m[s]++;
  }
  vector<string> v;
  ll mx = 0;
  for (auto u : m) {
    mx = max(mx, u.S);
  }
  for (auto u : m) {
    if (u.S == mx)
      v.pu(u.F);
  }
  sort(all(v));
  f(i, 0, v.size()) { cout << v[i] << '\n'; }
}
int main() {
  IOS();

  int tc = 1;
  while (tc--)
    test_case();
  return 0;
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <string>
#include <utility>
#include <vector>

int main(int argc, char *argv[]) {
  int n;
  std::vector<std::string> s;
  std::vector<std::pair<int, std::string>> scnt;

  std::cin >> n;

  s.resize(n);

  for (int i = 0; i < n; i++) {
    std::cin >> s[i];
  }

  std::sort(s.begin(), s.end());

  std::string scur = "";

  for (int i = 0; i < n; i++) {
    if (s[i] != scur) {
      scur = s[i];
      scnt.push_back(std::pair<int, std::string>(0, scur));
    }
    scnt.back().first++;
  }

  std::sort(scnt.begin(), scnt.end());

  const int maxcnt = scnt.back().first;

  std::vector<std::string> smax;
  // smax.reserve(n);

  for (int i = 0; i < n; i++) {
    if (scnt[i].first == maxcnt) {
      smax.push_back(scnt[i].second);
    }
  }

  std::sort(smax.begin(), smax.end());

  for (int i = 0; i < smax.size(); i++) {
    std::cout << smax[i] << std::endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <string>
#include <utility>
#include <vector>

int main(int argc, char *argv[]) {
  int n;
  std::vector<std::string> s;
  std::vector<std::pair<int, std::string>> scnt;

  std::cin >> n;

  s.resize(n);

  for (int i = 0; i < n; i++) {
    std::cin >> s[i];
  }

  std::sort(s.begin(), s.end());

  std::string scur = "";

  for (int i = 0; i < n; i++) {
    if (s[i] != scur) {
      scur = s[i];
      scnt.push_back(std::pair<int, std::string>(0, scur));
    }
    scnt.back().first++;
  }

  std::sort(scnt.begin(), scnt.end());

  const int maxcnt = scnt.back().first;

  std::vector<std::string> smax;
  // smax.reserve(n);

  for (int i = 0; i < scnt.size(); i++) {
    if (scnt[i].first == maxcnt) {
      smax.push_back(scnt[i].second);
    }
  }

  std::sort(smax.begin(), smax.end());

  for (int i = 0; i < smax.size(); i++) {
    std::cout << smax[i] << std::endl;
  }

  return 0;
}
Problem p02773 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int vector_finder(std::vector<string> vec, string number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int n;
  cin >> n;
  vector<string> a;
  vector<string> b;
  map<string, int> m;
  for (int i = 0; i < n; i++) {
    a.push_back("");
    cin >> a[i];
  }

  int max_size = 0;
  for (int i = 0; i < n; i++) {

    int res = vector_finder(b, a[i]);
    if (res == 0) {
      b.push_back(a[i]);
      m.insert(make_pair(a[i], 1));
    } else {
      m[a[i]] += 1;
    }
    if (m[a[i]] > max_size) {
      max_size = m[a[i]];
    }
  }
  //    cout<<"---"<<endl;
  pair<string, int> item;
  for (map<string, int>::iterator it = m.begin(); it != m.end(); it++) {
    item = *it;
    if (item.second == max_size) {
      cout << item.first << endl;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int vector_finder(std::vector<string> vec, string number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int n;
  cin >> n;
  vector<string> a;
  vector<string> b;
  map<string, int> m;
  for (int i = 0; i < n; i++) {
    a.push_back("");
    cin >> a[i];
  }

  int max_size = 0;
  for (int i = 0; i < n; i++) {

    int res = m.count(a[i]);
    if (res == 0) {
      b.push_back(a[i]);
      m.insert(make_pair(a[i], 1));
    } else {
      m[a[i]] += 1;
    }
    if (m[a[i]] > max_size) {
      max_size = m[a[i]];
    }
  }
  //    cout<<"---"<<endl;
  pair<string, int> item;
  for (map<string, int>::iterator it = m.begin(); it != m.end(); it++) {
    item = *it;
    if (item.second == max_size) {
      cout << item.first << endl;
    }
  }
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d %d", &a, &b)
#define sll(a) scanf("%lld", &a)
#define sll2(a, b) scanf("%lld %lld", &a, &b)
#define mem(a, i) memset(a, i, sizeof(a))

const double pi = acos(-1);
const int mod = 1e9 + 7;
const int maxn = 1e4 + 10;
string ss[maxn], ans[maxn];
map<string, int> mp;
int main() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (!mp[s])
      ss[sum++] = s;
    mp[s]++;
  }
  int m = -1;
  for (int i = 0; i < sum; i++)
    if (m < mp[ss[i]]) {
      m = mp[ss[i]];
    }
  int k = 0;
  for (int i = 0; i < sum; i++)
    if (m == mp[ss[i]])
      ans[k++] = ss[i];
  sort(ans, ans + k);
  for (int i = 0; i < k; i++)
    cout << ans[i] << endl;
  ;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d %d", &a, &b)
#define sll(a) scanf("%lld", &a)
#define sll2(a, b) scanf("%lld %lld", &a, &b)
#define mem(a, i) memset(a, i, sizeof(a))

const double pi = acos(-1);
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
string ss[maxn], ans[maxn];
map<string, int> mp;
int main() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (!mp[s])
      ss[sum++] = s;
    mp[s]++;
  }
  int m = -1;
  for (int i = 0; i < sum; i++)
    if (m < mp[ss[i]]) {
      m = mp[ss[i]];
    }
  int k = 0;
  for (int i = 0; i < sum; i++)
    if (m == mp[ss[i]])
      ans[k++] = ss[i];
  sort(ans, ans + k);
  for (int i = 0; i < k; i++)
    cout << ans[i] << endl;
  ;
  return 0;
}
Problem p02773 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
int main() {
  int n;
  std::cin >> n;
  map<string, int> m;
  int max = 0;
  while (n--) {
    string str;
    cin >> str;
    if (m.find(str) == m.end()) {
      m[str] = 1;
      max = max > m[str] ? max : m[str];
    } else {
      m[str] += 1;
      max = max > m[str] ? max : m[str];
    }
  }
  vector<string> res;

  auto it = m.begin();
  while (it != m.end()) {
    if (it->second == max) {
      res.push_back(it->first);
    }
    ++it;
  }

  for (int i = 0; i < res.size(); i++) {
    for (int j = 0; j < res.size() - 1; j++) {
      if (res.at(j) > res.at(j + 1)) {
        string tmp = res.at(j);
        res.at(j) = res.at(j + 1);
        res.at(j + 1) = tmp;
      }
    }
  }
  auto itt = res.begin();
  while (itt != res.end()) {
    std::cout << *itt << std::endl;
    ++itt;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
int main() {
  int n;
  std::cin >> n;
  map<string, int> m;
  int max = 0;
  while (n--) {
    string str;
    cin >> str;
    if (m.find(str) == m.end()) {
      m[str] = 1;
      max = max > m[str] ? max : m[str];
    } else {
      m[str] += 1;
      max = max > m[str] ? max : m[str];
    }
  }
  vector<string> res;

  auto it = m.begin();
  while (it != m.end()) {
    if (it->second == max) {
      res.push_back(it->first);
    }
    ++it;
  }

  sort(res.begin(), res.end());

  auto itt = res.begin();
  while (itt != res.end()) {
    std::cout << *itt << std::endl;
    ++itt;
  }
  return 0;
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> count(0);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  sort(s.begin(), s.end());

  for (int i = 0; i < n; i++) {
    if (i == 0) {
      count[i] = 1;
    } else if (s[i - 1] == s[i]) {
      count[i] = count[i - 1] + 1;
    } else {
      count[i] = 1;
    }
  }

  int m = 0;
  for (int i = 0; i < n; i++) {
    m = max(m, count[i]);
  }

  for (int i = 0; i < n; i++) {
    if (count[i] == m) {
      cout << s[i] << endl;
    }
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> count(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  sort(s.begin(), s.end());

  for (int i = 0; i < n; i++) {
    if (i == 0) {
      count[i] = 1;
    } else if (s[i - 1] == s[i]) {
      count[i] = count[i - 1] + 1;
    } else {
      count[i] = 1;
    }
  }

  int m = 0;
  for (int i = 0; i < n; i++) {
    m = max(m, count[i]);
  }

  for (int i = 0; i < n; i++) {
    if (count[i] == m) {
      cout << s[i] << endl;
    }
  }
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll n, a;
  in(n);
  vector<string> c(n);
  vector<ll> d(n, 1);
  rep(i, n) in(c[i]);
  sort(all(c));
  rep(i, n - 1) {
    if (c[i - 1] == c[i])
      d[i] = d[i - 1] + 1;
  }
  a = 0;
  rep(i, n) a = max(a, d[i]);
  rep(i, n) {
    if (d[i] == a) {
      out(c[i]);
      memi;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll n, a;
  in(n);
  vector<string> c(n);
  vector<ll> d(n, 1);
  rep(i, n) in(c[i]);
  sort(all(c));
  rep(i, n - 1) {
    if (c[i + 1] == c[i])
      d[i + 1] = d[i] + 1;
  }
  a = 0;
  rep(i, n) a = max(a, d[i]);
  rep(i, n) {
    if (d[i] == a) {
      out(c[i]);
      memi;
    }
  }
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int n, MAX;
string s[100007];
vector<string> v;

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> s[i];
  sort(s + 1, s + n + 1);
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    cnt++;
    if (s[i] != s[i + 1]) {
      MAX = max(MAX, cnt);
      cnt = 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    cnt++;
    if (s[i] != s[i + 1]) {
      if (cnt == MAX)
        v.push_back(s[i]);
      cnt = 0;
    }
  }
  sort(v.begin(), v.end());
  for (auto x : v)
    cout << x << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int n, MAX;
string s[200007];
vector<string> v;

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> s[i];
  sort(s + 1, s + n + 1);
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    cnt++;
    if (s[i] != s[i + 1]) {
      MAX = max(MAX, cnt);
      cnt = 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    cnt++;
    if (s[i] != s[i + 1]) {
      if (cnt == MAX)
        v.push_back(s[i]);
      cnt = 0;
    }
  }
  sort(v.begin(), v.end());
  for (auto x : v)
    cout << x << '\n';
  return 0;
}
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, maxnum = 0, m = 0;
  cin >> n;
  string t;
  vector<string> s(n), ans;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  for (int i = 0; i < n;) {
    t = s[i];
    while (s[i] == t) {
      i++;
      m++;
    }
    if (m == maxnum)
      ans.push_back(t);
    if (m > maxnum) {
      maxnum = m;
      ans.clear();
      ans.shrink_to_fit();
      ans.push_back(t);
    }
    m = 0;
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, maxnum = 0, m = 0;
  cin >> n;
  string t;
  vector<string> s(n), ans;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  for (int i = 0; i < n;) {
    t = s[i];
    while (i < n && s[i] == t) {
      i++;
      m++;
    }
    if (m == maxnum)
      ans.push_back(t);
    if (m > maxnum) {
      maxnum = m;
      ans.clear();
      ans.shrink_to_fit();
      ans.push_back(t);
    }
    m = 0;
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
Problem p02773 (Python)

Buggy submission (status: Time Limit Exceeded):
import collections

N = int(input())
data = [input() for i in range(N)]

dicdata = collections.Counter(data)

newdata = [k for k, v in dicdata.items() if v == max(dicdata.values())]

newdata.sort()

[print(i) for i in newdata]


Fixed submission:
import collections

N = int(input())
data = [input() for i in range(N)]

dicdata = collections.Counter(data)

m = max(dicdata.values())

newdata = [k for k, v in dicdata.items() if v == m]

newdata.sort()

[print(i) for i in newdata]
Problem p02773 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
input_line = [input() for _ in range(N)]
count = {}
for w in input_line:
    if w in count:
        count[w] += 1
    else:
        count[w] = 1

keys = [k for k, v in count.items() if v == max(count.values())]
for w in sorted(keys):
    print(w)


Fixed submission:
N = int(input())
input_line = [input() for _ in range(N)]
count = {}
for w in input_line:
    if w in count:
        count[w] += 1
    else:
        count[w] = 1
max_values = max(count.values())
keys = [k for k, v in count.items() if v == max_values]
for w in sorted(keys):
    print(w)
Problem p02773 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
str_dic = {}
for _ in range(n):
    inp = input()
    if inp in str_dic:
        str_dic[inp] += 1
    else:
        str_dic[inp] = 1

max_str = [s[0] for s in str_dic.items() if s[1] == max(str_dic.values())]

for s in sorted(max_str):
    print(s)


Fixed submission:
n = int(input())
str_dic = {}
for _ in range(n):
    inp = input()
    if inp in str_dic:
        str_dic[inp] += 1
    else:
        str_dic[inp] = 1

max_num = max(str_dic.values())

max_str = [s[0] for s in str_dic.items() if s[1] == max_num]

for s in sorted(max_str):
    print(s)
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

bool my_compare(pair<int, string> a, pair<int, string> b) {
  // 基本はfirstで比較
  if (a.first != b.first) {
    // return a.first < b.first; // 昇順
    return a.first > b.first; // 降順
  }

  // それ以外はsecondで比較
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    // どちらも同じ
    return true;
  }
}
int main() {
  int N, i, num = 0;
  cin >> N;
  vector<string> S(N);
  map<string, int> cnt;
  vector<pair<int, string>> V;

  for (i = 0; i < N; i++)
    cin >> S.at(i);

  sort(S.begin(), S.end());

  for (i = 0; i < N; i++) {
    if (cnt.count(S.at(i)))
      cnt[S.at(i)]++;
    else
      cnt[S.at(i)] = 1;
  }

  for (auto p : cnt) {
    auto k = p.first;
    auto v = p.first;
    V.push_back(make_pair(p.second, p.first));
  }
  sort(V.begin(), V.end(), my_compare);

  for (i = 0; i < N; i++) {
    if (i == 0)
      num = V.at(i).first;
    if (num == V.at(i).first)
      cout << V.at(i).second << endl;
    else
      break;
  }
}

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

bool my_compare(pair<int, string> a, pair<int, string> b) {
  // 基本はfirstで比較
  if (a.first != b.first) {
    // return a.first < b.first; // 昇順
    return a.first > b.first; // 降順
  }

  // それ以外はsecondで比較
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    // どちらも同じ
    return true;
  }
}
int main() {
  int N, i, num = 0;
  cin >> N;
  vector<string> S(N);
  map<string, int> cnt;
  vector<pair<int, string>> V;

  for (i = 0; i < N; i++)
    cin >> S.at(i);

  sort(S.begin(), S.end());

  for (i = 0; i < N; i++) {
    if (cnt.count(S.at(i)))
      cnt[S.at(i)]++;
    else
      cnt[S.at(i)] = 1;
  }

  for (auto p : cnt) {
    auto k = p.first;
    auto v = p.first;
    V.push_back(make_pair(p.second, p.first));
  }
  sort(V.begin(), V.end(), my_compare);

  for (i = 0; i < V.size(); i++) {
    if (i == 0)
      num = V.at(i).first;
    if (num == V.at(i).first)
      cout << V.at(i).second << endl;
    else
      break;
  }
}
Problem p02773 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())

d = {}
for i in range(n):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
max_d_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]

ans = sorted(max_d_list)

for i in ans:
    print(i)


Fixed submission:
n = int(input())

d = {}
for i in range(n):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
max_d = max(d.values())
max_d_list = [kv[0] for kv in d.items() if kv[1] == max_d]

ans = sorted(max_d_list)

for i in ans:
    print(i)
Problem p02773 (Python)

Buggy submission (status: Runtime Error):
import collections

n = int(input())
s_ = [input() for i in range(n)]

cnt = collections.Counter(s_)
cntList = list(cnt.most_common())
cnt_f = cnt.most_common()[0][1]

resList = []
for i in range(n):
    if cntList[i][1] == cnt_f:
        resList.append(cntList[i][0])
    else:
        break

resList.sort()
for i in resList:
    print(i)


Fixed submission:
import collections

n = int(input())
s_ = [input() for i in range(n)]

cnt = collections.Counter(s_)
cntList = list(cnt.most_common())
cnt_f = cnt.most_common()[0][1]

resList = []
for i in range(len(cntList)):
    if cntList[i][1] == cnt_f:
        resList.append(cntList[i][0])
    else:
        break

resList.sort()
for i in resList:
    print(i)
Problem p02773 (Python)

Buggy submission (status: Runtime Error):
import sys
from collections import Counter

read = sys.stdin.read

N, *S = map(str, read().split())
s = Counter(S)
n = max(s.values())
answer = [i for i, j in s if j == n]
answer.sort()
print("\n".join(answer))


Fixed submission:
import sys
from collections import Counter

read = sys.stdin.read

N, *S = map(str, read().split())
s = Counter(S)
n = max(s.values())
answer = [i for i, j in s.items() if j == n]
answer.sort()
print("\n".join(answer))
Problem p02773 (Python)

Buggy submission (status: Time Limit Exceeded):
from collections import Counter

n = int(input())
S = [input() for i in range(n)]

L = Counter(S)
K = sorted([kv[0] for kv in L.items() if kv[1] == max(L.values())])

for i in range(len(K)):
    print(K[i])


Fixed submission:
from collections import Counter

n = int(input())
S = [input() for i in range(n)]

L = Counter(S)
m = 0
for v in L.values():
    m = max(m, v)
ans = []
for k, v in L.items():
    if v == m:
        ans.append(k)
ans.sort()
print(*ans, sep="\n")
Problem p02773 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define INF 0x3f3f3f3f;

using namespace std;

string s[200005];

bool cmp(string a, string b) { return a <= b; }

int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    cin >> s[i];
  sort(s, s + n, cmp);
  int m = 1, cnt = 1;
  for (i = 1; i < n; i++) {
    if (s[i].compare(s[i - 1]) == 0)
      cnt++;
    else
      cnt = 1;
    m = max(cnt, m);
  }
  cnt = 1;
  if (m == 1)
    cout << s[0] << endl;
  for (i = 1; i < n; i++) {
    if (s[i].compare(s[i - 1]) == 0)
      cnt++;
    else
      cnt = 1;
    if (cnt == m)
      cout << s[i] << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define INF 0x3f3f3f3f;

using namespace std;

string s[200005];

bool cmp(string a, string b) { return a < b; }

int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    cin >> s[i];
  sort(s, s + n, cmp);
  int m = 1, cnt = 1;
  for (i = 1; i < n; i++) {
    if (s[i].compare(s[i - 1]) == 0)
      cnt++;
    else
      cnt = 1;
    m = max(cnt, m);
  }
  cnt = 1;
  if (m == 1)
    cout << s[0] << endl;
  for (i = 1; i < n; i++) {
    if (s[i].compare(s[i - 1]) == 0)
      cnt++;
    else
      cnt = 1;
    if (cnt == m)
      cout << s[i] << endl;
  }
}