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

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int ans = 1;

  for (int i = 0; i < N; i++) {
    int cnt = 1;
    int jump = 0;
    for (int j = i + 1; j < N; j++) {
      if (vec.at(i) == vec.at(j)) {
        cnt++;
        jump++;
      } else if (vec.at(i) + 1 == vec.at(j) || vec.at(i) + 2 == vec.at(j)) {
        cnt++;
      } else {
        ans = max(ans, cnt);
        i += jump;
        break;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int ans = 1;

  for (int i = 0; i < N; i++) {
    int cnt = 1;
    int jump = 0;
    for (int j = i + 1; j < N; j++) {
      if (vec.at(i) == vec.at(j)) {
        cnt++;
        jump++;
      } else if (vec.at(i) + 1 == vec.at(j) || vec.at(i) + 2 == vec.at(j)) {
        cnt++;
      } else {
        ans = max(ans, cnt);
        i += jump;
        break;
      }
      if (j == N - 1) {
        ans = max(ans, cnt);
        i += jump;
        break;
      }
    }
  }
  cout << ans << endl;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int c[100000];
  rep(i, 100000) { c[i] = 0; }
  rep(i, n) {
    int a;
    cin >> a;
    c[a]++;
  }

  int ans = 0;
  for (int i = 1; i <= 999998; i++) {
    int t = c[i - 1] + c[i] + c[i + 1];
    ans = max(ans, t);
  }

  cout << ans;

  cout << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int c[100000];
  rep(i, 100000) { c[i] = 0; }
  rep(i, n) {
    int a;
    cin >> a;
    c[a]++;
  }

  int ans = 0;
  for (int i = 1; i <= 99998; i++) {
    int t = c[i - 1] + c[i] + c[i + 1];
    ans = max(ans, t);
  }

  cout << ans;

  cout << endl;
  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main() {
  int n, ans = 0;
  cin >> n;
  map<int, int> mp;
  REP(i, n) {
    int a;
    cin >> a;
    auto itr = mp.find(a - 1);
    if (itr != mp.end())
      ++itr->second;
    else
      mp[a - 1] = 1;
    itr = mp.find(a);
    if (itr != mp.end())
      ++itr->second;
    else
      mp[a] = 1;
    itr = mp.find(a + 1);
    if (itr != mp.end())
      ++itr->second;
    else
      mp[a + 1] = 1;
    ;
    for (auto it = mp.begin(); it != mp.end(); ++it) {
      ans = max(ans, it->second);
    }
  }
  cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main() {
  int n, ans = 0;
  cin >> n;
  map<int, int> mp;
  REP(i, n) {
    int a;
    cin >> a;
    auto itr = mp.find(a - 1);
    if (itr != mp.end())
      ++itr->second;
    else
      mp[a - 1] = 1;
    itr = mp.find(a);
    if (itr != mp.end())
      ++itr->second;
    else
      mp[a] = 1;
    itr = mp.find(a + 1);
    if (itr != mp.end())
      ++itr->second;
    else
      mp[a + 1] = 1;
  }
  for (auto it = mp.begin(); it != mp.end(); ++it) {
    ans = max(ans, it->second);
  }
  cout << ans << "\n";
  return 0;
}
Problem p03611 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> num(100000);
  int m = 0;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    m = max(tmp, m);
    num.at(tmp)++;
    num.at(tmp + 1)++;
    if (tmp != 0)
      num.at(tmp - 1)++;
  }
  int ans = 0;
  rep(i, m + 2) { ans = max(ans, num.at(i)); }
  cout << ans << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> num(100010);
  int m = 0;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    m = max(tmp, m);
    num.at(tmp)++;
    num.at(tmp + 1)++;
    if (tmp != 0)
      num.at(tmp - 1)++;
  }
  int ans = 0;
  rep(i, m + 2) { ans = max(ans, num.at(i)); }
  cout << ans << endl;
  return 0;
}
Problem p03611 (C++)

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

typedef long long ll;

template <typename T> void out(T x) {
  cout << x << endl;
  exit(0);
}
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  map<int, int> mp;
  int n;
  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    mp[x]++;
  }
  int best = 0;
  for (auto p : mp) {
    int cur = p.second + mp[p.first - 1] + mp[p.first + 1];
    best = max(best, cur);
  }
  cout << best;

  return 0;
}


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

