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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, d, n, m, i, j, p, q, sum = 0, cnt1 = 0, cnt, cnt2 = 0,
                                              cnt3 = 0, flag = 0;
  long long int it, st, ct, qt;
  string str, ptr;
  vector<long long int> veci;
  vector<char> vecc;
  vector<string> vecs;
  queue<long long int> vecq;
  set<long long int> si;
  cin >> n;
  vector<long long int> count(n + 1, 0);
  for (i = 1; i < n; i++) {
    cin >> a;
    // veci.push_back(a);
    count[a]++;
  }
  for (i = 1; i <= n; i++)
    cout << count[i] << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, d, n, m, i, j, p, q, sum = 0, cnt1 = 0, cnt, cnt2 = 0,
                                              cnt3 = 0, flag = 0;
  long long int it, st, ct, qt;
  string str, ptr;
  vector<long long int> veci;
  vector<char> vecc;
  vector<string> vecs;
  queue<long long int> vecq;
  set<long long int> si;
  cin >> n;
  vector<long long int> count(150000, 0);
  for (i = 1; i < n; i++) {
    cin >> a;
    veci.push_back(a);
    count[a]++;
  }
  for (i = 1; i <= n; i++)
    cout << count[i] << endl;

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

#include <iostream>
#include <map>

using namespace std;

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

  map<int, int> mp;

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

    mp[a]++;
  }

  int temp = 1;
  for (auto p : mp) {
    for (int i = 0; i < p.first - temp; i++) {
      cout << "0" << endl;
    }

    temp += p.first - temp + 1;

    cout << p.second << endl;
  }

  temp--;
  while (temp - n) {
    cout << "0" << endl;
    temp++;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>

using namespace std;

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

  map<int, int> mp;

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

    mp[a]++;
  }

  for (int i = 1; i <= n; i++) {
    bool can = true;
    for (auto p : mp) {
      if (i == p.first) {
        cout << p.second << endl;
        can = false;
      }
    }

    if (can) {
      cout << "0" << 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> s(n, 0);
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    s[a - 1] += 1;
  }
  for (int x : s) {
    cout << x << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <string>
using namespace std;
int main() {
  int m;
  cin >> m;
  int a[m];
  int count[1000] = {0};

  for (int i = 0; i < m - 1; i++) {
    cin >> a[i];
    count[a[i]]++;
  }
  for (int i = 1; i <= m; i++)
    cout << count[i] << "\\n";

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  ll n, m, a[200005] = {}, b;
  cin >> n;
  for (ll i = 1; i < n; i++) {
    cin >> b;
    a[b]++;
  }
  for (ll i = 1; i <= n; i++) {
    cout << a[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int n, m, a[100005] = {}, b;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> b;
    a[b]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << a[i] << 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> vec(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> vec.at(i);
  }
  vector<int> count(N);
  for (int i = 0; i < N - 1; i++)

    count.at(vec.at(i) - 1)++;

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


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  vector<int> count(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i + 1 == vec.at(j))
        count.at(i)++;
    }
  }
  for (int i = 0; i < N; i++)
    cout << count.at(i) << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>

using namespace std;

int main() {
  map<int, int> map;
  int n, in, buf;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> in;
    buf = map[in] + 1;
    map[in] = buf;
  }
  for (int i = 1; i < n + 1; i++) {
    cout << map[i] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <list>

using namespace std;

int main() {
  list<int> list;
  list.push_back(0);
  int n, buf;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> buf;
    list.push_back(buf);
  }
  for (int i = 1; i < n + 1; i++) {
    int count = 0;
    for (auto it = list.begin(); it != list.end(); ++it) {
      if (*it == i) {
        count++;
      }
    }
    cout << count << 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;
using ll = long long;
typedef std::pair<int, int> ipair;

int main() {
  int n;

  cin >> n;
  vector<ll> a(n - 1, 0);
  rep(i, n - 1) { cin >> a[i]; }

  vector<ll> count(n, 0);
  // int count[1000000];
  rep(i, n - 1) { count[a[i] - 1]++; }

  rep(i, n) { cout << count[i] << endl; }

  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

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

int main() {
  int n;
  vector<ll> a(n - 1, 0);
  // int a[1000000];
  cin >> n;
  rep(i, n - 1) { cin >> a[i]; }

  vector<ll> count(n, 0);
  // int count[1000000];
  rep(i, n - 1) { count[a[i] - 1]++; }

  rep(i, n) { cout << count[i] << endl; }

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int p[200001] = {0};
  int a, n;
  cin >> n;
  rep(i, n - 1) {
    cin >> a;
    p[a - 1]++;
  }
  rep(i, n) { cout << p[i] << endl; }
}

Error: 0

Fixed submission:

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

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

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N); // A[i]はiの上司を指す。
  A.at(0) = 0;
  for (int i = 1; i < N; i++)
    cin >> A.at(i); // [(0), 1, 1, 2, 2]

  // 各上司について部下を求める。これには2次配列を用いる
  // 5人で、1 1 2 2 の場合、2と3の上司が1、4と5の上司は2となる。
  // [[2,3], [4,5], [], [], []]のような物を得たい。
  vector<vector<int>> B(N, vector<int>(0));

  /* for (int i = 1; i < N; i++){
(*_*; これでもできるがTLE ちょっとの改善でO(N)にできる!
      for (int j = 1; j <= N; j++){
          if (A.at(i) == j) B.at(j-1).push_back(i+1);
      }} */

  for (int i = 1; i < N; i++) {      // iはAの添え字
    int boss = A.at(i);              // i+1番目の上司の番号はboss
    B.at(boss - 1).push_back(i + 1); // こうすれば、O(N) !!
  }

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

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N); // A[i]はiの上司を指す。
  A.at(0) = 0;
  for (int i = 1; i < N; i++)
    cin >> A.at(i); // [(0), 1, 1, 2, 2]

  // 各上司について部下を求める。これには2次配列を用いる
  // 5人で、1 1 2 2 の場合、2と3の上司が1、4と5の上司は2となる。
  // [[2,3], [4,5], [], [], []]のような物を得たい。
  vector<vector<int>> B(N, vector<int>(0));
  for (int i = 1; i < N; i++) {
    for (int j = 1; j <= N; j++) {
      if (A.at(i) == j)
        B.at(j - 1).push_back(i + 1);
    }
  }

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

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

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

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

Error: TLE

Fixed submission:

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

using pii = pair<int, int>;

int main() {
  int N;
  cin >> N;
  int A[N]; // 上司に指定された社員番号を入れる配列

  for (int i = 0; i < N - 1; i++) { // 社員番号1には上司がいない。N-1個の入力
    cin >> A[i];
  }

  for (int i = 1; i <= N; i++) { // 社員番号1～Nまで出力
    int count = 0;
    for (int j = 0; j < N - 1; j++) { // 配列のj番目が社員番号と一致していたら
      if (i == A[j])
        count++; // 部下を持っているのでインクリ
    }
    cout << count << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int N = 0; // 総人数
  // int b = 0;//宿題の個数
  // int c = 0;

  cin >> N;

  vector<int> vec(N);
  // vector<int> mem(N);//記憶用
  vector<int> output(N); // 各社員番号の部下の人数

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

    output.at(k) = 0;
    // c+=vec.at(k);
  }

  int a = 0;
  // cout << a << b << c << endl;
  // m：考えている社員番号
  for (int m = 0; m < N - 1; m++) {
    a = vec.at(m);
    output.at(a - 1) = output.at(a - 1) + 1;
  }
  for (int j = 0; j < N; j++) {
    cout << output.at(j) << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {

  int N = 0; // 総人数
  // int b = 0;//宿題の個数
  // int c = 0;

  cin >> N;

  vector<int> vec(N);
  // vector<int> mem(N);//記憶用
  vector<int> output(N); // 各社員番号の部下の人数

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

    output.at(k) = 0;
    // c+=vec.at(k);
  }

  // cout << a << b << c << endl;
  // mが考えている社員番号
  for (int m = 0; m < N - 1; m++) {
    for (int k = 0; k < N; k++) {
      if (vec.at(k) == m + 1) {
        output.at(m) = output.at(m) + 1;
      }
    }
  }
  for (int j = 0; j < N; j++) {
    cout << output.at(j) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
#define pb push_back
int b[200005];

int main() {
  int n;
  cin >> n;
  unordered_map<int, int> mp;
  unordered_map<int, int>::iterator it;
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    mp[x]++;
  }
  for (it = mp.begin(); it != mp.end(); it++) {
    b[(it->first) - 1] = it->second;
  }
  for (int i = 0; i < n; i++)
    cout << b[i] << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define pb push_back
int b[20005];

int main() {
  int n;
  cin >> n;
  unordered_map<int, int> mp;
  unordered_map<int, int>::iterator it;
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    mp[x]++;
  }
  for (it = mp.begin(); it != mp.end(); it++) {
    b[(it->first) - 1] = it->second;
  }
  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>
#define ll long long int
using namespace std;

int main() {
  ll n;
  cin >> n;
  ll b[200001] = {0}, x;
  for (ll i = 1; i < n; i++) {
    cin >> x;
    b[x]++;
  }
  for (ll i = 1; i <= n; i++) {
    cout << b[i] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  int b[100001] = {0}, x;
  for (int i = 1; i < n; i++) {
    cin >> x;
    b[x]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << b[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int l1;
#define pb push_back
#define input                                                                  \\
  l1 t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
l1 min(l1 a, l1 b) {
  l1 ma = (a < b) ? a : b;
  return ma;
}
l1 max(l1 a, l1 b) {
  l1 ma = (a > b) ? a : b;
  return ma;
}
l1 gcd(l1 a, l1 b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
#define pie 3.14159265358979323
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  l1 n, m, x;
  cin >> n;
  vector<l1> a, b;
  for (l1 i = 0; i < n; i++) {
    b.pb(0);
  }
  l1 s = 0;
  for (l1 i = 1; i < n; i++) {
    cin >> x;
    b[x - 1]++;
  }
  for (l1 i = 0; i < n; i++) {
    cout << b[i] << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int l1;
#define pb push_back
#define input                                                                  \\
  l1 t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
l1 min(l1 a, l1 b) {
  l1 ma = (a < b) ? a : b;
  return ma;
}
l1 max(l1 a, l1 b) {
  l1 ma = (a > b) ? a : b;
  return ma;
}
l1 gcd(l1 a, l1 b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
#define pie 3.14159265358979323
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  l1 n, m, x;
  cin >> n;
  vector<l1> a;
  l1 s = 0;
  for (l1 i = 0; i < n - 1; i++) {
    cin >> x;
    a.pb(x);
  }
  for (l1 i = 1; i <= n; i++) {
    cout << count(a.begin(), a.end(), i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

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

  vector<int> a(n, 0);

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

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

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

const int MAX_N = 1e5 + 10;

int main() {
  int n, a[MAX_N], ai;

  cin >> n;

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

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

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

#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int n;
vector<int> a;
vector<int> b;

int main() {

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

  rep(i, n - 1) { b[a[i] - 1]++; }

  rep(i, n) {
    cout << b[i];
    if (i != n - 1)
      cout << " ";
  }
  cout << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

const int MAX_N = 1e5 + 10;

int main() {
  int n, a[MAX_N];

  cin >> n;

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

  for (int i = 0; i < n; i++) {
    printf("%d\\n", a[i]);
  }

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

#include <bits/stdc++.h>
using namespace std;
main() {
  int a, n;
  cin >> n;
  vector<int> m;
  for (int i = 1; i < n; i++) {
    cin >> a;
    m.push_back(a);
  }
  unordered_map<int, int> mp;
  for (int i = 0; i < m.size(); i++) {
    mp[m[i]] = mp[m[i]] + 1;
  }
  for (int i = 1; i <= n; i++) {
    if (mp[i] > 0) {
      cout << mp[i] << endl;
    } else {
      cout << 0 << endl;
    }
  }
}

Error: TLE

Fixed submission:

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

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

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  vector<int> b(n, 0);
  rep(i, n - 1) cin >> a[i];
  sort(a.begin(), a.end());
  int i = 1, j = 0;
  while (i < n) {
    if (i == a[j]) {
      ++b[i - 1];
      ++j;
      continue;
    } else if (i != a[j]) {
      ++i;
      continue;
    }
  }
  rep(i, n) cout << b.at(i) << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  vector<int> b(n, 0);
  rep(i, n - 1) cin >> a[i];
  sort(a.begin(), a.end());
  rep(i, n - 1) {
    for (int j = i; j < n - 1; ++j) {
      if (i + 1 == a[j]) {
        ++b[i];
      } else if (i + 1 < a[j]) {
        break;
        i = j;
      }
    }
  }
  rep(i, n) cout << b.at(i) << "\\n";
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(200010), count(200010);
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    count[i] = 0;
  }
  for (int i = 2; i <= n; i++) {
    count[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << count[i] << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

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

  for (int i = 0; i < n; i++) {
    count[a[i]]++;
  }
  for (int i = 0; i < n + 1; i++) {
    cout << count[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<int> A(N), vec(N);

  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
    vec.at(A.at(i) - 1)++;
  }
  /*
    for(int i=0;i<N-1;i++){
        for(int j=0;j<N-1;j++){
          if(i == A.at(j)-1){
            vec.at(i)++;
          }
        }
    }
  */
  for (int i = 0; i < N; i++) {
    cout << vec.at(i) << endl;
  }

  /*
    map<char, int> A(N);
    for(int i=0;i<N;i++){
      A()
    }
  */
}


Error: TLE

Fixed submission:

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

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

  vector<int> A(N), vec(N);

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

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

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

#include <algorithm>
#include <cstdio>
#include <iostream>

#define MAX_N 200000

using namespace std;

int A[MAX_N];
int answer[MAX_N];

int main() {
  int N;
  cin >> N;
  for (int i = 2; i <= N; i++)
    cin >> A[i];
  for (int i = 2; i <= N; i++)
    answer[A[i]]++;
  for (int i = 1; i <= N; i++)
    cout << answer[i] << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>

#define MAX_N 200000
int answer[MAX_N + 1];

using namespace std;

size_t array_count_values(const int *array, int size, int value) {
  int count = 0;
  for (int i = 1; i <= size; i++) {
    if (array[i] == value) {
      count++;
    }
  }
  return count;
}

int main() {
  int N;
  int A[MAX_N + 1];

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

  for (int i = 1; i <= N; i++) {
    answer[i] = array_count_values(A, N, i);
    printf("%d\\n", answer[i]);
  }

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

#pragma GCC optimize("Ofast", 3, "inline")
#include <bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int>> min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int mon[20] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
ll gcd(ll x, ll y) { return ((y == 0) ? x : gcd(y, x % y)); }
ll n, a[200010], x;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  //	freopen(".in","r",stdin);
  //	freopen(".out","w",stdout);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> x;
    x--;
    a[x]++;
  }
  for (int i = 0; i < n; i++)
    cout << a[i] << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#pragma GCC optimize("Ofast", 3, "inline")
#include <bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int>> min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int mon[20] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
ll gcd(ll x, ll y) { return ((y == 0) ? x : gcd(y, x % y)); }
ll n, a[100010], x;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  //	freopen(".in","r",stdin);
  //	freopen(".out","w",stdout);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> x;
    x--;
    a[x]++;
  }
  for (int i = 0; i < n; i++)
    cout << a[i] << '\\n';
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, A[1000000], i, j;
  cin >> N;
  for (i = 2; i <= N; i++) {
    cin >> j;
    A[j]++;
  }
  for (i = 1; i <= N; i++) {
    cout << A[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int n;
vector<int> A;
int cnt[200000];

void solve() {
  for (int i = 0; i < n; i++) {
    cnt[i] = 0;
  }
  for (auto &e : A) {
    cnt[e - 1]++;
  }
  for (int i = 0; i < n; i++)
    cout << cnt[i] << endl;
}

int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    A.push_back(a);
  }
  solve();

  return EXIT_SUCCESS;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int n;
vector<int> A;
ll cnt[20001];

void solve() {
  for (int i = 0; i < n; i++) {
    cnt[i] = 0;
  }
  for (auto &e : A) {
    cnt[e - 1]++;
  }
  for (int i = 0; i < n; i++)
    cout << cnt[i] << endl;
}

int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    A.push_back(a);
  }
  solve();

  return EXIT_SUCCESS;
}