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

#include <bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define MOD 1000000000
#define inf -100000
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
int main() {
  fast;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll int n;
  cin >> n;
  ll int a[n - 1];
  ll int i, z, s = 0;
  ll int f[200005] = {0};
  for (i = 0; i < n - 1; i++) {
    cin >> a[i];
    f[a[i]]++;
  }
  for (i = 1; i <= n; i++) {
    cout << f[i] << endl;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define MOD 1000000000
#define inf -100000
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
int main() {
  fast;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll int n;
  cin >> n;
  ll int a[n - 1];
  ll int i, z, s = 0;
  ll int f[100005] = {0};
  for (i = 0; i < n - 1; i++) {
    cin >> a[i];
    f[a[i]]++;
  }
  for (i = 1; i <= n; i++) {
    cout << f[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, 0);
  vector<int> count(N, 0);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
    count.at(A.at(i) - 1) += 1;
  }
  for (int i = 0; i < N; i++) {
    cout << count.at(i) << endl;
  }
}

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


Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  vector<int> count(N, 0);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
    count.at(A.at(i - 1)) += 1;
  }
  for (int i = 0; i < N; i++) {
    cout << count.at(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> boss(N - 1);
  for (int i = 0; i < N - 1; i++)
    cin >> boss.at(i);

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

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

Error: TLE

Fixed submission:

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

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

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

  vector<int> num(N);
  for (int i = 0; i < N - 1; i++) {
    int count = 0;
    for (int j : boss) {
      if (i == j - 1)
        count++;
    }
    num.at(i) = count;
  }

  for (int i = 0; i < N; i++)
    cout << num.at(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 - 1);
  vector<int> B(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
    B.at(A.at(i) - 1)++;
  }

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


Error: TLE

Fixed submission:

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

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

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

  int sum = 0;
  for (int i = 1; i < N + 1; i++) {
    if (sum == N - 1) {
      cout << 0 << endl;
    } else {
      sum += count(v.begin(), v.end(), i);
      cout << count(v.begin(), v.end(), 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> count(N, 0);
  for (int i = 0; i < N - 1; i++) {
    int x;
    cin >> x;
    count.at(x - 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> con(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> con.at(i);
  }

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

#include <iostream>
using namespace std;
int main() {
  int N, A;
  cin >> N;
  int S[N];
  for (int i = 0; i < N; i++) {
    S[i] = 0;
  }
  for (int i = 0; i < N - 1; i++) {
    cin >> A;
    S[A - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << S[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N - 1], cnt[N - 1];
  for (int j = 0; j < N - 1; j++) {
    cnt[j] = 0;
  }
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i];
    for (int j = 0; j < N - 1; j++) {
      if (A[i] == j + 1) {
        cnt[j]++;
      }
    }
  }
  for (int j = 0; j < N - 1; j++) {
    cout << cnt[j] << endl;
  }
  cout << 0 << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
int main() {
  int n, a[300000], b[300000] = {0}, i;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> a[i];
  }
  for (i = 1; i < n; i++) {
    b[a[i]]++;
  }
  for (i = 1; i <= n; i++) {
    cout << b[i] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
int main() {
  int n, a[100000], b[100000] = {0}, i;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> a[i];
  }
  for (i = 1; i < n; i++) {
    b[a[i]]++;
  }
  for (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;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int a[200005];
  int c[200005];
  for (int i = 1; i <= n; i++) {
    c[i] = 0;
  }

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

    cin >> a[i];
    int t = a[i];

    c[t]++;
  }

  for (int j = 1; j <= n; j++) {
    cout << c[j] << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int a[200005];
  int c[200005];
  for (int i = 1; i <= n; i++) {
    c[i] = 0;
  }

  for (int i = 2; i <= n; i++) {
    cin >> a[i];
    for (int j = 1; j <= n; j++) {
      if (a[i] == j) {
        c[j]++;
      }
    }
  }

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

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

int main() {
  int N;
  vector<int> bangou(3000000);
  vector<int> d(3000000);

  cin >> N;

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

  for (int i = 1; i < N; i++) {
    d.at(bangou.at(i)) = d.at(bangou.at(i)) + 1;
  }

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


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


Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  for (int i = 1; i < N; i++) {
    cin >> a.at(i);
  }
  for (int i = 1; i < N; i++) {
    b.at(a.at(i))++;
  }
  for (int i = 1; i <= N; i++) {
    cout << b.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <sstream>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long
#define PI 3.14159265358979323846264338327950L

#define INF 0x3f3f3f3f
// const int N = 2e5 + 5;

int a[200010];

int32_t main() {

  IOS;

  int N;
  cin >> N;

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

    int tmp;

    cin >> tmp;

    a[tmp]++;
  }

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

Error: 0

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <sstream>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long
#define PI 3.14159265358979323846264338327950L

#define INF 0x3f3f3f3f
// const int N = 2e5 + 5;

int a[100010];

int32_t main() {

  IOS;

  int N;
  cin >> N;

  int cnt = 0;
  int prev = 1;
  int tmp;
  for (int i = 1; i < N; i++) {

    cin >> tmp;

    a[tmp]++;
  }

  for (int i = 1; i <= N; i++) {
    cout << a[i] << 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 repr(i, n) for (int i = n - 1; i >= 0; i--)
#define MAX(a, b) a = a > b ? a : b
#define MIN(a, b) a = a < b ? a : b
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPR(i, x, n) for (int i = n - 1; i >= x; i--)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  ll n, m, a[201010], sum[201010] = {};
  string s;
  cin >> n;
  rep(i, n - 1) {
    cin >> a[i];
    sum[a[i]]++;
  }
  rep(i, n) { cout << sum[i + 1] << endl; }
  // cout<<endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define MAX(a, b) a = a > b ? a : b
#define MIN(a, b) a = a < b ? a : b
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPR(i, x, n) for (int i = n - 1; i >= x; i--)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  ll n, m, a[101010], sum[101010] = {};
  string s;
  cin >> n;
  rep(i, n - 1) {
    cin >> a[i];
    sum[a[i]]++;
  }
  rep(i, n) { cout << sum[i + 1] << endl; }
  // cout<<endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

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

#include <iostream>
using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

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

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

int a[200010];
int ans[200010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 2; i <= n; i++)
    ans[a[i]]++;
  for (int i = 1; i <= n; i++)
    printf("%d\\n", ans[i]);
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N + 1);
  A.at(0) = 0;
  for (int i = 1; i < N; i++)
    cin >> A.at(i);
  sort(A.begin(), A.end());
  for (int i = 1; i < A.at(N - 1) + 1; i++)
    B.at(i) = count(A.begin(), A.end(), i);
  for (int i = A.at(N - 1) + 1; i < N; i++)
    B.push_back(0);
  for (int i = 1; i < N + 1; i++)
    cout << B.at(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> temp(N);
  vector<int> num(N);

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

  for (int i = 0; i < N - 1; i++) {
    num.at(temp.at(i) - 1)++;
  }

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

Error: TLE

Fixed submission:

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

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

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

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

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

#include <iostream>

using namespace std;

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

  int A[N];

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

  int shain;

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

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


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int A[N];

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

  int B[N];

  for (int i = 0; i != N; ++i) {
    B[i] = 0;
    for (int j = 1; j != N; ++j) {
      if (i == A[j]) {
        ++B[i];
      }
    }
  }

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

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

int main() {
  int n;
  cin >> n;
  int arr[n];
  vector<int> ans(n + 1);
  map<int, int> m;
  for (int i = 1; i <= n - 1; i++) {
    cin >> arr[i];
    ans[arr[i]]++;
  }

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


Error: -11

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int arr[n];
  unordered_map<int, int> m;
  for (int i = 1; i <= n - 1; i++) {
    cin >> arr[i];
    m[arr[i]]++;
  }
  //  sort(arr,arr+n);
  for (int i = 1; i <= n; i++) {

    cout << m.find(i)->second << endl;

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

#include <iostream>
#include <vector>
using namespace std;

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

  int a;
  vector<int> ans(n - 1, 0);
  for (int i = 0; i < n - 1; i++) {
    cin >> a;
    ans.at(a - 1)++;
  }
  for (int i = 0; i < n - 1; i++) {
    cout << ans.at(i) << endl;
  }
  cout << 0 << 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 <iostream>
#include <vector>
using namespace std;

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

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

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

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define int long long
#define pb push_back
using ll = long long;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main(void) {
  int N, temp;
  vector<int> e;
  cin >> N;
  for (int i = 0; i <= N; i++) {
    e.pb(0);
  }
  for (int i = 1; i < N; i++) {
    cin >> temp;
    e[temp]++;
  }
  for (int i = 1; i <= N; i++) {
    cout << e[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define int long long
#define pb push_back
using ll = long long;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main(void) {
  int N, temp;
  string s;
  vector<int> e, A;
  cin >> N;
  for (int i = 0; i <= 20000; i++) {
    e.pb(0);
  }
  for (int i = 1; i < N; i++) {
    cin >> temp;
    // A.pb(temp);
    e[temp]++;
  }
  for (int i = 0; i < N; i++) {
    cout << e[i + 1] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i, n) for (lli i = 0; i < n; i++)
#define loop(i, j, n) for (lli i = j; i < n; i++)
lli combi(lli n, lli r) {
  if (r == 0 || r == n)
    return 1;
  else
    return combi(n - 1, r) + combi(n - 1, r - 1);
}
using namespace std;
// }}} End Header

int main() {
  lli n, A;
  cin >> n;
  vector<lli> a(n + 1, 0);
  loop(i, 2, n + 1) {
    cin >> A;
    a[A]++;
  }
  loop(i, 1, n + 1) { cout << a[i] << endl; }
}

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


Fixed submission:

#include <bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i, n) for (lli i = 0; i < n; i++)
#define loop(i, j, n) for (lli i = j; i < n; i++)
lli combi(lli n, lli r) {
  if (r == 0 || r == n)
    return 1;
  else
    return combi(n - 1, r) + combi(n - 1, r - 1);
}
using namespace std;
// }}} End Header

int main() {
  lli n;
  vector<lli> a(n + 1, 0);
  cin >> n;

  for (lli i = 2; i < n + 1; i++) {
    lli b;
    cin >> b;
    a[b]++;
  }
  for (lli j = 1; j < n + 1; j++) {
    cout << a[j] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long n, m, ans, temp;
int a[11111111];
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> temp;
    a[temp]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << a[i] << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long n, m, ans, temp;
int a[111111];
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> temp;
    a[temp]++;
  }
  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() {
  int n, a, i, m;
  cin >> n;
  int arr[n];
  memset(arr, 0, sizeof(arr));
  m = n - 1;
  while (m--) {
    cin >> a;
    arr[a - 1]++;
  }
  for (i = 0; i < n; i++)
    cout << arr[i] << endl;
}

Error: 0

Fixed submission:

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

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

int main() {
  int N, i = 1, a[200000], l, j = 1, s[200000], k = 0, n = 0;
  cin >> N;
  s[0] = 0;
  while (cin >> l) {
    a[i] = l;
    s[i] = 0;
    i++;
  }
  while (j < N) {
    s[a[j] - 1] = s[a[j] - 1] + 1;
    j++;
  }
  while (k < N) {
    cout << s[k] << endl;
    k++;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int N, i = 1, a[200000], l, j = 0;
  cin >> N;
  while (cin >> l) {
    a[i] = l;
    i++;
  }
  while (j < N) {
    vector<int> v(a + j, a + N);
    size_t n_count = count(v.begin(), v.end(), j + 1);
    cout << n_count << endl;
    j++;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ARB                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
#define bp __builtin_popcount
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
const int maxn = 1e8 + 5;
const double EPS = 1e-14;
const int MOD = 1000000007;
int arr[maxn];
int fr[maxn] = {0};
int main() {
  ARB int n;
  cin >> n;
  for (int i = 1; i < n; i++)
    cin >> arr[i];
  for (int i = 1; i <= n; i++)
    fr[arr[i]]++;
  for (int i = 1; i <= n; i++)
    cout << fr[i] << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ARB                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
#define bp __builtin_popcount
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
const int maxn = 1e5 + 5;
const double EPS = 1e-14;
const int MOD = 1000000007;
int arr[maxn];
int fr[maxn] = {0};
int main() {
  ARB int n;
  cin >> n;
  for (int i = 1; i < n; i++)
    cin >> arr[i];
  for (int i = 1; i <= n; i++)
    fr[arr[i]]++;
  for (int i = 1; i <= n; i++)
    cout << fr[i] << endl;
}