typedef long long ll;

template <typename T> void out(T x) {
  cout << x << endl;
  exit(0);
}
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  map<int, int> mp;
  int n;
  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    mp[x]++;
  }
  int best = 0;
  for (auto p : mp) {
    int i = mp.count(p.first - 1) ? mp[p.first - 1] : 0;
    int j = mp.count(p.first + 1) ? mp[p.first + 1] : 0;
    int cur = p.second + i + j;
    best = max(best, cur);
  }
  cout << best;

  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> dp(1e5 + 5);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    dp[a]++;
    a++;
    dp[a]++;
    a -= 2;
    dp[a]++;
  }
  sort(dp.rbegin(), dp.rend());
  cout << dp[0] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> dp(1e5 + 5);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    dp[a]++;
    a++;
    dp[a]++;
    a -= 2;
    if (a >= 0)
      dp[a]++;
  }
  sort(dp.rbegin(), dp.rend());
  cout << dp[0] << endl;
  return 0;
}
Problem p03611 (C++)

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

int main() {
  vector<long> table(100001, 0);
  int n, max = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long a;
    cin >> a;
    table[a]++;
    table[a - 1]++;
    table[a + 1]++;
  }
  for (long i = 0; i < table.size(); i++) {
    if (max < table[i]) {
      max = table[i];
    }
  }
  cout << max << endl;
}


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

int main() {
  vector<long> table(100001, 0);
  int n, max = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long a;
    cin >> a;
    table[a]++;
    if (a != 0)
      table[a - 1]++;
    table[a + 1]++;
  }
  for (long i = 0; i < table.size(); i++) {
    if (max < table[i]) {
      max = table[i];
    }
  }
  cout << max << endl;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;

const ll INF = 1LL << 62;
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;
}
// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];

  vector<int> counter(10000000, 0);

  rep(i, N) {
    counter[a[i] - 1]++;
    counter[a[i]]++;
    counter[a[i] + 1]++;
  }

  int ans = 0;
  rep(i, 10000000) { ans = max(ans, counter[i]); }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;

