alexjercan/bugnet huggingface dataset:
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <sstream>
#include <string>

using namespace std;

void solve() {
  int n;
  cin >> n;
  cin.ignore();
  vector<int> in, c;
  in.reserve(n);
  c.reserve(n);
  for (int i = 0; i < n; i++)
    c[i] = 0;

  string r;
  getline(cin, r);
  istringstream iss(r);

  for (int i = 0; i < n - 1; i++) {
    iss >> in[i];
    c[in[i] - 1]++;
  }

  for (int i = 0; i < n; i++)
    cout << c[i] << endl;
}

int main() {
  solve();
  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>

using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<int> in, c;
  in.reserve(n);
  c.reserve(n);
  for (int i = 0; i < n; i++)
    c[i] = 0;

  copy_n(istream_iterator<int>(cin), n - 1, back_inserter(in));

  for (int i = 0; i < n; i++)
    c[in[i] - 1]++;

  for (int i = 0; i < n; i++)
    cout << c[i] << endl;
}

int main() {
  solve();
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <istream>
#include <map>
#include <math.h>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define fore(i, x, y) for (long long i = x; i < y; i++)
typedef long long ll;
using namespace std;

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

int main() {
  ll N;
  vector<ll> vec;
  cin >> N;
  fore(i, 0, N) { vec.push_back(0); }
  fore(i, 0, N - 1) {
    ll t;
    cin >> t;
    vec[t - 1]++;
  }
  fore(i, 0, N) { cout << vec[i] << endl; }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <istream>
#include <map>
#include <math.h>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define fore(i, x, y) for (long long i = x; i < y; i++)
typedef long long ll;
using namespace std;

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

int main() {
  ll N;
  vector<ll> vec;
  cin >> N;
  fore(i, 0, N - 1) {
    ll t;
    cin >> t;
    vec.push_back(t);
  }
  fore(i, 0, N) {
    size_t n_count = count(vec.begin(), vec.end(), i + 1);
    cout << n_count << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
// #include<string>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  int buff;
  vector<int> G(N, 0);
  for (int i = 1; i < N; i++) {
    cin >> buff;
    G[buff - 1]++;
  }

  for (int i = 0; i < N; i++) {
    cout << G[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
// #include<string>
// #include<vector>

using namespace std;

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

  int answer = 0;

  for (int i = 0; i < N; i++) {
    answer = 0;
    for (int j = i + 1; j < N; j++) {
      if (A[j] == i + 1)
        answer++;
    }
    cout << answer << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

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

  int answer[200000] = {0};

  for (int j = 1; j < N; j++) {
    answer[A[j] - 1]++;
  }

  for (int k = 0; k < N; k++) {
    cout << answer[k] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

  for (int j = 0; j < N; j++) {
    int answer = 0;
    for (int k = j + 1; k < N; k++) {
      if (A[k] == j + 1) {
        answer++;
      }
      // if(A[k] > j+1){
      //     break;
      // }
    }
    cout << answer << endl;
  }

  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long int N;
  cin >> N;
  vector<int> A(N);
  vector<int> sum(N);
  for (int i = 1; i < N; i++) {
    cin >> A.at(i);
    sum.at((A.at(i) - 1))++;
  }

  for (int i = 0; i < N; i++) {
    cout << sum.at(i) << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  long long int N;
  cin >> N;
  vector<int> A(N);
  vector<int> sum(N);
  for (int i = 1; i < N; i++) {
    cin >> A.at(i);
    for (int l = 0; l < i; l++) {
      if (A.at(i) == l + 1) {
        sum.at(l)++;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    cout << sum.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fo(i, a, b) for (int i = a; i < b; i++)
#define SQ(a) (a) * (a)

int main() {
  int n, k;
  cin >> n;
  vector<int> cnt(n + 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> k;
    cnt[k]++;
  }
  for (int i = 1; i <= n; i++)
    cout << cnt[i] << "\\n";
}

Error: TLE

Fixed submission:

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fo(i, a, b) for (int i = a; i < b; i++)
#define SQ(a) (a) * (a)

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n - 1; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    int c = count(a.begin(), a.end(), i);
    cout << c << "\\n";
  }
  a.clear();
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n;
  int *p;

  cin >> n;

  p = new int[n];

  for (int i = 0; i < n; i++)
    p[i] = 0;

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

  for (int i = 0; i < n; i++)
    cout << p[i] << endl;

  delete[] p;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  int *p;

  cin >> n;

  p = new int(n);

  for (int i = 0; i < n; i++)
    p[i] = 0;

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

  for (int i = 0; i < n; i++)
    cout << p[i] << endl;

  delete[] p;

  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long N;
  cin >> N;
  vector<long long> A(N - 1);
  vector<long long> ans(N);
  ans[0] = 0;
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i];
    ans[A[i] - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i] << endl;
  }
}


Error: 0

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N - 1);
  vector<int> ans(N);
  ans[0] = 0;
  for (int i = 1; i < N; i++) {
    ans[i] = 0;
    cin >> A[i];
    ans[A[i] - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

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

  vector<int> b(n, 0);
  for (int i = 0; i < n - 1; i++) {
    b[a[i] - 1]++;
  }
  rep(i, n) cout << b[i] << endl;
  return 0;
}

Error: -6
double free or corruption (out)


Fixed submission:

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

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

  vector<int> b(n, 0);
  rep(i, n) b[a[i] - 1]++;

  rep(i, n) cout << b[i] << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  vector<int> b(n, 0);
  for (int i = 0; i < n - 1; i++)
    cin >> a[i];
  for (auto e : a)
    b[e - 1]++;
  for (auto e : b)
    cout << e << endl;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(16);

  solve();

  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n, 0);
  for (int i = 0; i < n - 1; i++)
    cin >> a[i];
  for (auto e : a)
    b[e - 1]++;
  for (auto e : b)
    cout << e << endl;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(16);

  solve();

  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  long long int n;
  cin >> n;
  long long a[n], i;
  long long h[n + 1];
  for (i = 1; i <= n; i++) {
    h[i] = 0;
  }

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

  for (i = 1; i <= n; i++) {
    cout << h[i] << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main(void) {
  int n, i, val;
  cin >> n;
  vector<int> id;
  for (i = 1; i < n; i++) {
    cin >> val;
    id.push_back(val);
  }
  for (i = 1; i <= n; i++) {
    int ans = count(id.begin(), id.end(), i);
    cout << ans << endl;
  }

  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>

int main() {

  int N;
  std::cin >> N;

  int n[N];
  int emps[N];

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

  for (int i = 1; i < N; i++) {
    std::cin >> emps[i];
  }

  for (int i = 1; i < N; i++) {
    n[emps[i] - 1]++;
  }

  for (int i = 0; i < N; i++) {
    std::cout << n[i] << std::endl;
  }

  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <map>

int main() {

  int N;
  N = 5;
  std::cin >> N;

  int n[N];
  int emps[N];

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

  // std::cin >> N;

  // test code;
  emps[1] = 1;
  emps[2] = 1;
  emps[3] = 2;
  emps[4] = 2;

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

  for (int i = 1; i < N; i++) {
    std::cout << emps[i];
    n[emps[i] - 1]++;
  }
  std::cout << "hrer\\n";

  for (int i = 0; i < N; i++) {
    std::cout << n[i] << std::endl;
  }

  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  A[0] = N + 5;
  for (int i = 1; i < N; i++) {
    cin >> A[i];
  }
  vector<int> answer(N + 5);
  for (int i = 0; i < N; i++) {
    answer[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    answer[A[i] - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << answer[i] << endl;
  }
}


Error: -6
double free or corruption (out)


Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  A[0] = 0;
  for (int i = 1; i < N; i++) {
    cin >> A[i];
  }
  vector<int> answer(N);
  for (int i = 0; i < N; i++) {
    answer[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    answer[A[i] - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << answer[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \\t" << x.second << '\\n'

int n;
VI a(100100);
VI cnt(100010, 0);

signed main() {
  cin >> n;
  a.resize(n - 1);
  cnt.resize(n);
  REP(i, n - 1) { cin >> a[i]; }

  REP(i, n - 1) { cnt[a[i] - 1]++; }

  REP(i, cnt.size()) { cout << cnt[i] << endl; }
  return 0;
}

Error: 0

Fixed submission:

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \\t" << x.second << '\\n'

int n;
VI a(100100);
VI cnt(100010, 0);

signed main() {
  cin >> n;
  REP(i, n - 1) { cin >> a[i]; }

  a.resize(n - 1);
  cnt.resize(n);

  REP(i, n - 1) { cnt[a[i] - 1]++; }

  REP(i, n) { cout << cnt[i] << endl; }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) {
  if (x > y)
    x = y;
}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) {
  if (x < y)
    x = y;
}

int n;
vector<int> a;

void read() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int x;
    cin >> x;
    x--;
    a[x]++;
  }
  for (auto i : a)
    cout << i << "\\n";
}

void run() {}

void write() {}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  read();
  run();
  write();
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) {
  if (x > y)
    x = y;
}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) {
  if (x < y)
    x = y;
}

int n;
vector<int> a;

void read() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    x--;
    a[x]++;
  }
  for (auto i : a)
    cout << i << "\\n";
}

void run() {}

void write() {}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  read();
  run();
  write();
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int A[200000] = {};
  int N;
  cin >> N;
  std::set<int> st;
  for (int i = 1; i < N; i++) {
    int t;
    cin >> t;
    A[t - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << A[i] << endl;
  }
}


Error: 0

Fixed submission:

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

int main() {
  int A[10000] = {};
  int N;
  cin >> N;
  std::set<int> st;
  int sum = 0;
  for (int i = 1; i < N; i++) {
    int t;
    cin >> t;
    A[t - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << A[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

int main() {
  using namespace std;
  int n, t;
  vector<int> a;
  cin >> n;
  int cnt[n + 1] = {0};
  for (int i = 0; i < n - 1; i++) {
    cin >> t;
    a.push_back(t);
  }
  sort(a.begin(), a.end());
  for (auto it = a.begin(); it != a.end(); it++) {
    cnt[*it]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << cnt[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

int main() {
  using namespace std;
  int n, t, c;
  vector<int> a;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> t;
    a.push_back(t);
  }
  sort(a.begin(), a.end());
  for (int i = 1; i <= n; i++) {
    c = count(a.begin(), a.end(), i);
    cout << c << endl;
    a.erase(a.begin(), a.begin() + c);
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <bits/stdc++.h>

using namespace std;

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define tc                                                                     \\
  ll t = 0;                                                                    \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define pop pop_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define ub upper_bound
#define endl "\\n"
#define max *max_element
#define min *min_element
#define f first
#define s second
#define vli vll::iterator
#define mp make_pair
#define max_val 99999999
#define min_val -99999999
#define mod 1000000007

int main() {
  IOS
#ifdef LOCAL
      freopen("C:\\\\Users\\\\Just Coding Things\\\\Codeforces\\\\input.txt", "r",
              stdin);
  freopen("C:\\\\Users\\\\Just Coding Things\\\\Codeforces\\\\output.txt", "w", stdout);
#endif
  ll n, i, cnt;
  cin >> n;
  vll v(n - 1), u(n), x;
  for (i = 0; i < n - 1; i++) {
    cin >> cnt;
    u[cnt - 1]++;
  }

  for (i = 0; i < n; i++) {
    cout << u[i] << "\\n";
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:


#include <bits/stdc++.h>

using namespace std;

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define tc                                                                     \\
  ll t = 0;                                                                    \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define pop pop_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define ub upper_bound
#define endl "\\n"
#define max *max_element
#define min *min_element
#define f first
#define s second
#define vli vll::iterator
#define mp make_pair
#define max_val 99999999
#define min_val -99999999
#define mod 1000000007

int main() {
  IOS
#ifdef LOCAL
      freopen("C:\\\\Users\\\\Just Coding Things\\\\Codeforces\\\\input.txt", "r",
              stdin);
  freopen("C:\\\\Users\\\\Just Coding Things\\\\Codeforces\\\\output.txt", "w", stdout);
#endif
  ll n, i, cnt;
  cin >> n;
  vll v(n - 1), u(n);
  for (i = 0; i < n - 1; i++)
    cin >> v[i];

  set<int> s;
  for (i = 0; i < v.size(); i++)
    s.insert(v[i]);
  set<int>::iterator it;
  for (it = s.begin(); it != s.end(); it++) {
    ll var = *it;
    cnt = count(all(v), var);
    u[var - 1] = cnt;
  }

  for (i = 0; i < n; i++) {
    cout << u[i] << "\\n";
  }
  cout << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int n, x;
int a[200005];

int main() {
  cin >> n;

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

  for (int i = 0; i < n; i++) {
    cout << a[i] << endl;
  }
}

Error: 0

Fixed submission:

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

int n, x;
int a[100005];

int main() {
  cin >> n;

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

  for (int i = 0; i < n; i++) {
    cout << a[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n - 1);
  rep(i, n - 1) { cin >> a.at(i); }
  sort(all(a));
  ll j = 0;
  for (int i = 0; i < n - 1; i++) {
    ll count = 0;
    if (j == n - 1) {
      cout << count << "\\n";
      continue;
    }
    while (a.at(j) == i + 1) {
      count++;
      j++;
      if (j == n - 1) {
        break;
      }
    }
    cout << count << "\\n";
  }
  cout << 0 << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n - 1);
  rep(i, n - 1) { cin >> a.at(i); }
  sort(all(a));
  ll j = 0;
  ll count = 0;
  while (j <= n - 1) {
    for (ll i = 0; i < n; i++) {
      while (a.at(j) == i + 1) {
        count++;
        j++;
      }
      cout << count << "\\n";
      count = 0;
      j++;
    }
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
int main() {
  int flag = 0;
  int sum1 = 0;
  int n, m;
  int i, arr[200005];
  int brr[200005];
  memset(brr, 0, sizeof(brr));
  int sum = 0;
  scanf("%d", &n);
  for (i = 0; i < n - 1; i++) {
    scanf("%d", &arr[i]);
    if (arr[i] == 1)
      sum++;
    else
      brr[arr[i]]++;
  }
  printf("%d\\n", sum);
  for (int j = 2; j <= n; j++) {
    printf("%d\\n", brr[j]);
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
int main() {
  int flag = 0;
  int sum1 = 0;
  int n, m;
  int i, arr[200005];
  int sum = 0;
  scanf("%d", &n);
  for (i = 0; i < n - 1; i++) {
    scanf("%d", &arr[i]);
    if (arr[i] == 1)
      sum++;
  }
  printf("%d\\n", sum);
  sort(arr, arr + (n - 1));
  for (int j = 2; j <= n; j++) {
    sum1 = 0;
    if (flag == 1)
      printf("0\\n");
    else {
      for (i = 0; i < n - 1; i++) {
        if (arr[i] == j)
          sum1++;
        else if (arr[i] > j) {
          break;
        } else if (j > arr[n - 2]) {
          flag = 1;
          break;
        }
      }
      printf("%d\\n", sum1);
    }
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
int ar[200005];
int main() {

  int n;
  cin >> n;
  int x;
  for (int i = 1; i <= n - 1; i++) {
    cin >> x;
    ar[x] = ar[x] + 1;
  }

  for (int i = 1; i <= n; i++) {
    cout << ar[i] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int ar[100003];
int main() {

  int n;
  cin >> n;
  int x;
  for (int i = 1; i <= n - 1; i++) {
    cin >> x;
    ar[x] = ar[x] + 1;
  }

  for (int i = 1; i <= n; i++) {
    cout << ar[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int n;
  cin >> n;
  vector<int> a(200001);
  for (int i = 0; i < n - 1; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << a[i] << '\\n';
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int n;
  cin >> n;
  vector<int> a(20001);
  for (int i = 0; i < n - 1; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << a[i] << '\\n';
  }
}