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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[]) {
  ll n;
  cin >> n;
  vector<ll> a(100000, 0);
  for (ll i = 0; i < n; i++) {
    ll temp;
    cin >> temp;
    a[temp - 1]++;
  }

  ll max = 0;
  for (ll i = 0; i < 100000; i++) {
    ll temp;
    if (i == 0)
      temp = a[i] + a[i + 1];
    else if (i == 100000 - 1)
      temp = a[i - 1] + a[i];
    else
      temp = a[i - 1] + a[i] + a[i + 1];

    if (max < temp)
      max = temp;
  }
  cout << max << endl;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[]) {
  ll n;
  cin >> n;
  vector<ll> a(100000, 0);
  for (ll i = 0; i < n; i++) {
    ll temp;
    cin >> temp;
    a[temp]++;
  }

  ll max = 0;
  for (ll i = 0; i < 100000; i++) {
    ll temp;
    if (i == 0)
      temp = a[i] + a[i + 1];
    else if (i == 100000 - 1)
      temp = a[i - 1] + a[i];
    else
      temp = a[i - 1] + a[i] + a[i + 1];

    if (max < temp)
      max = temp;
  }
  cout << max << endl;
}
Problem p03611 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def, Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def, pii> pip;
typedef vector<pip> vip;
// #define mt make_tuple
// typedef tuple<double,int,double> tp;
// typedef vector<tp> vt;
template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main() {
  int n;
  cin >> n;
  map<int, int> ma;
  rep(i, n) {
    int a;
    cin >> a;
    ma[a]++;
  }
  int out = 0;
  for (auto a : ma) {
    int t = a.first;
    out = max(out, ma[t] + ma[t - 1] + ma[t + 1]);
  }
  cout << out << endl;
}


Fixed submission:
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def, Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def, pii> pip;
typedef vector<pip> vip;
// #define mt make_tuple
// typedef tuple<double,int,double> tp;
// typedef vector<tp> vt;
template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main() {
  int n;
  cin >> n;
  map<int, int> ma;
  rep(i, n) {
    int a;
    cin >> a;
    ma[a]++;
  }
  int out = 0;
  rep(t, 100010) out = max(out, ma[t] + ma[t - 1] + ma[t + 1]);
  cout << out << endl;
}
Problem p03611 (C++)

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

int main() {
  int n;
  cin >> n;
  int num[100100100] = {0};
  int M = 0;
  rep(i, n) {
    int a;
    cin >> a;
    a++;
    num[a - 1]++;
    num[a]++;
    num[a + 1]++;
    if (a + 1 > M)
      M = a + 1;
  }
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    if (num[i] > ans)
      ans = num[i];
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int num[100100] = {0};
  int M = 0;
  rep(i, n) {
    int a;
    cin >> a;
    a++;
    num[a - 1]++;
    num[a]++;
    num[a + 1]++;
    if (a + 1 > M)
      M = a + 1;
  }
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    if (num[i] > ans)
      ans = num[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  vector<int> b(1e5);
  for (int i = 0; i < 1e5; i++) {
    b[a[i]]++;
  }
  int cnt = 0;
  int ans = 0;
  for (int i = 1; i < 1e5; i++) {
    cnt = b[i - 1] + b[i] + b[i + 1];
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  vector<int> b(1e5);
  for (int i = 0; i < N; i++) {
    b[a[i]]++;
  }
  int cnt = 0;
  int ans = 0;
  for (int i = 1; i < 1e5; i++) {
    cnt = b[i - 1] + b[i] + b[i + 1];
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}
Problem p03611 (C++)

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

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());
  a.push_back(100000);

  vector<int> ans;
  if (N >= 2) {
    for (int i = 0; i < N; i++) {
      int c = 0;
      if (i >= 1 && a[i] == a[i - 1]) {
        continue;
      }
      for (int j = i; j < N + 1; j++) {
        if (a[j] <= a[i] + 2) {
          c++;
        } else if (a[j] > a[i] + 2) {
          ans.push_back(c);
          break;
        }
      }
    }
    sort(ans.begin(), ans.end());
    cout << ans[ans.size() - 1] << endl;
  }
  if (N == 1)
    cout << 1 << endl;
}


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

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());
  a.push_back(1000000);

  vector<int> ans;
  if (N >= 2) {
    for (int i = 0; i < N; i++) {
      int c = 0;
      if (i >= 1 && a[i] == a[i - 1]) {
        continue;
      }
      for (int j = i; j < N + 1; j++) {
        if (a[j] <= a[i] + 2) {
          c++;
        } else if (a[j] > a[i] + 2) {
          ans.push_back(c);
          break;
        }
      }
    }
    sort(ans.begin(), ans.end());
    cout << ans[ans.size() - 1] << endl;
  }
  if (N == 1)
    cout << 1 << endl;
}
Problem p03611 (C++)

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

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());
  a.push_back(100000);

  vector<int> ans;
  if (N >= 2) {
    for (int i = 0; i < N; i++) {
      int c = 0;
      if (i >= 1 && a[i] == a[i - 1]) {
        continue;
      }
      for (int j = i; j < N + 1; j++) {
        if (a[j] <= a[i] + 2) {
          c++;
        } else if (a[j] > a[i] + 2) { /*aの末尾に大きい数字を足さないとa
              ={2,4}のようなケースでは、 else
              if文を満たすa[j]が存在しないので、ans配列が空集合になりREとなる*/
          ans.push_back(c);
          ans.push_back(c);
          break;
        }
      }
    }
    sort(ans.begin(), ans.end());
    cout << ans[ans.size() - 1] << endl;
  }
  if (N == 1)
    cout << 1 << endl;
}


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

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());
  a.push_back(1000000);

  vector<int> ans;
  if (N >= 2) {
    for (int i = 0; i < N; i++) {
      int c = 0;
      if (i >= 1 && a[i] == a[i - 1]) {
        continue;
      }
      for (int j = i; j < N + 1; j++) {
        if (a[j] <= a[i] + 2) {
          c++;
        } else if (a[j] > a[i] + 2) { /*aの末尾に大きい数字を足さないとa
              ={2,4}のようなケースでは、 else
              if文を満たすa[j]が存在しないので、ans配列が空集合になりREとなる*/
          ans.push_back(c);
          ans.push_back(c);
          break;
        }
      }
    }
    sort(ans.begin(), ans.end());
    cout << ans[ans.size() - 1] << endl;
  }
  if (N == 1)
    cout << 1 << endl;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// 差が2以内の数は操作により同じ数にできる