const ll INF = 1LL << 62;
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;
}
// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];

  vector<int> counter(10000000, 0);

  rep(i, N) {
    if (a[i] - 1 >= 0)
      counter[a[i] - 1]++;
    counter[a[i]]++;
    counter[a[i] + 1]++;
  }

  int ans = 0;
  rep(i, 10000000) { ans = max(ans, counter[i]); }

  cout << ans << endl;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define forx(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;

int main() {
  int n, ans;
  cin >> n;
  vector<int> a(100010);
  rep(i, n) {
    int t;
    cin >> t;
    a[t]++;
    a[t + 1]++;
    a[t - 1]++;
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  cout << a[0] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define forx(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;

int main() {
  int n, ans;
  cin >> n;
  vector<int> a(100010);
  rep(i, n) {
    int t;
    cin >> t;
    t++;
    a[t]++;
    a[t + 1]++;
    a[t - 1]++;
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  cout << a[0] << endl;
  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
// #include <iomanip>
// #include <string>
#include <vector>
// #include <algorithm>
// #include <utility>
// #include <set>
// #include <map>
// #include <queue>
// #include <deque>
// #include <bitset>
// #include <math.h>
using namespace std;
using ll = long long;
// using ld = long double ;
using vll = vector<ll>;
// using vvll = vector<vll> ;
// using vc = vector<char> ;
// using vvc = vector<vc> ;
// using vb = vector<bool> ;
// using vvb = vector<vb> ;
// using pll = pair<ll,ll> ;
// #define all(v) v.begin(),v.end()
// ll mod = 1000000007 ;
// long double pie = acos(-1) ;
// ll INF = 1000000000000 ;

// void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
// void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
// ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
// ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
// ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
// void fix_cout(){cout << fixed << setprecision(20) ;}

int main() {
  vll cnt(1000000, 0);
  ll n;
  cin >> n;
  //	cout << n << endl ;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    cnt.at(a)++;
    cnt.at(a - 1)++;
    cnt.at(a + 1)++;
  }
  ll ans = 0;
  for (int i = 0; i < cnt.size(); i++) {
    if (cnt.at(i) > ans)
      ans = cnt.at(i);
  }
  cout << ans << endl;
}


Fixed submission:
#include <iostream>
// #include <iomanip>
// #include <string>
#include <vector>
// #include <algorithm>
// #include <utility>
// #include <set>
// #include <map>
// #include <queue>
// #include <deque>
// #include <bitset>
// #include <math.h>
using namespace std;
using ll = long long;
// using ld = long double ;
using vll = vector<ll>;
// using vvll = vector<vll> ;
// using vc = vector<char> ;
// using vvc = vector<vc> ;
// using vb = vector<bool> ;
// using vvb = vector<vb> ;
// using pll = pair<ll,ll> ;
// #define all(v) v.begin(),v.end()
// ll mod = 1000000007 ;
// long double pie = acos(-1) ;
// ll INF = 1000000000000 ;

// void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
// void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
// ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
// ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
// ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
// void fix_cout(){cout << fixed << setprecision(20) ;}

int main() {
  vll cnt(1000000, 0);
  ll n;
  cin >> n;
  //	cout << n << endl ;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    cnt.at(a)++;
    if (a != 0)
      cnt.at(a - 1)++;
    cnt.at(a + 1)++;
  }
  ll ans = 0;
  for (int i = 0; i < cnt.size(); i++) {
    if (cnt.at(i) > ans)
      ans = cnt.at(i);
  }
  cout << ans << endl;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 10);
  rep(i, n) {
    int b;
    cin >> b;
    a[b]++;
  }
  int count = 0;
  int max_count = 0;
  _rep(i, 1, a.size()) {
    count = a[i - 1] + a[i] + a[i + 1];
    max_count = max(count, max_count);
  }
  print(max_count);
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(100100);
  rep(i, n) {
    int b;
    cin >> b;
    a[b]++;
  }
  int count = 0;
  int max_count = 0;
  _rep(i, 1, a.size()) {
    count = a[i - 1] + a[i] + a[i + 1];
    max_count = max(count, max_count);
  }
  print(max_count);
}
Problem p03611 (C++)

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

int main() {
  int n;
  cin >> n;

  int i, a;
  vector<int> x(100000);
  for (i = 0; i < n; i++) {
    cin >> a;
    x.at(a - 1)++;
  }

  int ans = 0;
  for (i = 0; i < 99998; i++) {
    ans = max(ans, x.at(i) + x.at(i + 1) + x.at(i + 2));
  }

  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;

  int i, a;
  vector<int> x(100000);
  for (i = 0; i < n; i++) {
    cin >> a;
    x.at(a)++;
  }

  int ans = 0;
  for (i = 0; i < 99998; i++) {
    ans = max(ans, x.at(i) + x.at(i + 1) + x.at(i + 2));
  }

  cout << ans << endl;
}
Problem p03611 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  int start = *min_element(ALL(a));
  int end = *max_element(ALL(a));
  int tmp = count(ALL(a), start);
  vector<int> c(1e5, 0);
  c.at(start) = tmp;
  FORE(X, start + 1, end + 1) {
    c.at(X) += tmp;
    tmp = count(ALL(a), X);
    c.at(X - 1) += tmp;
    c.at(X) += tmp;
  }
  cout << *max_element(ALL(c)) << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  vector<int> c(1e5 + 1, 0);
  for (auto &X : a) {
    if (X - 1 > 0) {
      ++c.at(X - 1);
    }
    ++c.at(X);
    ++c.at(X + 1);
  }
  cout << *max_element(ALL(c)) << endl;
}
Problem p03611 (C++)

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

using namespace std;

int main() {

  int num = 0;
  int max_num = 0;
  int N;
  int A[100000];
  int M[100000] = {};

  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  max_num = *max_element(A, A + N);

  for (int i = 0; i < N; ++i) {
    ++M[A[i]];
  }

  for (int i = 0; i <= max_num; ++i) {
    if (M[i] < 1)
      continue;
    int tmp = 0;
    for (int k = 0; k < N; ++k) {
      int m = A[k] - i;
      if (m >= -1 && m <= 1)
        ++tmp;
    }
    num = max(num, tmp);
  }

  cout << num << endl;
  return 0;
}

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

using namespace std;

int main() {

  int num = 0;
  int max_num = 0;
  int N;
  int A[100000];
  int M[100000] = {};

  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  max_num = *max_element(A, A + N);

  for (int i = 0; i < N; ++i) {
    ++M[A[i]];
  }

  for (int i = 0; i <= max_num; ++i) {
    //        if (M[i] < 1) continue;
    //        int tmp = 0;
    //        for (int k = 0; k < N; ++k) {
    //            int m = A[k] - i;
    //            if (m >= -1 && m <= 1) ++tmp;
    //        }
    int tmp = M[i];
    if (i - 1 >= 0)
      tmp += M[i - 1];
    if (i + 1 <= max_num)
      tmp += M[i + 1];
    num = max(num, tmp);
  }

  cout << num << endl;
  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define ll long long
#define LIM 1000
using namespace std;
int main() {
  vector<int> v;
  vector<int> cash(10003, 0);
  int n;
  cin >> n;
  while (n--) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  int max_cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    max_cnt = max(max_cnt, ++cash[v[i] + 1]);
    max_cnt = max(max_cnt, ++cash[v[i]]);
    max_cnt = max(max_cnt, ++cash[v[i] + 2]);
  }
  cout << max_cnt << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define ll long long
#define LIM 1000
using namespace std;
int main() {
  vector<int> v;
  vector<int> cash(100003, 0);
  int n;
  cin >> n;
  while (n--) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  int max_cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    max_cnt = max(max_cnt, ++cash[v[i] + 1]);
    max_cnt = max(max_cnt, ++cash[v[i]]);
    max_cnt = max(max_cnt, ++cash[v[i] + 2]);
  }
  cout << max_cnt << endl;
  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64 = 9223372036854775807;
using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];

  SORT(a);
  int ans = 0;
  FOR(i, a[0], a[N - 1] + 1) {
    auto x = count(ALL(a), i - 1);
    auto y = count(ALL(a), i);
    auto z = count(ALL(a), i + 1);
    int sum = x + y + z;
    chmax(ans, sum);
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64 = 9223372036854775807;
using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];

  SORT(a);
  int ans = 0;
  FOR(i, a[0], a[N - 1] + 1) {
    auto x = equal_range(ALL(a), i - 1);
    auto y = equal_range(ALL(a), i);
    auto z = equal_range(ALL(a), i + 1);
    int sum = x.second - x.first + y.second - y.first + z.second - z.first;
    chmax(ans, sum);
  }

  cout << ans << endl;
  return 0;
}
Problem p03611 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> cnt(
      10010,
      0); // cnt.at(i)はXとしてa_iを選んだときにいくらかの操作を経た後にXと等しくなる項の数
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    cnt.at(a + 1)++;
    cnt.at(a)++;
    cnt.at(a + 2)++;
  }
  sort(cnt.begin(), cnt.end());
  reverse(cnt.begin(), cnt.end());
  cout << cnt.at(0) << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> cnt(
      100010,
      0); // cnt.at(i)はXとしてa_iを選んだときにいくらかの操作を経た後にXと等しくなる項の数
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    cnt.at(a + 1)++;
    cnt.at(a)++;
    cnt.at(a + 2)++;
  }
  sort(cnt.begin(), cnt.end());
  reverse(cnt.begin(), cnt.end());
  cout << cnt.at(0) << endl;
  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
