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

#include <bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using Heap = priority_queue<T>;
template <class T> using heaP = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template <class T> using uset = unordered_set<T>;

template <class T> bool ChangeMax(T &a, const T &b) {
  if (a >= b)
    return false;
  a = b;
  return true;
}

template <class T> bool ChangeMin(T &a, const T &b) {
  if (a <= b)
    return false;
  a = b;
  return true;
}

template <class T, size_t N, class U> void Fill(T (&a)[N], const U &v) {
  fill((U *)a, (U *)(a + N), v);
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &e : v)
    is >> e;
  return is;
}

int main() {
  int n;
  cin >> n;
  vector<int> v(n - 1);
  cin >> v;
  vector<int> ans(n);
  for (auto e : v) {
    ans[e - 1]++;
  }
  for (auto e : ans)
    cout << e << endl;
  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using Heap = priority_queue<T>;
template <class T> using heaP = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template <class T> using uset = unordered_set<T>;

template <class T> bool ChangeMax(T &a, const T &b) {
  if (a >= b)
    return false;
  a = b;
  return true;
}

template <class T> bool ChangeMin(T &a, const T &b) {
  if (a <= b)
    return false;
  a = b;
  return true;
}

template <class T, size_t N, class U> void Fill(T (&a)[N], const U &v) {
  fill((U *)a, (U *)(a + N), v);
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &e : v)
    is >> e;
  return is;
}

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  cin >> v;
  vector<int> ans(n);
  for (auto e : v) {
    ans[e - 1]++;
  }
  for (auto e : ans)
    cout << e << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  long long d[2000001], a[2000001], i, n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
    d[a[i]]++;
  }
  for (int i = 1; i <= n; i++)
    cout << d[i] << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int d[20001], a[20001], i, n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
    d[a[i]]++;
  }
  for (int i = 1; i <= n; i++)
    cout << d[i] << "\\n";
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<long long> b(n);
  for (long long i = 0; i < n - 1; i++) {
    b.at(a.at(i) - 1)++;
  }
  for (long long i = 0; i < n; i++) {
    cout << b.at(i) << endl;
  }
}

Error: TLE