// 差が2以内の数の集合のうち、要素数がmaxのものを出力
/*先頭から順に見ていき、差が2まではカウントを増やす。差が2より大きくなると、その数より２だけ小さい数が在れば、その数の１個目からカウント再開、無ければ１だけ小さい数からカウント再開、無ければその数からカウント再開。　カウントが途切れるたびに最大のものに更新していく*/
// 数とその個数のペア配列を作る
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());
  a.push_back(-1);
  int c = 1;
  vector<pair<int, int>> p;
  for (int i = 0; i < N; i++) {
    if (a[i] == a[i + 1]) {
      c++;
    }
    if (a[i] != a[i + 1]) {
      p.push_back(make_pair(a[i], c));
      c = 1;
    }
  }
  if (p.size() == 1)
    cout << p[0].second << endl;
  else {
    p.push_back(P(100000, 1));
    int C = 0;
    int ans = 0;
    int i = 0;
    int j = 0;
    while (true) {
      if (p[j].first - p[i].first <= 2) {
        C += p[j].second;
        j++;
      } else if (p[j].first - p[i].first > 2) {
        ans = max(ans, C);
        i++;
        C = 0;
        if (p[j].first - p[i].first <= 2) {
          j = i;
        } else
          i++;
      }
      if (i == p.size() - 1)
        break;
    }
    cout << ans << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// 差が2以内の数は操作により同じ数にできる
// 差が2以内の数の集合のうち、要素数がmaxのものを出力
/*先頭から順に見ていき、差が2まではカウントを増やす。差が2より大きくなると、その数より２だけ小さい数が在れば、その数の１個目からカウント再開、無ければ１だけ小さい数からカウント再開、無ければその数からカウント再開。　カウントが途切れるたびに最大のものに更新していく*/
// 数とその個数のペア配列を作る
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());
  a.push_back(-1);
  int c = 1;
  vector<pair<int, int>> p;
  for (int i = 0; i < N; i++) {
    if (a[i] == a[i + 1]) {
      c++;
    }
    if (a[i] != a[i + 1]) {
      p.push_back(make_pair(a[i], c));
      c = 1;
    }
  }
  if (p.size() == 1)
    cout << p[0].second << endl;
  else {
    p.push_back(P(1000000, 1));
    int C = 0;
    int ans = 0;
    int i = 0;
    int j = 0;
    while (true) {
      if (p[j].first - p[i].first <= 2) {
        C += p[j].second;
        j++;
      } else if (p[j].first - p[i].first > 2) {
        ans = max(ans, C);
        i++;
        C = 0;
        if (p[j].first - p[i].first <= 2) {
          j = i;
        } else
          i++;
      }
      if (i == p.size() - 1)
        break;
    }
    cout << ans << endl;
  }
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1 << 29;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for (int i = x; i < n; i++)