int main() {
  // Your code
  int s;
  cin >> s;

  map<int, int> MP;

  REP(i, s) {
    int a;
    cin >> a;

    MP[a - 1]++;
    MP[a]++;
    MP[a + 1]++;
  }

  int ans = 0;

  REP(i, MP.size()) { ans = max(ans, MP[i]); }

  cout << ans << endl;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
int main() {
  // Your code
  int s;
  cin >> s;

  map<int, int> MP;

  REP(i, s) {
    int a;
    cin >> a;

    MP[a - 1]++;
    MP[a]++;
    MP[a + 1]++;
  }

  int ans = 0;

  for (auto &x : MP) {

    ans = max(ans, x.second);
  }

  cout << ans << endl;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll int64_t
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = 1; i <= n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007

using namespace std;

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

bool my_compare(pair<string, ll> a, pair<string, ll> b) {

  if (a.first != b.first)
    return a.first < b.first;
  if (a.second != b.second)
    return a.second > b.second;
  else
    return true;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(ALL(a));
  vector<ll> d(a[n - 1] + 10);
  rep(i, a[n - 1] + 10) d[i] = 0;
  rep(i, n) {
    d[a[i] - 1]++;
    d[a[i]]++;
    d[a[i] + 1]++;
  }
  sort(ALL(d));
  cout << d[a[n - 1] + 9] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll int64_t
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = 1; i <= n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007

using namespace std;

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

bool my_compare(pair<string, ll> a, pair<string, ll> b) {

  if (a.first != b.first)
    return a.first < b.first;
  if (a.second != b.second)
    return a.second > b.second;
  else
    return true;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(ALL(a));
  vector<ll> d(a[n - 1] + 10);
  rep(i, a[n - 1] + 10) d[i] = 0;
  rep(i, n) {
    if (a[i] != 0) {
      d[a[i] - 1]++;
      d[a[i]]++;
      d[a[i] + 1]++;
    } else {
      d[a[i]]++;
      d[a[i] + 1]++;
    }
  }
  sort(ALL(d));
  cout << d[a[n - 1] + 9] << endl;
  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  int ans = 0;
  vector<int> cost(N, 0);

  for (int i = 0; i < N; i++) {
    cost[a[i]]++;
    cost[a[i] + 1]++;
    if (a[i] > 0)
      cost[a[i] - 1]++;
  }

  rep(i, 100010) { ans = max(cost[i], ans); }

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  int ans = 0;
  vector<int> cost(100010, 0);

  for (int i = 0; i < N; i++) {
    cost[a[i]]++;
    cost[a[i] + 1]++;
    if (a[i] > 0)
      cost[a[i] - 1]++;
  }

  rep(i, 100010) { ans = max(cost[i], ans); }

  cout << ans << endl;
}
Problem p03611 (C++)

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n), cnt(n + 666);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
  }
  int mx = 0;
  for (int i = 1; i <= 100000; i++) {
    mx = max(mx, cnt[i] + cnt[i - 1] + cnt[i + 1]);
  }
  mx = max(mx, cnt[0] + cnt[1]);
  printf("%d\n", mx);
  return 0;
}

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n), cnt(123456);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
  }
  int mx = 0;
  for (int i = 1; i <= 100000; i++) {
    mx = max(mx, cnt[i] + cnt[i - 1] + cnt[i + 1]);
  }
  mx = max(mx, cnt[0] + cnt[1]);
  printf("%d\n", mx);
  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>