Fixed submission:

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

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

  vector<long long> b(n);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n - 1; j++) {
      if (a.at(j) == i + 1) {
        b.at(i)++;
      }
    }
    cout << b.at(i) << endl;
  }
}
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 + 1, 0);
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> ans(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    ans[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


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, -1);
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  vector<int> ans(n, 0);
  for (int i = 0; i < n; i++)
    ans[a[i]]++;
  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 lli long long
int main() {
  lli n, i, j, c = 0, s = 0;
  cin >> n;
  lli arr[n - 1];
  lli brr[1000001] = {0};
  for (i = 0; i < n - 1; i++)
    cin >> arr[i];
  unordered_map<lli, lli> m;
  for (i = 0; i < n - 1; i++) {
    m[arr[i]]++;
  }
  for (auto it : m) {
    brr[it.first] = it.second;
  }
  for (i = 1; i <= n; i++) {
    cout << brr[i] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lli long long
int main() {
  lli n, i, j, c = 0, s = 0;
  cin >> n;
  lli arr[n - 1];
  lli brr[10001] = {0};
  for (i = 0; i < n - 1; i++)
    cin >> arr[i];
  unordered_map<lli, lli> m;
  for (i = 0; i < n - 1; i++) {
    m[arr[i]]++;
  }
  for (auto it : m) {
    brr[it.first] = it.second;
  }
  for (i = 1; i <= n; i++) {
    cout << brr[i] << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define MAX 10000005
int a[MAX] = {0};
int main() {
  int n, i, temp;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> temp;
    a[temp]++;
  }
  for (i = 1; i <= n; i++) {
    cout << a[i] << endl;
    ;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, temp = 0, j;
  cin >> n;
  int a[n];
  for (i = 1; i < n; i++) {
    cin >> a[i];
  }
  for (j = 1; j <= n; j++) {
    temp = 0;
    for (i = 1; i < n; i++) {
      if (j == a[i])
        temp++;
    }
    cout << temp << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

  vector<int> buka(N);
  for (int i = 0; i < N - 1; i++) {
    buka.at(joushi.at(i) - 1) += 1;
  }

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

  return 0;
}


Error: TLE

Fixed submission:

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

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

  vector<int> joushi(N - 1);

  for (int i = 0; i < N - 1; i++) {
    cin >> joushi.at(i);
  }

  for (int j = 0; j < N; j++) {
    vector<int> buka(N);
    for (int h = j; h < N - 1; h++) {
      if (joushi.at(h) == j + 1) {
        buka.at(j) += 1;
      }
    }

    cout << buka.at(j) << endl;
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int n;
  cin >> n;
  map<int, int> a;
  rep(i, n - 1) {
    int b;
    cin >> b;
    b--;
    a[b]++;
  }
  vector<int> ans;
  rep(i, n - 1) { ans.push_back(a[i]); }
  ans.push_back(0);
  rep(i, n) cout << ans[i] << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int n;
  cin >> n;
  map<int, int> a;
  rep(i, n - 1) {
    int b;
    cin >> b;
    a[b]++;
  }
  vector<int> ans(n);
  rep(i, n - 1) { ans[i] = a[i + 1]; }
  ans[n] = 0;
  rep(i, n) cout << ans[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
  int n, k;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i, n - 1) { cin >> a.at(i); }
  rep(i, n - 1) { b.at(a.at(i) - 1)++; }
  rep(i, n) { cout << b.at(i) << endl; }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) { cin >> a.at(i); }
  rep(i, n) { cout << count(a.begin(), a.end(), i + 1) << endl; }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int nmax = 200005;
int v[nmax];
int main() {
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    if (x < i)
      v[x]++;
  }
  for (int i = 1; i <= n; i++)
    cout << v[i] << "\\n";
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int nmax = 20005;
int v[nmax];
int main() {
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    if (x < i)
      v[x]++;
  }
  for (int i = 1; i <= n; i++)
    cout << v[i] << "\\n";
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<int> vec(N, 0);

  for (int i = 0; i < N - 1; i++) {
    int A;
    cin >> A;
    vec.at(A - 1)++;
  }

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


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);

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

  for (int i = 1; i < N + 1; i++) {
    int B = 0;

    for (int j = 0; j < N; j++)
      if (A.at(j) == i)
        B++;

    cout << B << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int a[200010];
int ans[200010];

int main() {
  int n;
  cin >> n;
  rep(i, n - 1) cin >> a[i + 2];
  rep(i, n - 1) { ++ans[a[i + 2]]; }
  rep(i, n) cout << ans[i + 1] << endl;
  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> ans(n);
  rep(i, n) { ++ans[a[i] - 1]; }
  rep(i, n) cout << ans[i] << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio();
  cin.tie(0);
  long long int n;
  cin >> n;
  long long int a[n - 1];
  int i;
  int b[n + 1];
  memset(b, 0, sizeof(b));
  for (i = 0; i < n - 1; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (i = 1; i <= n; i++) {
    cout << b[i] << "\\n";
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[n - 1], i;
  for (i = 0; i < n - 1; i++) {
    cin >> a[i];
  }
  int j;
  int ct;
  vector<int> v;
  for (i = 1; i <= n; i++) {
    ct = 0;
    for (j = 0; j < n - 1; j++) {

      if (a[j] == i) {
        ct++;
      }
    }
    cout << ct << "\\n";
  }

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

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define _for(i, a, b) for (int i = (a); i < (b); i++)
#define endl '\\n'
#define inf 0x3f3f3f3f
#define ull unsigned long long
using namespace std;
const int mod = 1e9 + 7;
const int MAX = 2e5 + 7;
int a[MAX];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    ll x;
    cin >> x;
    a[x]++;
  }
  for (int i = 1; i <= n; i++)
    cout << a[i] << endl;
}

Error: 0

Fixed submission:

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define _for(i, a, b) for (int i = (a); i < (b); i++)
#define endl '\\n'
#define inf 0x3f3f3f3f
#define ull unsigned long long
using namespace std;
const int mod = 1e9 + 7;
const int MAX = 1e5 + 7;
ll a[MAX];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  for (int i = 1; i <= n; i++)
    cout << a[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

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

  for (long long i = 0; i < n; i++) {
    cout << b.at(i) << endl;
  }

  return 0;
}


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;

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

  for (long long i = 0; i < n; i++) {
    cout << b.at(i) << 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> number(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> number.at(i);
  }
  vector<int> buka(N, 0);
  for (int i = 0; i < N - 1; i++) {
    buka[number[i] - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << buka[i] << 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;

int main() {
  int N;
  cin >> N;
  vector<int> number(N - 1);
  for (int i = 1; i < N; i++) {
    cin >> number.at(i);
  }
  vector<int> buka(N, 0);
  for (int i = 1; i < N; i++) {
    buka[number[i] - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << buka[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int count_subordinate(int target, vector<int> &A) {
  int count = 0;

  for (int i = 0; i < A.size(); i++) {
    if (A.at(i) == target + 1) {
      count++;
    }
  }

  return count;
}

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

  vector<int> A(N);
  vector<int> C(N, 0);
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      A.at(i) = -1;
    } else {
      cin >> A.at(i);
      C.at(A.at(i) - 1)++;
    }
  }

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

Error: TLE

Fixed submission:

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

int count_subordinate(int target, vector<int> &A) {
  int count = 0;

  for (int i = 0; i < A.size(); i++) {
    if (A.at(i) == target + 1) {
      count++;
    }
  }

  return count;
}

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      A.at(i) = -1;
    } else {
      cin >> A.at(i);
    }
  }

  for (int i = 0; i < N; i++) {
    cout << count_subordinate(i, A) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: -6
double free or corruption (out)


Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i, n) b[i] = 0; // initialization
  rep(i, n) {
    cin >> a[i];
    b[a[i] - 1]++;
  }
  rep(i, n) { cout << b[i] << endl; }
  return 0;
}
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;

int main() {
  ll N;
  cin >> N;
  vector<ll> ans(200100, 0);

  for (ll i = 1; i < N; ++i) {
    ll temp;
    cin >> temp;
    ++ans[temp - 1];
  }
  for (ll i = 0; i < N; ++i) {
    cout << ans[i] << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  ll N;
  cin >> N;
  vector<ll> ans(100100, 0);

  for (ll i = 1; i < N; ++i) {
    ll temp;
    cin >> temp;
    ++ans[temp - 1];
  }
  for (ll i = 0; i < N; ++i) {
    cout << ans[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

/*Raihan Kabir
  University of Chittagong
  Bangladesh
  */
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define endl '\\n'
const int m = 2e5 + 50;
int cnt[m];
int main() {
  int n;
  cin >> n;
  vector<int> b;
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    b.push_back(a);
    cnt[a]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << cnt[i] << endl;
    ;
  }
  return 0;
}


Error: TLE

Fixed submission:

/*Raihan Kabir
  University of Chittagong
  Bangladesh
  */
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define endl '\\n'
int main() {
  int n;
  cin >> n;
  vector<int> b;
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    b.push_back(a);
  }
  for (int i = 0; i < n; i++) {
    cout << count(b.begin(), b.end(), i + 1) << endl;
    ;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;

typedef long long int ll;
const ll N = 2e5 + 9;
// const ll m = 1e9 + 7;
const ll inf = 1ll << 62;
#define x first
#define y second
#define pb push_back
#define mp make_pair
using pii = pair<ll, ll>;
const ll mod = 1e9;
ll powm(ll a, ll b) {
  a = a % mod;
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
int main() {

  ll T = 1;
  // cin>>T;
  ll ca = 1;
  while (T--) {
    ll n;
    cin >> n;
    ll p[n + 1];
    ll ct[n + 1];
    memset(ct, 0, sizeof(ct));
    for (int i = 2; i <= n; i++) {
      cin >> p[i];
      ct[p[i]]++;
    }
    for (int i = 1; i <= n; i++) {
      cout << ct[i] << '\\n';
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;

typedef long long int ll;
const ll N = 2e5 + 9;
// const ll m = 1e9 + 7;
const ll inf = 1ll << 62;
#define x first
#define y second
#define pb push_back
#define mp make_pair
using pii = pair<ll, ll>;
const ll mod = 1e9;
ll powm(ll a, ll b) {
  a = a % mod;
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
int main() {

  ll T = 1;
  // cin>>T;
  ll ca = 1;
  while (T--) {
    ll n;
    cin >> n;
    ll p[n];
    ll ct[n];
    memset(ct, 0, sizeof(ct));
    for (int i = 0; i < n; i++) {
      cin >> p[i];
      ct[p[i]]++;
    }
    for (int i = 0; i < n; i++) {
      cout << ct[i] << '\\n';
    }
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

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

  int *A = (int *)malloc(sizeof(int) * N);
  if (A == NULL) {
    printf("Memory cannot be allocated.");
  }

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

  int *Out = (int *)malloc(sizeof(int) * N);
  if (Out == NULL) {
    printf("Memory cannot be allocated.");
  }
  for (int i = 0; i < N; i++) {
    Out[i] = 0;
  }

  int num;
  for (int i = 1; i <= N - 1; i++) {
    num = A[i];
    Out[num - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << Out[i] << endl;
  }
}

Error: 0

Fixed submission:

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

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

  int *A = (int *)malloc(sizeof(int) * (N - 1));
  if (A == NULL) {
    printf("Memory cannot be allocated.");
  }

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

  int *Out = (int *)malloc(sizeof(int) * N);
  if (Out == NULL) {
    printf("Memory cannot be allocated.");
  }
  for (int i = 0; i < N; i++) {
    Out[i] = 0;
  }

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

#include <iostream>
using namespace std;

typedef long long ll;

int main() {
  int N;
  int b[200000] = {0};
  cin >> N;
  for (int i = 1; i < N; i++) {
    int tmp;
    cin >> tmp;
    b[tmp - 1]++;
  }
  for (int i = 0; i < N; i++)
    cout << b[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

typedef long long ll;

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

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, l, r) for (int i = (l); i < (r); ++i)
#define sz(x) (int)(x).size()
#define dbg(x) cout << (#x) << ' ' << (x) << endl
#define memfill(x, a) memset((x), (a), sizeof(x))
#define all(x) (x).begin(), (x).end()

typedef string str;
typedef long long int64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const int64 LLINF = 1LL << 60LL;

/*-------- END OF TEMPLATE --------*/

int N, A;
vector<int> arr(1e6, 0);

int main() {
  scanf("%i", &N);
  for (int i = 0; i < N - 1; i++) {
    scanf("%i", &A);
    arr[A]++;
  }
  for (int i = 1; i <= N; i++) {
    printf("%i\\n", arr[i]);
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, l, r) for (int i = (l); i < (r); ++i)
#define sz(x) (int)(x).size()
#define dbg(x) cout << (#x) << ' ' << (x) << endl
#define memfill(x, a) memset((x), (a), sizeof(x))
#define all(x) (x).begin(), (x).end()

typedef string str;
typedef long long int64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const int64 LLINF = 1LL << 60LL;

/*-------- END OF TEMPLATE --------*/

int N, arr[100005], A;

int main() {
  scanf("%i", &N);
  memset(arr, 0, sizeof(arr));
  for (int i = 0; i < N - 1; i++) {
    scanf("%i", &A);
    arr[A]++;
  }
  for (int i = 1; i <= N; i++) {
    printf("%i\\n", arr[i]);
  }
}