int main() {
  int N, t;
  cin >> N;
  vint a(N);
  rep(i, N) {
    cin >> t;
    a[t + 1]++;
    a[t]++;
    a[t + 2]++;
  }
  sort(ALL(a));
  cout << a.back() << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1 << 29;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for (int i = x; i < n; i++)

int main() {
  int N, t;
  cin >> N;
  vint a(100006, 0);
  rep(i, N) {
    cin >> t;
    a[t + 1]++;
    a[t]++;
    a[t + 2]++;
  }
  sort(ALL(a));
  cout << a.back() << endl;
  return 0;
}
Problem p03611 (C++)

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> list(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &list[i]);
  }
  if (n == 1) {
    printf("%d", 1);
    return 0;
  }
  if (n == 2) {
    if (abs(list[0] - list[1]) <= 1) {
      printf("%d", 2);
    } else {
      printf("%d", 1);
    }
    return 0;
  }
  vector<int> num_list(n, 0);
  for (int j = 0; j < n; j++) {
    num_list[list[j] - 1] = num_list[list[j] - 1] + 1;
  }
  int max = 1;
  for (int k = 0; k <= n - 3; k++) {
    if (max < num_list[k] + num_list[k + 1] + num_list[k + 2]) {
      max = num_list[k] + num_list[k + 1] + num_list[k + 2];
    }
  }
  printf("%d", max);
  return 0;
}

Fixed submission:
#include <cmath>
#include <stdio.h>
#include <vector>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> list(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &list[i]);
  }
  if (n == 1) {
    printf("%d", 1);
    return 0;
  }
  if (n == 2) {
    if (abs(list[0] - list[1]) <= 1) {
      printf("%d", 2);
    } else {
      printf("%d", 1);
    }
    return 0;
  }
  vector<int> num_list(n, 0);
  for (int j = 0; j < n; j++) {
    num_list[list[j]] = num_list[list[j]] + 1;
  }
  int max = 1;
  for (int k = 0; k <= n - 3; k++) {
    if (max < num_list[k] + num_list[k + 1] + num_list[k + 2]) {
      max = num_list[k] + num_list[k + 1] + num_list[k + 2];
    }
  }
  printf("%d", max);
  return 0;
}
Problem p03611 (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 REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())

int chk(int x, int y) {
  if (x == y - 1) {
  }
}

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

  vector<int> A(N);
  vector<int> B(100010);
  REP(i, N) {
    cin >> A[i];
    B[A[i] - 1]++;
    B[A[i]]++;
    B[A[i] + 1]++;
  }

  sort(ALL(B));
  reverse(ALL(B));

  cout << B[0] << endl;

  return 0;
}


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 REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())