using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> num(100002);
  for (ll i = 0; i < 100002; i++) {
    num[i].second = i;
  }
  vector<ll> a(N);
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
    num[a[i]].first++;
    num[a[i] - 1].first++;
    num[a[i] + 1].first++;
  }
  sort(num.begin(), num.end());
  reverse(num.begin(), num.end());
  cout << num[0].first << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>

using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> num(100002);
  for (ll i = 0; i < 100002; i++) {
    num[i].second = i;
  }
  vector<ll> a(N);
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
    num[a[i]].first++;
    if (a[i] > 0)
      num[a[i] - 1].first++;
    num[a[i] + 1].first++;
  }
  sort(num.begin(), num.end());
  reverse(num.begin(), num.end());
  cout << num[0].first << endl;
  return 0;
}
Problem p03611 (C++)

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

using namespace std;

const long long int MAX_N = 100000;

int main(int argc, char const *argv[]) {
  long long int n, ans = 0;
  cin >> n;
  vector<long long int> a;
  for (size_t i = 0; i < n; i++) {
    long long int temp;
    cin >> temp;
    a.push_back(temp);
  }
  sort(a.begin(), a.end());

  for (size_t i = 0; i < a.size();) {
    vector<long long int>::iterator lb = lower_bound(a.begin(), a.end(), a[i]);
    long long int iter = lb - a.begin();
    long long int cnt = 0;
    cnt += count(a.begin(), a.end(), a[iter]);
    cnt += count(a.begin(), a.end(), a[iter] - 1);
    cnt += count(a.begin(), a.end(), a[iter] + 1);
    if (cnt > ans)
      ans = cnt;
    i = upper_bound(a.begin(), a.end(), a[i]) - a.begin();
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

const long long int MAX_N = 100000;

int main(int argc, char const *argv[]) {
  long long int n, ans = 0;
  cin >> n;
  vector<long long int> a;
  for (size_t i = 0; i < n; i++) {
    long long int temp;
    cin >> temp;
    a.push_back(temp);
  }
  sort(a.begin(), a.end());

  for (size_t i = 0; i < a.size();) {
    vector<long long int>::iterator lb = lower_bound(a.begin(), a.end(), a[i]);
    long long int iter = lb - a.begin();
    long long int cnt = 0;
    vector<long long int>::iterator lbp = lower_bound(a.begin(), a.end(),
                                                      a[i] - 1),
                                    ubn = upper_bound(a.begin(), a.end(),
                                                      a[i] + 1);
    cnt += ubn - lbp;
    if (cnt > ans)
      ans = cnt;
    i = upper_bound(a.begin(), a.end(), a[i]) - a.begin();
  }

  cout << ans << endl;

  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>

using namespace std;

int main() {
  int N;
  scanf("%d", &N);

  int a[N];
  int b[100005] = {0};
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);

    b[a[i] - 1] += 1;
    b[a[i]] += 1;
    b[a[i] + 1] += 1;
  }

  int ans = *max_element(b, b + 100001);

  printf("%d\n", ans);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <stdio.h>

using namespace std;

int main() {
  int N;
  scanf("%d", &N);

  int a[N];
  int b[100005] = {0};
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);

    if (a[i] != 0)
      b[a[i] - 1] += 1;
    b[a[i]] += 1;
    b[a[i] + 1] += 1;
  }

  int ans = *max_element(b, b + 100001);

  printf("%d\n", ans);

  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):

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

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

  vector<int> vec(n);

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

    cin >> vec[i];
  }

  sort(vec.begin(), vec.end());
  int N = vec.back();

  vector<int> ar(N + 10, 0);

  for (int i = 0; i < n; i++) {
    ar[vec[i]]++;
    ar[vec[i] + 1]++;
    ar[vec[i] + 2]++;
  }
  /*for (int i = 0; i < n; i++) {
    cout << vec[i] << ":::" << ar[i] << endl;
  }*/
  int ans = 0;
  for (int i = 1; i < n; i++) {
    ans = max(ans, ar[i]);
  }

  // sort(cou.begin(), cou.begin() + vec[n - 1] + 1, greater<int>());
  if (n != 1) {
    cout << ans << endl;
  } else {
    cout << 1;
  }
  return 0;
}


