alexjercan/bugnet huggingface dataset:
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define FRU freopen("out.txt", "w", stdout);
#define FRO freopen("in.txt", "r", stdin);
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define mp make_pair
#define ff first
#define ss second
#define flash                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define mem(ara, n) memset(ara, n, sizeof ara)
#define fr(i, j, n) for (i = j; i < n; i++)
#define rf(i, j, n) for (i = n; i >= j; i--)
#define inf 2147483647
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define vch vector<char>
#define itr ::iterator
#define msi map<string, int>
#define psi pair<string, int>
#define vii vector<pair<int, int>>
#define all(n) n.begin(), n.end()
#define INF 10000000000000000LL
#define pi 3.1415926535897932384626434
#define sii set<int>
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mid3(a, b, c) min(max(a, b), max(b, c), max(a, b))
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define endl '\\n'
#define endll cout << "\\n";
#define spc ' '
#define ld long double

using namespace std;

int main() {
  flash string s, st;
  int n, t, T, i, j, J, I, k, m;
  char ch;
  cin >> n;
  int boss[200005] = {0};
  fr(i, 1, n) {
    cin >> m;
    boss[m]++;
  }
  fr(i, 1, n + 1) cout << boss[i] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

#include <cstring>
#include <iostream>
#include <set>

using namespace std;

int arr[200005];

int main() {
  int n, a;
  while (cin >> n) {
    memset(arr, 0, sizeof(arr));
    n--;
    for (int i = 0; i < n; i++) {
      cin >> a;
      arr[a]++;
    }
    for (int i = 1; i <= n + 1; i++)
      cout << arr[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, arr[200000], c = 0, k = 1;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    for (int i = 1; i <= n - 1; i++) {
      if (arr[i - 1] == k) {
        c++;
      }
    }
    if (k < n) {
      k++;
    }
    cout << c << endl;
    c = 0;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int A[200001];
int main() {
  map<int, int> mp;

  int i, n;
  cin >> n;
  for (i = 0; i < (n - 1); i++) {
    cin >> A[i];
    mp[A[i]]++;
  }
  for (i = 1; i <= n; i++) {
    cout << mp[i] << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int arr[2 * 100000];
  int cnta[2 * 100000] = {0};
  for (int i = 0; i < n - 1; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int cnt = 0;
    int a = arr[i];
    for (int j = 0; j < n - 1; j++) {
      if (arr[j] != 0) {
        if (arr[j] == a) {
          cnt++;
          arr[j] = 0;
        }
      }
    }
    if (a != 0)
      cnta[a - 1] = cnt;
  }
  for (int i = 0; i < n; i++) {
    cout << cnta[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long num;
  while (cin >> num) {
    long long arr[num + 5], count[num + 5] = {0};
    for (long long i = 0; i < num - 1; i++) {
      cin >> arr[i];
      count[arr[i]]++;
    }
    for (long long i = 1; i <= num; i++) {
      cout << count[i] << endl;
    }
    break;
  }
}


Error: -7

Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  ll i;
  ll arr[n];
  ll p[200001] = {0};
  for (i = 0; i < n - 1; i++)
    cin >> arr[i];
  for (i = 0; i < n; i++) {
    p[arr[i]]++;
  }
  for (i = 1; i <= n; i++)
    cout << p[i] << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int A[200005];
int main() {
  int N, M;
  cin >> N;
  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;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int A[100005];
int main() {
  int N, M;
  cin >> N;
  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;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
using namespace std;

int main(int argc, char *argv[]) {
  int N;
  int A;

  scanf("%d", &N);
  int count[200005] = {};

  for (int i = 1; i < N; i++) {
    scanf("%d", &A);
    count[A]++;
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
using namespace std;

int main(int argc, char *argv[]) {

  int N;
  int A[300000] = {};

  scanf("%d", &N);
  int count[300000] = {};

  for (int i = 1; i < N; i++) {
    scanf("%d", &A[i]);
  }

  for (int i = 1; i < N + 1; i++) {
    for (int j = i; j < N; j++) {
      if (A[j] == i) {
        count[i]++;
        //				printf("y\\n");
      }
    }
  }

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

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

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

using namespace std;

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

  vector<int> numOfTeam(N, 0);
  for (int i = 1; i < N; ++i) {
    int boss = A[i] - 1;
    numOfTeam[boss] += 1;
  }

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


Error: -6
double free or corruption (out)


Fixed submission:

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

using namespace std;

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

  vector<int> numOfTeam(N, 0);
  for (int i = 0; i < N; ++i) {
    int boss = A[i] - 1;
    numOfTeam[boss] += 1;
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long num;
  while (cin >> num) {
    long long arr[num + 5], count[num + 5] = {0};
    for (long long i = 0; i < num - 1; i++) {
      cin >> arr[i];
      count[arr[i]]++;
    }
    for (long long i = 1; i <= num; i++) {
      cout << count[i] << endl;
    }
    break;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int num;
  while (cin >> num) {
    int arr[1000], count[100005] = {0};
    for (int i = 0; i < num - 1; i++) {
      cin >> arr[i];
      count[arr[i]]++;
    }
    for (int i = 1; i <= num; i++) {
      cout << count[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++)
using namespace std;
using ll = long long;

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

  rep(i, n) b[i] = 0;
  sort(a.begin(), a.end());
  rep(i, n) {

    while (a[x] == i + 1) {
      x++;
      b[i]++;
    }
  }
  rep(i, n) cout << b[i] << endl;
  return 0;
}


Error: -11

Fixed submission:

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

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

  rep(i, n) b[i] = 0;
  sort(a.begin(), a.end());
  rep(i, n) {

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

Error: TLE

Fixed submission:

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

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

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, a;
  vector<int> A = vector<int>();
  cin >> N;
  vector<int> B = vector<int>(N, 0);
  A.push_back(0);
  for (int i = 0; i < N - 1; i++) {
    cin >> a;
    A.push_back(a);
  }
  for (int i = 1; i < N; i++) {
    if (A[i] != 0) {
      B[A[i] - 1] += 1;
    }
  }
  for (int i : B) {
    cout << i << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, a;
  vector<int> A = vector<int>();
  vector<int> B = vector<int>(5, 0);
  cin >> N;
  A.push_back(0);
  for (int i = 0; i < N - 1; i++) {
    cin >> a;
    A.push_back(a);
  }
  for (int i = 1; i < N; i++) {
    if (A[i] != 0) {
      B[A[i] - 1] += 1;
    }
  }
  for (int i : B) {
    cout << i << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

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

  rep(i, n - 1) { b[a.at(i) - 1] += 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;
// typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
// define
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)

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

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

  rep(i, n) cout << b[i] << endl;

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

#include <iostream>
using namespace std;

int main(void) {
  int N;

  cin >> N;

  int a[200001] = {0};
  int c[200001] = {0};

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

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

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int N;

  cin >> N;

  int a[20000] = {0};
  int c[20000] = {0};

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

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

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n - 1), b(n, 0);
  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;
  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n), b(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    b[a[i] - 1]++;
  }
  for (int i = 0; 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() {
  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);
  }
  for (int i = 0; i < N; i++) {
    B.at(i) = 0;
  }
  for (int i = 0; i < N - 1; i++) {
    int n;
    n = A.at(i);
    B.at(n - 1) += 1;
  }
  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> A(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
  }
  for (int i = -1; i < N - 1; i++) {
    int x = 0;
    if (i == N - 2) {
      cout << 0 << endl;
    } else {
      for (int j = i + 1; j < N - 1; j++) {
        if (A.at(j) == i + 2) {
          x++;
        }
      }
      cout << x << endl;
    }
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main(void) {

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

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


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {

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

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


//     THE ONLY WAY IS UP

#include <bits/stdc++.h>

#define ll long long int
#define ld long double
#define f1(i, a, b) for (ll i = a; i < b; i++)
#define f2(a, b) for (auto a : b)
#define ar(v, i) v[i]
#define ar_(v, i, j) v[i][j]
#define in_(x)                                                                 \\
  ll x;                                                                        \\
  cin >> x;
#define ino_(type, x)                                                          \\
  type x;                                                                      \\
  cin >> x;
#define pb push_back
#define nl "\\n"
#define tcase(t)                                                               \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  f1(z, 0, t)
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  in_(n) map<ll, ll> map;
  f1(i, 0, n - 1) {
    in_(x);
    map[x]++;
  }
  ll i = 1;
  f2(x, map) {
    while (true) {
      if (x.first == i) {
        cout << x.second << nl;
        i++;
        break;
      } else {
        cout << "0" << nl;
        i++;
      }
    }
  }
  f1(j, i, n + 1) cout << "0" << nl;
}


Error: TLE

Fixed submission:


//     THE ONLY WAY IS UP

#include <bits/stdc++.h>

#define ll long long int
#define ld long double
#define f1(i, a, b) for (ll i = a; i < b; i++)
#define f2(a, b) for (auto a : b)
#define ar(v, i) v[i]
#define ar_(v, i, j) v[i][j]
#define in_(x)                                                                 \\
  ll x;                                                                        \\
  cin >> x;
#define ino_(type, x)                                                          \\
  type x;                                                                      \\
  cin >> x;
#define pb push_back
#define nl "\\n"
#define tcase(t)                                                               \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  f1(z, 0, t)
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  in_(n) map<ll, ll> map;
  f1(i, 0, n - 1) {
    in_(x);
    map[x]++;
  }
  f1(i, 1, n + 1) {
    ll flag = 0;
    f2(x, map) {
      if (x.first == i) {
        cout << x.second << nl;
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      cout << "0" << nl;
    }
  }
}
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);
  for (int i = 0; i < n; i++) {
    a[i] = 0;
  }
  for (int i = 0; i < n - 1; i++) {
    int m;
    cin >> m;
    a[m - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << endl;
  }
}


Error: WA

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  for (int i = 0; i < n; i++) {
    a[i] = 0;
  }
  for (int i = 1; i < n - 1; i++) {
    int m;
    cin >> m;
    a[m - 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>
using namespace std;
using ll = long long;
ll a, b, c, i, j, k, l, m, n, ans, tmp, hoge, fuga, piyo;
ll x[200100], y[200100];
string s, str;
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n - 1; i++) {
    if (x[i] <= i + 1)
      y[x[i] - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << y[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a, b, c, i, j, k, l, m, n, ans, tmp, hoge, fuga, piyo;
ll x[200100], y[10010];
string s, str;
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n; i++) {
    cout << count(x + i, x + n, i + 1) << endl;
  }
  return 0;
}
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)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> add(n);
  rep(i, n - 1) { cin >> a.at(i + 1); }
  a.at(0) = 0;
  for (int i = 1; i < n; i++) {
    add.at(a.at(i) - 1)++;
  }
  rep(i, n) { printf("%d\\n", add.at(i)); }
}

Error: TLE

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> add(n);
  rep(i, n - 1) { cin >> a.at(i + 1); }
  a.at(0) = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a.at(i) == j) {
        add.at(j - 1)++;
      }
    }
  }
  rep(i, n) { printf("%d\\n", add.at(i)); }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <math.h>
#define pi acos(-1)
using namespace std;
typedef long long ll;
typedef long double ld;
ll x[200020], ans[200020];
int main()

{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  ll n;
  cin >> n;
  ll i;
  for (i = 2; i <= n; i++)
    cin >> x[i];
  for (i = 2; i <= n; i++) {
    ans[x[i]]++;
  }
  for (i = 1; i <= n; i++)
    cout << ans[i] << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
#define pi acos(-1)
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  ll n;
  cin >> n;
  ll x[100000], ans[100000];
  ll i;
  for (i = 2; i <= n; i++)
    cin >> x[i];
  for (i = 2; i <= n; i++) {
    ans[x[i]]++;
  }
  for (i = 1; i <= n; i++)
    cout << ans[i] << endl;

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

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

  vector<int> a;
  int temp;

  for (int i = 0; i < 200000; i++) {
    a.push_back(0);
  }

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

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

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> a;
    int temp;

    for (int i = 0; i < 20000; i++) {
        a.push_back(0);
    }

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

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




    return 0;
}*/

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

  vector<int> a;
  int temp;

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

  for (int i = 0; i < n; i++) {
    cout << count(a.begin(), a.end(), i + 1) << "\\n";
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main() {
  int g[200100] = {};
  int n;
  cin >> n;

  rep(i, n - 1) {
    int a;
    cin >> a;
    g[a]++;
  }

  repi(i, 1, n + 1) { cout << g[i] << endl; }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main() {
  int g[100100] = {};
  int n;
  cin >> n;

  rep(i, n - 1) {
    int a;
    cin >> a;
    g[a]++;
  }

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

#include <stdio.h>

int main(void) {
  long int n;
  int i;
  int a[200001];
  int sum[200001] = {0};

  do {
    scanf("%ld", &n);
  } while (n < 2 || n > 200000);

  for (i = 2; i <= n; i++) {
    do {
      scanf("%d ", &a[i]);
    } while (a[i] < 1 || a[i] >= i);
    sum[a[i]]++;
  }
  for (i = 1; i <= n; i++)
    printf("%d\\n", sum[i]);

  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>

int main(void) {
  long int n;
  int i;
  int a[100000];

  do {
    scanf("%ld", &n);
  } while (n < 2 || n > 200000);

  int sum[n];

  for (i = 1; i <= n; i++)
    sum[i] = 0;

  for (i = 2; i <= n; i++) {
    do {
      scanf("%d ", &a[i]);
    } while (a[i] < 1 || a[i] >= i);
    sum[a[i]]++;
  }
  for (i = 1; i <= n; i++)
    printf("%d\\n", sum[i]);

  return 0;
}