int chk(int x, int y) {
  if (x == y - 1) {
  }
}

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

  vector<int> A(N);
  vector<int> B(100010);
  REP(i, N) {
    cin >> A[i];
    if (A[i] > 0)
      B[A[i] - 1]++;
    B[A[i]]++;
    B[A[i] + 1]++;
  }

  sort(ALL(B));
  reverse(ALL(B));

  cout << B[0] << 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> da(n), co(100005, 0);
  for (int i = 0; i < n; i++) {
    cin >> da[i];
    for (int j = 0; j < 3; j++) {
      co[j + da[i]]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < 100005; i++) {
    ans = max(ans, da[i]);
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> da(n), co(100005, 0);
  for (int i = 0; i < n; i++) {
    cin >> da[i];
    for (int j = 0; j < 3; j++) {
      co[j + da[i]]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < 100005; i++) {
    ans = max(ans, co[i]);
  }
  cout << ans << endl;
}
Problem p03611 (C++)

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

int main() {
  // your code goes here
  int N;
  cin >> N;
  int a[N];
  int i;
  int a1[N], a2[N], a3[N];
  int num[100001];
  int max = 0;
  for (i = 0; i < 100001; i++) {
    num[i] = 0;
  }
  for (i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      a1[i] = a[i] - 1;
      a2[i] = a[i];
      a3[i] = a[i] + 1;
    }
  }
  for (i = 0; i < N; i++) {
    num[a1[i]]++;
    num[a2[i]]++;
    num[a3[i]]++;
  }
  for (i = 0; i < 100001; i++) {
    if (max < num[i]) {
      max = num[i];
    }
  }
  cout << max << '\n';
  return 0;
}

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

int main() {
  // your code goes here
  int N;
  cin >> N;
  int a[N];
  int i;
  int a1[N], a2[N], a3[N];
  int num[100001];
  int max = 0;
  for (i = 0; i < 100001; i++) {
    num[i] = 0;
  }
  for (i = 0; i < N; i++) {
    cin >> a[i];
    a1[i] = a[i] - 1;
    a2[i] = a[i];
    a3[i] = a[i] + 1;
  }
  for (i = 0; i < N; i++) {
    num[a1[i]]++;
    num[a2[i]]++;
    num[a3[i]]++;
  }
  for (i = 0; i < 100001; i++) {
    if (max < num[i]) {
      max = num[i];
    }
  }
  cout << max << '\n';
  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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;
}

// const int dy[] = { 0, 0, 1, -1 };
// const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a;
ll b[100000] = {0};

int main() {
  ll n, x = 0;
  ll ans = 0;
  cin >> n;

  for (ll i = 0; i < n; i++) {
    ll tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  for (ll i = 0; i < n; i++) {
    b[a[i]]++;
    if (a[i] != 0) {
      b[a[i] - 1]++;
    }
    b[a[i] + 1]++;
  }
  for (ll i = 0; i < 100000; i++) {
    ll tmp = b[i];
    ans = max(tmp, ans);
  }

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


Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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;
}

// const int dy[] = { 0, 0, 1, -1 };
// const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a;
ll b[100001] = {0};

int main() {
  ll n, x = 0;
  ll ans = 0;
  cin >> n;

  for (ll i = 0; i < n; i++) {
    ll tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  for (ll i = 0; i < n; i++) {
    b[a[i]]++;
    if (a[i] != 0) {
      b[a[i] - 1]++;
    }
    b[a[i] + 1]++;
  }
  for (ll i = 0; i < 100000; i++) {
    ll tmp = b[i];
    ans = max(tmp, ans);
  }

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

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

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

  int counts[10000] = {0};

  int i;

  for (i = 0; i < N; i++) {
    int c;
    cin >> c;

    counts[c]++;
  }

  int ans = 0;
  for (i = 0; i < 99998; i++) {
    ans = max(ans, counts[i] + counts[i + 1] + counts[i + 2]);
  }

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


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

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

  int counts[100000] = {0};

  int i;

  for (i = 0; i < N; i++) {
    int c;
    cin >> c;

    counts[c]++;
  }

  int ans = 0;
  for (i = 0; i < 99998; i++) {
    ans = max(ans, counts[i] + counts[i + 1] + counts[i + 2]);
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define INF 10000000

using namespace std;

// ifstream cin ("input.txt"); ofstream cout ("output.txt");

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    m[t]++;
  }
  vector<int> g;
  for (auto i : m) {
    g.push_back(i.first);
  }
  int ans = 0;
  for (int i = 0; i < g.size(); i++) {
    int tans = 0;
    for (int j = i; j < n; j++) {
      if (g[j] - g[i] <= 2) {
        tans += m[g[j]];
      } else
        break;
    }
    ans = max(ans, tans);
  }
  cout << ans;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define INF 10000000

using namespace std;

// ifstream cin ("input.txt"); ofstream cout ("output.txt");

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    m[t]++;
  }
  vector<int> g;
  for (auto i : m) {
    g.push_back(i.first);
  }
  int ans = 0;
  for (int i = 0; i < g.size(); i++) {
    int tans = 0;
    for (int j = i; j < g.size(); j++) {
      if (g[j] - g[i] <= 2) {
        tans += m[g[j]];
      } else
        break;
    }
    ans = max(ans, tans);
  }
  cout << ans;
}
Problem p03611 (C++)

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

int main() {
  int n, ans = 0, a, maxa = 0;
  cin >> n;
  vector<int> ac(10000000);
  for (int i = 0; i < n; i++) {
    cin >> a;
    ac[a]++;
    ac[a - 1]++;
    ac[a + 1]++;
    maxa = max(maxa, a + 1);
  }

  for (int i = 0; i <= maxa; i++) {
    ans = max(ans, ac[i]);
  }

  cout << ans;

  return 0;
}

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

int main() {
  int n, ans = 0, a, maxa = 0;
  cin >> n;
  int ac[100050] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a;
    ac[a]++;
    ac[a - 1]++;
    ac[a + 1]++;
    maxa = max(maxa, a + 1);
  }

  for (int i = 0; i <= maxa; i++) {
    ans = max(ans, ac[i]);
  }

  cout << ans;

  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, 0, N) { cin >> A[i]; }
  vector<int> a(N + 1, 0);
  for (auto i : A) {
    if (i > 0) {
      a[i - 1] += 1;
    }
    a[i] += 1;
    a[i + 1] += 1;
  }
  rsort(a);
  cout << a[0] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, 0, N) { cin >> A[i]; }
  vector<int> a(100001, 0);
  for (auto i : A) {
    if (i > 0) {
      a[i - 1] += 1;
    }
    a[i] += 1;
    a[i + 1] += 1;
  }
  rsort(a);
  cout << a[0] << endl;
  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define gcd(a, b) __gcd(a, b)