Fixed submission:

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

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

  vector<int> vec(n);

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

    cin >> vec[i];
  }

  sort(vec.begin(), vec.end());
  int N = vec.back();

  vector<int> ar(100010, 0);

  for (int i = 0; i < n; i++) {
    ar[vec[i]]++;
    ar[vec[i] + 1]++;
    ar[vec[i] + 2]++;
  }
  /*for (int i = 0; i < n; i++) {
    cout << vec[i] << ":::" << ar[i] << endl;
  }*/
  int ans = 0;
  for (int i = 1; i < n; i++) {
    ans = max(ans, ar[i]);
  }

  // sort(cou.begin(), cou.begin() + vec[n - 1] + 1, greater<int>());
  if (n != 1) {
    cout << ans << endl;
  } else {
    cout << 1;
  }
  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> cnt(100000, 0);
  int maxa = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    cnt.at(a)++;
    maxa = max(maxa, a);
  }
  int ans = 0;
  for (int X = 1; X <= maxa; ++X) {
    int res = cnt.at(X - 1) + cnt.at(X) + cnt.at(X + 1);
    ans = max(ans, res);
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> cnt(100000, 0);
  int maxa = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    cnt.at(a)++;
    maxa = max(maxa, a);
  }
  int ans = 0;
  for (int X = 1; X < 99999; ++X) {
    int res = cnt.at(X - 1) + cnt.at(X) + cnt.at(X + 1);
    ans = max(ans, res);
  }
  cout << ans << endl;

  return 0;
}
Problem p03611 (C++)

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

using namespace std;