#define mem(z, i) memset(z, i, sizeof(z))
const int mod = (int)1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int z[100001];
  mem(z, 0);
  int a[n];
  for (int x = 0; x < n; x++) {
    cin >> a[x];
    z[a[x]]++;
    z[a[x] + 1]++;
    z[a[x] - 1]++;
  }
  int m = -1;
  for (int x = 0; x < 100001; x++)
    m = max(m, z[x]);
  cout << m;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define gcd(a, b) __gcd(a, b)
#define mem(z, i) memset(z, i, sizeof(z))
const int mod = (int)1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int z[100001];
  mem(z, 0);
  int a[n];
  for (int x = 0; x < n; x++) {
    cin >> a[x];
    z[a[x]]++;
    z[a[x] + 1]++;
    if (a[x] - 1 >= 0)
      z[a[x] - 1]++;
  }
  int m = -1;
  for (int x = 0; x < 100001; x++)
    m = max(m, z[x]);
  cout << m;
}
Problem p03611 (C++)

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

typedef long long ll;
#define mod 1000000007

const long double PI = acos(-1);

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
  ll n;
  cin >> n;
  ll a[n];
  vector<ll> cnt(100009, 0);
  for (ll i = 0; i < n; i++)
    cin >> a[i];

  for (ll i = 0; i < n; i++) {
    cnt[a[i]]++;
    cnt[a[i] + 1]++;
    cnt[a[i] - 1]++;
  }

  ll ans = 0;
  for (ll i = 0; i < 100001; i++)
    ans = max(ans, cnt[i]);
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
#define mod 1000000007

const long double PI = acos(-1);

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
  ll n;
  cin >> n;
  ll a[n];
  vector<ll> cnt(100009, 0);
  for (ll i = 0; i < n; i++)
    cin >> a[i];

  for (ll i = 0; i < n; i++) {
    cnt[a[i]]++;
    cnt[a[i] + 1]++;
    if (a[i] == 0)
      continue;
    cnt[a[i] - 1]++;
  }

  ll ans = 0;
  for (ll i = 0; i < 100001; i++)
    ans = max(ans, cnt[i]);
  cout << ans << endl;
  return 0;
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> a(100000, 0);
  rep(i, n) {
    int t;
    cin >> t;
    a.at(t - 1)++;
  }
  int ans = 0;
  for (int i = 0; i + 2 < 100000; i++) {
    int count = a.at(i) + a.at(i + 1) + a.at(i + 2);
    ans = max(ans, count);
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> a(100000, 0);
  rep(i, n) {
    int t;
    cin >> t;
    a.at(t)++;
  }
  int ans = 0;
  for (int i = 0; i + 2 < 100000; i++) {
    int count = a.at(i) + a.at(i + 1) + a.at(i + 2);
    ans = max(ans, count);
  }
  cout << ans << endl;
}
Problem p03611 (C++)

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

int main() {
  int N;
  cin >> N;
  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }
  vector<int> vec(N, 0);
  for (int i = 0; i < N; i++) {
    int M;
    cin >> M;
    if (M - 1 >= 0 && M - 1 <= N) {
      vec[M - 1]++;
    }
    vec[M]++;
    if (M + 1 <= N) {
      vec[M + 1]++;
    }
  }
  sort(vec.begin(), vec.end());
  cout << vec[N - 1] << endl;
}


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

int main() {
  int N;
  cin >> N;
  if (N == 1) {
    int A;
    cin >> A;
    cout << 1 << endl;
    return 0;
  }
  if (N == 2) {
    int A, B;
    cin >> A >> B;
    if (abs(A - B) < 2) {
      cout << 2 << endl;
      return 0;
    }
    cout << 1 << endl;
    return 0;
  }
  vector<int> vec(N, 0);
  for (int i = 0; i < N; i++) {
    int M;
    cin >> M;
    if (M - 1 >= 0 && M - 1 <= N) {
      vec[M - 1]++;
    }
    vec[M]++;
    if (M + 1 <= N) {
      vec[M + 1]++;
    }
  }
  sort(vec.begin(), vec.end());
  cout << vec[N - 1] << endl;
}
Problem p03611 (C++)

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

using namespace std;

typedef long long ll;
const ll INF = 1LL << 60;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

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;
}

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

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

  vector<int> b(1e5 + 2);
  for (int i = 0; i < b.size(); i++) {
    b[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    b[a[i] - 1]++;
    b[a[i]]++;
    b[a[i] + 1]++;
  }

  int ans = 0;
  for (int i = 0; i < b.size(); i++) {
    chmax(ans, b[i]);
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL << 60;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

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;
}

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

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

  vector<int> b(1e5 + 2);
  for (int i = 0; i < b.size(); i++) {
    b[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    if (a[i] > 0) {
      b[a[i] - 1]++;
    }
    b[a[i]]++;
    b[a[i] + 1]++;
  }

  int ans = 0;
  for (int i = 0; i < b.size(); i++) {
    chmax(ans, b[i]);
  }

  cout << ans << endl;

  return 0;
}
Problem p03611 (C++)

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

#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N, 0);
  REP(i, N) { cin >> a[i]; }

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

  // p, q, r : X の候補
  // q = p - 1, r = q + 1を満たす
  int p, q, r;
  int countP, countQ, countR;
  vector<int> countVec;

  // 初期化
  q = a[0];
  p = q - 1;
  r = q + 1;
  countP = 1;
  countQ = 1;
  countR = 1;
  for (int i = 1; i < N; ++i) {
    if (a[i] == q) {
      countP++;
      countQ++;
      countR++;
    } else if (a[i] == q + 1) {
      countVec.push_back(countP);
      countP = countQ + 1;
      countQ = countR + 1;
      countR = 1;
    } else if (a[i] == q + 2) {
      countVec.push_back(countP);
      countVec.push_back(countQ);
      countP = countR + 1;
      countQ = 1;
      countR = 1;
    } else {
      countVec.push_back(countP);
      countVec.push_back(countQ);
      countVec.push_back(countR);
      countP = 1;
      countQ = 1;
      countR = 1;
    }
    q = a[i];
    p = q - 1;
    r = q + 1;
  }

  int ans;
  if (N == 1) {
    ans = 1;
  } else {
    sort(countVec.begin(), countVec.end());
    ans = countVec[countVec.size() - 1];
  }

  cout << ans << endl;
}


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

#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N, 0);
  REP(i, N) { cin >> a[i]; }

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

  // p, q, r : X の候補
  // q = p - 1, r = q + 1を満たす
  int p, q, r;
  int countP, countQ, countR;
  vector<int> countVec;

  // 初期化
  q = a[0];
  p = q - 1;
  r = q + 1;
  countP = 1;
  countQ = 1;
  countR = 1;
  for (int i = 1; i < N; ++i) {
    if (a[i] == q) {
      countP++;
      countQ++;
      countR++;
    } else if (a[i] == q + 1) {
      countVec.push_back(countP);
      countP = countQ + 1;
      countQ = countR + 1;
      countR = 1;
    } else if (a[i] == q + 2) {
      countVec.push_back(countP);
      countVec.push_back(countQ);
      countP = countR + 1;
      countQ = 1;
      countR = 1;
    } else {
      countVec.push_back(countP);
      countVec.push_back(countQ);
      countVec.push_back(countR);
      countP = 1;
      countQ = 1;
      countR = 1;
    }
    q = a[i];
    p = q - 1;
    r = q + 1;
  }
  countVec.push_back(countP);
  countVec.push_back(countQ);
  countVec.push_back(countR);

  int ans;
  if (N == 1) {
    ans = 1;
  } else {
    sort(countVec.begin(), countVec.end());
    ans = countVec[countVec.size() - 1];
  }

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

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

using namespace std;