int main() {
  int n;
  cin >> n;

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

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

#if 0
  for (int i = 0; i < n; i++) {
    cout << a[i] << ", ";
  }
  cout << endl;
#endif

  int max_count = 0;
  //   for (int i = 0; i < n; i++) {
  //     int count = 0;
  //     int j = i;
  //     while (a[j] - a[i] <= 2 && j < n) {
  //       count++;
  //       j++;
  //     }
  //     if (count > max_count) {
  //       max_count = count;
  //     }
  //   }

  vector<int> same_num_count(a[n - 1] + 1);
  for (int i = 0; i < n; i++) {
    same_num_count[a[i]]++;
  }

#if 0
  for (int i = 0; i < same_num_count.size(); i++) {
    cout << same_num_count[i] << ", ";
  }
  cout << endl;
#endif

  for (int i = 0; i < same_num_count.size() - 2; i++) {
    int count =
        same_num_count[i] + same_num_count[i + 1] + same_num_count[i + 2];
    if (count > max_count) {
      max_count = count;
    }
  }

  cout << max_count << endl;

  return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;

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

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

#if 0
  for (int i = 0; i < n; i++) {
    cout << a[i] << ", ";
  }
  cout << endl;
#endif

  int max_count = 0;
  //   for (int i = 0; i < n; i++) {
  //     int count = 0;
  //     int j = i;
  //     while (a[j] - a[i] <= 2 && j < n) {
  //       count++;
  //       j++;
  //     }
  //     if (count > max_count) {
  //       max_count = count;
  //     }
  //   }

  vector<int> same_num_count(a[n - 1] + 1);
  for (int i = 0; i < n; i++) {
    same_num_count[a[i]]++;
  }

#if 0
  for (int i = 0; i < same_num_count.size(); i++) {
    cout << same_num_count[i] << ", ";
  }
  cout << endl;
#endif

  if (same_num_count.size() == 1) {
    max_count = same_num_count[0];
  } else if (same_num_count.size() == 2) {
    max_count = same_num_count[0] + same_num_count[1];
  } else {
    for (int i = 0; i < same_num_count.size() - 2; i++) {
      int count =
          same_num_count[i] + same_num_count[i + 1] + same_num_count[i + 2];
      if (count > max_count) {
        max_count = count;
      }
    }
  }

  cout << max_count << endl;

  return 0;
}
Problem p03611 (C++)

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