int main() {

  int n;
  cin >> n;

  int tmp;

  vector<int> a(100000, 0);

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

  int ans = 0;

  for (int i = 2; i < 100000; i++) {
    tmp = a[i - 2] + a[i - 1] + a[i];
    ans = max(tmp, ans);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {

  int n;
  cin >> n;

  int tmp;

  vector<int> a(100000, 0);

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

  int ans = 0;

  for (int i = 2; i < 100000; i++) {
    tmp = a[i - 2] + a[i - 1] + a[i];
    ans = max(tmp, ans);
  }
  cout << ans << endl;
  return 0;
}
Problem p03611 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(100001);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  long long ans = 0;
  for (int i = *min_element(a.begin(), a.end());
       i <= *max_element(a.begin(), a.end()); i++) {
    long long tmp = 0;
    tmp += b[i - 1] + b[i] + b[i + 1];
    ans = max(tmp, ans);
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(100001);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  long long ans = 0;
  for (int i = 0; i <= 100000; i++) {
    long long tmp = 0;
    tmp += b[i - 1] + b[i] + b[i + 1];
    ans = max(tmp, ans);
  }
  cout << ans << endl;
}
Problem p03611 (C++)

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

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

  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }

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

  int ans = 1;

  for (int i = 0; i < N - 1; i++) {
    int goukei = 1;
    for (int j = 1; j < N - i; j++) {
      if (p.at(i) == p.at(i + j) || p.at(i) + 1 == p.at(i + j) ||
          p.at(i) + 2 == p.at(i + j)) {
        goukei++;
      } else if (p.at(i) + 2 < p.at(i + j)) {
        break;
      }
    }
    if (goukei > ans) {
      ans = goukei;
    }
  }

  cout << ans << endl;
}

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

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

  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }

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

  int ans = 1;

  for (int i = 0; i < N - 1; i++) {
    int goukei = 1;
    for (int j = 1; j < N - i; j++) {
      if (p.at(i) == p.at(i + j) || p.at(i) + 1 == p.at(i + j) ||
          p.at(i) + 2 == p.at(i + j)) {
        goukei++;
      } else if (p.at(i) + 2 < p.at(i + j)) {
        break;
      }
    }
    if (goukei > ans) {
      ans = goukei;
    }
    if (ans > N - i) {
      break;
    }
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <unordered_set>
#include <vector>

using namespace std;
#define INF 99999
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
using namespace std;

int main() {
  int N;
  cin >> N;
  vint a(N);
  REP(i, N) cin >> a[i];
  int amax = 0;
  REP(i, N) {
    if (a[i] > amax)
      amax = a[i];
  }

  vint c(max(2, amax) + 1);
  REP(i, amax) c[i] = 0;

  REP(i, N) c[a[i]] += 1;

  int max = 0;
  REP(i, N - 2) {
    if (c[i] + c[i + 1] + c[i + 2] >= max) {
      max = c[i] + c[i + 1] + c[i + 2];
    }
  }
  cout << max;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <unordered_set>
#include <vector>

using namespace std;
#define INF 99999
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
using namespace std;

int main() {
  int N;
  cin >> N;
  vint a(N);
  REP(i, N) cin >> a[i];
  int amax = 0;
  REP(i, N) {
    if (a[i] > amax)
      amax = a[i];
  }

  vint c(max(2, amax) + 1);
  REP(i, amax) c[i] = 0;

  REP(i, N) c[a[i]] += 1;

  int max = 0;
  REP(i, c.size() - 2) {
    if (c[i] + c[i + 1] + c[i + 2] >= max) {
      max = c[i] + c[i + 1] + c[i + 2];
    }
  }
  cout << max;
}
Problem p03611 (C++)

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

int main() {
  vector<int> x(10005);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    x.at(a)++;
    x.at(a + 1)++;
    x.at(a + 2)++;
  }
  sort(x.begin(), x.end());
  reverse(x.begin(), x.end());

  cout << x.at(0);
}


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

int main() {
  vector<int> x(100100);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    x.at(a)++;
    x.at(a + 1)++;
    x.at(a + 2)++;
  }
  sort(x.begin(), x.end());
  reverse(x.begin(), x.end());

  cout << x.at(0);
}
Problem p03611 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
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;
}
int main() {
  ll n;
  cin >> n;
  ll size = 1001001;
  vector<ll> cnt(size, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    cnt[a + 1]++;
    cnt[a]++;
    cnt[a - 1]++;
  }
  ll res = 0;
  rep(i, size) chmax(res, cnt[i]);
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
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;
}
int main() {
  ll n;
  cin >> n;
  ll size = 1001001;
  vector<ll> cnt(size, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    cnt[a + 1]++;
    cnt[a]++;
    if (a > 0)
      cnt[a - 1]++;
  }
  ll res = 0;
  rep(i, size) chmax(res, cnt[i]);
  cout << res << endl;
  return 0;
}
Problem p03612 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define END(x) (*(x.end() - 1))
#define INF INT_MAX / 2

using namespace std;
typedef long long ll;

template <typename T> T gcd(T a, T b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

int main(void) {
  ll n;
  cin >> n;
  vector<ll> p(n);
  rep(i, n) { cin >> p[i]; }
  ll ans = 0;
  rep(i, n) {
    if (p[i] - 1 == i) {
      p[i + 1] = p[i];
      ++ans;
      ++i;
    }
  }
  cout << ans;
}
/*

*/


Fixed submission:
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define END(x) (*(x.end() - 1))
#define INF INT_MAX / 2

using namespace std;
typedef long long ll;

template <typename T> T gcd(T a, T b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

int main(void) {
  ll n;
  cin >> n;
  vector<ll> p(n);
  rep(i, n) { cin >> p[i]; }
  ll ans = 0;
  rep(i, n) {
    if (p[i] - 1 == i) {
      ++ans;
      ++i;
    }
  }
  cout << ans;
}
/*

*/
Problem p03612 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  int64_t count = 0;
  for (int i = 0; i < N; i++) {
    int index = i + 1;
    if (vec[i] == index) {
      int64_t tmp = vec[i];
      vec[i] = vec[i + 1];
      vec[i + 1] = tmp;
      count += 1;
    }
  }

  cout << count << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  int64_t count = 0;
  for (int i = 0; i < N; i++) {
    int index = i + 1;
    if (vec[i] == index) {
      if (index == N) {
        int64_t tmp = vec[i];
        vec[i] = vec[i - 1];
        vec[i - 1] = tmp;
      } else {
        int64_t tmp = vec[i];
        vec[i] = vec[i + 1];
        vec[i + 1] = tmp;
      }
      count += 1;
    }
  }

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

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long int;

#define rep(i, n, m) for (long long int i = n; i < (long long int)(m); i++)

int main() {

  int n;
  cin >> n;
  vector<int> num(n);
  rep(i, 0, n) cin >> num[i];

  int cnt = 0;
  bool flag = false;
  int tmp;

  while (!flag) {
    flag = true;
    rep(i, 0, n) {
      if (num[i] == i + 1) {
        flag = false;
        if (i == 0) {
          tmp = num[i];
          num[i] = num[i + 1];
          num[i + 1] = tmp;
        } else if (i == n - 1) {
          tmp = num[i];
          num[i] = num[i - 1];
          num[i - 1] = tmp;
        } else {

          if (num[i + 1] == i + 2) {
            tmp = num[i];
            num[i] = num[i + 1];
            num[i + 1] = tmp;
          } else {
            tmp = num[i];
            num[i] = num[i - 1];
            num[i - 1] = tmp;
          }
        }

        cnt++;
        break;
      }
    }
    if (flag) {
      cout << cnt << endl;
      return 0;
    }
  }

  return 0;
}

Fixed submission:

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long int;

#define rep(i, n, m) for (long long int i = n; i < (long long int)(m); i++)

int main() {

  int n;
  cin >> n;
  vector<int> num(n);
  rep(i, 0, n) cin >> num[i];

  int cnt = 0;
  bool flag = false;
  int tmp;

  while (!flag) {
    flag = true;
    rep(i, 0, n) {
      if (num[i] == i + 1) {
        flag = false;
        if (i == 0) {
          tmp = num[i];
          num[i] = num[i + 1];
          num[i + 1] = tmp;
        } else if (i == n - 1) {
          tmp = num[i];
          num[i] = num[i - 1];
          num[i - 1] = tmp;
        } else {

          if (num[i + 1] == i + 2) {
            tmp = num[i];
            num[i] = num[i + 1];
            num[i + 1] = tmp;
          } else {
            tmp = num[i];
            num[i] = num[i - 1];
            num[i - 1] = tmp;
          }
        }

        cnt++;
      }
    }
    if (flag) {
      cout << cnt << endl;
      return 0;
    }
  }

  return 0;
}
Problem p03612 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define foreps(i, m, n) for (ll i = (m); i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const long long mod = 1e9 + 7;
const long long inf = 1e18;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  map<ll, ll> mp;
  rep(i, N) cin >> A[i];

  ll res = 0;
  rep(i, N) {
    if (i + 1 == A[i]) {
      swap(A[i], A[i + 1]);
      res++;
      continue;
    }
  }
  cout << res << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define foreps(i, m, n) for (ll i = (m); i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const long long mod = 1e9 + 7;
const long long inf = 1e18;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  map<ll, ll> mp;
  rep(i, N) cin >> A[i];

  ll res = 0;
  rep(i, N) {
    if (i + 1 == A[i]) {
      if (i == N - 1) {
        swap(A[i - 1], A[i]);
        res++;
        continue;
      } else {
        swap(A[i], A[i + 1]);
        res++;
        continue;
      }
    }
  }
  cout << res << endl;
}