int main() {
  int n;
  cin >> n;
  int a;
  vector<int> vec(n + 15);
  for (int i = 0; i < n; i++) {
    cin >> a;
    vec.at(a + 3)++;
    vec.at(a + 4)++;
    vec.at(a + 5)++;
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  cout << vec.at(0) << endl;
}


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

int main() {
  int n;
  cin >> n;
  int a;
  vector<int> vec(100010);
  for (int i = 0; i < n; i++) {
    cin >> a;
    vec.at(a + 3)++;
    vec.at(a + 4)++;
    vec.at(a + 5)++;
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  cout << vec.at(0) << endl;
}
Problem p03611 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> num(100001, 0);
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    num[tmp]++;
    num[tmp + 1]++;
    num[tmp - 1]++;
  }

  int ans = 0;
  for (int i = 0; i < (int)num.size(); i++) {
    // printf("%d:%d\n", i, num[i]);
    if (ans < num[i]) {
      ans = num[i];
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> num(100001, 0);
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    num[tmp]++;
    num[tmp + 1]++;
    if (tmp > 0) {
      num[tmp - 1]++;
    }
  }

  int ans = 0;
  for (int i = 0; i < (int)num.size(); i++) {
    // printf("%d:%d\n", i, num[i]);
    if (ans < num[i]) {
      ans = num[i];
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define MOD 1000000007
#define all(c) c.begin(), c.end()
#define rep(i, s, e) for (auto i = s; i < e; i++)
#define peek(c)                                                                \
  for (auto i : c)                                                             \
    cout << i << ' ';

void solve() {
  ll n;
  cin >> n;
  map<ll, ll> m;
  rep(i, 0, n) {
    ll x;
    cin >> x;
    m[x]++;
  }
  ll res = INT_MIN;
  for (auto i : m) {
    ll x = i.first;
    res = max(res, m[x - 1] + m[x] + m[x + 1]);
  }
  cout << res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  cerr << "\n\n~" << 500 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define MOD 1000000007
#define all(c) c.begin(), c.end()
#define rep(i, s, e) for (auto i = s; i < e; i++)
#define peek(c)                                                                \
  for (auto i : c)                                                             \
    cout << i << ' ';

void solve() {
  ll n;
  cin >> n;
  map<ll, ll> m;
  rep(i, 0, n) {
    ll x;
    cin >> x;
    m[x]++;
  }
  ll res = INT_MIN;
  for (auto i : m) {
    ll x = i.first;
    ll prev, cur, next;
    prev = cur = next = 0;
    if (m.find(x - 1) != m.end())
      prev = m[x - 1];
    if (m.find(x) != m.end())
      cur = m[x];
    if (m.find(x + 1) != m.end())
      next = m[x + 1];
    res = max(res, prev + cur + next);
  }
  cout << res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  cerr << "\n\n~" << 500 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
Problem p03611 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> b;
  for (int i = 0; i < n; i++) {
    cin >> a.at(n);
    b[a.at(n)]++;
  }
  sort(a.begin(), a.end());
  int f = a.at(0);
  int l = a.at(n - 1);
  int max = 0;
  for (int i = f; i <= l; i++) {
    if (b[i] + b[i + 1] + b[i + 2] > max)
      max = b[i] + b[i + 1] + b[i + 2];
  }
  cout << max << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> b;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    b[a.at(i)]++;
  }
  sort(a.begin(), a.end());
  int f = a.at(0);
  int l = a.at(n - 1);
  int max = 0;
  for (int i = f; i <= l; i++) {
    if (b[i] + b[i + 1] + b[i + 2] > max)
      max = b[i] + b[i + 1] + b[i + 2];
  }
  cout << max << endl;
}
Problem p03611 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> count(100005);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    count[a]++;
    count[a - 1]++;
    count[a + 1]++;
  }
  int ans = 0;
  for (int i = 0; i < count.size(); i++) {
    ans = max(ans, count[i]);
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> count(100005);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    count[a]++;
    if (a - 1 == -1) {
      count[100001]++;
    } else {
      count[a - 1]++;
    }
    count[a + 1]++;
  }
  int ans = 0;
  for (int i = 0; i < count.size(); i++) {
    ans = max(ans, count[i]);
  }
  cout << ans << endl;
}
Problem p03611 (C++)

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

const long long MAX = 1e5 + 5;

int main(void) {
  int N;
  cin >> N;
  vector<long long> a(N);
  vector<long long> bucket(N);

  for (long long i = 0; i < N; i++) {
    cin >> a[i];
    bucket[a[i]]++;
  } // for

  long long ans = bucket[0] + bucket[1];
  for (long long i = 1; i <= MAX; i++) {
    long long count = bucket[i - 1] + bucket[i] + bucket[i + 1];
    ans = max(ans, count);
  } // for

  cout << ans << "\n";
} // main


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

const long long MAX = 1e5 + 5;

int main(void) {
  int N;
  cin >> N;
  vector<long long> a(N);
  vector<long long> bucket(MAX);

  for (long long i = 0; i < N; i++) {
    cin >> a[i];
    bucket[a[i]]++;
  } // for

  long long ans = bucket[0] + bucket[1];
  for (long long i = 1; i <= MAX; i++) {
    long long count = bucket[i - 1] + bucket[i] + bucket[i + 1];
    ans = max(ans, count);
  } // for

  cout << ans << "\n";
} // main
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vll a(n), ans(100010, 0);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    ans[a[i]]++;
    ans[a[i] + 1]++;
    ans[a[i] - 1]++;
  }
  cout << *max_element(ans.begin(), ans.end());
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vll a(n), ans(100010, 0);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    ans[a[i]]++;
    ans[a[i] + 1]++;
    ans[a[i] + 2]++;
  }
  cout << *max_element(ans.begin(), ans.end());
}
Problem p03611 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, j, n) for (ll i = j; i < n; i++)
#define all(vec) vec.begin(), vec.end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  ll ans = 0;
  rep(i, n) {
    ll l = 0;
    while (i + l < n && a[i + l] - a[i] <= 2)
      l++;
    chmax(ans, l);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, j, n) for (ll i = j; i < n; i++)
#define all(vec) vec.begin(), vec.end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  ll ans = 0;
  ll r = 0;
  rep(l, n) {
    while (r < n && a[r] - a[l] <= 2)
      r++;
    chmax(ans, r - l);
  }
  cout << ans << endl;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int n, a;
  cin >> n;
  std::vector<int> c(10002);
  for (int i = 0; i < n; i++) {
    cin >> a;
    c[a]++;
    c[a + 1]++;
    c[a + 2]++;
  }
  cout << *max_element(c.begin(), c.end());
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int n, a;
  cin >> n;
  std::vector<int> c(100002);
  for (int i = 0; i < n; i++) {
    cin >> a;
    c[a]++;
    c[a + 1]++;
    c[a + 2]++;
  }
  cout << *max_element(c.begin(), c.end());
}