prithivMLmods/Coder-Stat huggingface dataset:
Problem p02707 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

struct node {
  int num;
  int sco;
} b[200005];

int main() {
  int n, i, j;
  cin >> n;
  int a[n];

  for (i = 1; i <= n; i++)
    b[i].num = i;
  for (i = 1; i < n; i++)
    cin >> a[i];

  for (i = 1; i < n; i++)
    for (j = 1; j <= n; j++) {
      if (a[i] == b[j].num)
        b[j].sco++;
    }

  for (i = 1; i <= n; i++)
    cout << b[i].sco << endl;
  return 0;
}

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

struct node {
  int num;
  int sco;
} b[200005];

int main() {
  int n, i, j;
  cin >> n;
  int a[n];

  for (i = 1; i <= n; i++)
    b[i].num = i;
  for (i = 1; i < n; i++)
    cin >> a[i];

  for (i = 1; i < n; i++)
    b[a[i]].sco++;

  for (i = 1; i <= n; i++)
    cout << b[i].sco << endl;
  return 0;
}
Problem p02707 (C++)

Buggy submission (status: 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, 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;
}


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(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;
}
Problem p02707 (C++)

Buggy submission (status: 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, 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;
  }
}

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);
  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;
  }
}
Problem p02707 (C++)

Buggy submission (status: 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) { b[a.at(i) - 1] += 1; }

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

  return 0;
}


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 - 1) { b[a.at(i) - 1] += 1; }

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

  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#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;
  }
}

Fixed submission:
#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;
  }
}
Problem p02707 (C++)

Buggy submission (status: 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++) {
    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)); }
}

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++) {
    add.at(a.at(i) - 1)++;
  }
  rep(i, n) { printf("%d\n", add.at(i)); }
}
Problem p02707 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <bits/stdc++.h>

using namespace std;

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

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

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

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

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

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

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

Buggy submission (status: Runtime Error):
using namespace std;
#include <bits/stdc++.h>

int n, x;
int a[100005];

int main() {
  cin >> n;

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

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

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

int n, x;
int a[200005];

int main() {
  cin >> n;

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

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

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

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


Fixed submission:
#include <bits/stdc++.h>

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

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

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

Buggy submission (status: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
for i in range(1, N + 1):
    print(A.count(i))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

lis = [0] * N
for i in range(N - 1):
    lis[(A[i] - 1)] += 1

for i in range(N):
    print(lis[i])
Problem p02707 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    print(a.count(i + 1))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]

for i in a:
    b[i - 1] += 1

for i in b:
    print(i)
Problem p02707 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = []
for i in range(1, N + 1):
    print(A.count(i))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(N)]
for i in A:
    B[i - 1] += 1
for i in B:
    print(i)
Problem p02707 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
A_i = list(map(int, input().split()))
uq_A_i = list(set(A_i))
C = ["0\n"] * N
for i in uq_A_i:
    C[i - 1] = "{}".format(A_i.count(i)) + "\n"
print("".join(C))


Fixed submission:
N = int(input())
A_i = list(map(int, input().split()))
C = [0] * N
for i in A_i:
    C[i - 1] += 1
print(*C)
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

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

  cin >> n;

  p = new int(n);

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

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

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

  delete[] p;

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

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

  cin >> n;

  p = new int[n];

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

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

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

  delete[] p;

  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define repi(i, a, n) for (int i = (int)a; i < (int)(n); i++)
#define ll long long

int main(void) {
  int n;
  std::cin >> n;
  std::vector<int> num(100005, 0);

  rep(i, n - 1) {
    int t;
    std::cin >> t;
    num[t]++;
  }
  repi(i, 1, n + 1) { std::cout << num[i] << std::endl; }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define repi(i, a, n) for (int i = (int)a; i < (int)(n); i++)
#define ll long long

int main(void) {
  int n;
  std::cin >> n;
  std::vector<int> num(1000005, 0);

  rep(i, n - 1) {
    int t;
    std::cin >> t;
    num[t]++;
  }
  repi(i, 1, n + 1) { std::cout << num[i] << std::endl; }
}
Problem p02707 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC diagnostic error "-std=c++14"
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <cctype>
#include <cstdio>
using namespace std;
template <class code> inline code read(const code &a) {
  code x = 0;
  short w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return w ? -x : x;
}
void print(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x >= 10)
    print(x / 10);
  putchar(x % 10 + 48);
}
int a[200005];
int main() {
  int n = read(n);
  for (int i = 1; i <= n; i++) {
    int x = read(x);
    a[x]++;
  }
  for (int i = 1; i <= n; i++)
    printf("%d\n", a[i]);
  return 0;
}


Fixed submission:
#pragma GCC diagnostic error "-std=c++14"
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <cctype>
#include <cstdio>
using namespace std;
template <class code> inline code read(const code &a) {
  code x = 0;
  short w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return w ? -x : x;
}
void print(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x >= 10)
    print(x / 10);
  putchar(x % 10 + 48);
}
int a[200005];
int main() {
  int n = read(n);
  for (int i = 1; i <= n - 1; i++) {
    int x = read(x);
    a[x]++;
  }
  for (int i = 1; i <= n; i++)
    printf("%d\n", a[i]);
  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  a[0] = 0;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  sort(ALL(a));
  vector<int> ans(n + 1);
  ans[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    ans[i] = count(a.begin() + ans[i - 1], a.end(), i);
  }
  rep(i, n) { cout << ans[i + 1] << endl; }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  a[0] = 0;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  sort(ALL(a));
  vector<int> ans(n + 1);
  ans[0] = 0;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = sum; j <= n; j++) {
      if (a[j + 1] != i) {
        ans[i] = j - sum;
        sum = j;
        break;
      }
    }
  }
  rep(i, n) { cout << ans[i + 1] << endl; }
  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

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

  vector<int> vec1(N - 1);
  vector<int> vec2(N);

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

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

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

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

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

  vector<int> vec1(N - 1);
  vector<int> vec2(N);

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

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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

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

  int ans[200001];
  for (int i = 1; i <= N; i++) {
    for (int j = 2; j <= N; j++) {
      if (A[j] == i) {
        ans[i]++;
      }
    }
  }

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

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

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

  int ans[200001];
  for (int j = 2; j <= N; j++) {
    ans[A[j]]++;
  }

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

  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main(void) {

  int A[20001] = {0};
  int N;
  int chk;
  cin >> N;

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

  return 0;
}

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

  int A[200001] = {0};
  int N;
  int chk;
  cin >> N;

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

  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define PI 3.141592653
int main() {
  ll arr[20002] = {0};
  ll n;
  cin >> n;
  rep(i, 1, n) {
    ll ch;
    cin >> ch;
    arr[ch] += 1;
  }
  rep(i, 1, n + 1) cout << arr[i] << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define PI 3.141592653
int main() {
  ll arr[200002] = {0};
  ll n;
  cin >> n;
  rep(i, 1, n) {
    ll ch;
    cin >> ch;
    arr[ch] += 1;
  }
  rep(i, 1, n + 1) cout << arr[i] << "\n";
  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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


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

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

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

  for (int i = 0; i < n; i++) {
    cout << B.at(i) << endl;
  }
}
Problem p02707 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

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

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

  vector<long long> B(n, 0);

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

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

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

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

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

  vector<long long> B(n, 0);

  for (int i = 0; i < n - 1; i++) {
    B.at(A.at(i) - 1)++;
  }

  for (int i = 0; i < n; i++) {
    cout << B.at(i) << endl;
  }
}
Problem p02707 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

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

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

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

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == A[j])
        a[i]++;
    }
  }

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

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

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

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

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

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

  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

const int mN = 100100;
int c[mN];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 2, a; i <= n; i++)
    cin >> a, c[a]++;
  for (int i = 1; i <= n; i++)
    cout << c[i] << " ";
}

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

const int mN = 200200;
int c[mN];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 2, a; i <= n; i++)
    cin >> a, c[a]++;
  for (int i = 1; i <= n; i++)
    cout << c[i] << " ";
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 2; i <= (int)(n); i++)

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

  rep(i, N) {
    cin >> A[i];

    dp[A[i]]++;
  }

  for (int i = 1; i <= N; ++i)
    cout << dp[i] << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 2; i <= (int)(n); i++)

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

  rep(i, N) {
    cin >> A[i];

    dp[A[i]]++;
  }

  for (int i = 1; i <= N; ++i)
    cout << dp[i] << endl;

  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
#define mes(a, b) memset(a, b, sizeof a)
#define pb push_back
typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 1e5 + 20;
const int maxm = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
int has[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int v;
    cin >> v;
    has[v]++;
  }
  for (int i = 1; i <= n; i++)
    printf("%d\n", has[i]);
}

Fixed submission:

#include <bits/stdc++.h>
#define mes(a, b) memset(a, b, sizeof a)
#define pb push_back
typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 2e5 + 20;
const int maxm = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
int has[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int v;
    cin >> v;
    has[v]++;
  }
  for (int i = 1; i <= n; i++)
    printf("%d\n", has[i]);
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
//**PEACE BE UPON YOU**
// AZMAYEN FAYEK SABIL
// IUT CSE SWE-19

#include <bits/stdc++.h>
#include <iostream>

#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int main()

{
  int n;
  cin >> n;

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

  int i;

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

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

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

  return 0;
}


Fixed submission:
//**PEACE BE UPON YOU**
// AZMAYEN FAYEK SABIL
// IUT CSE SWE-19

#include <bits/stdc++.h>
#include <iostream>

#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int main()

{
  int n;
  cin >> n;

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

  int i;

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

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

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

  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n + 1);
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n + 1; i++) {
    int cnt = 0;
    for (int j = 1; j < n + 1; j++) {
      if (i == a[j]) {
        cnt++;
        b[a[j]] = cnt;
      }
    }
  }
  for (int i = 1; i < n + 1; i++)
    cout << b[i] << endl;
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n + 1);
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (int i = 1; i < n + 1; i++)
    cout << b[i] << endl;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n;
  cin >> n;
  long long int a[n];
  vector<long long int> v(n + 1, 0);
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    v[a[i]] += 1;
  }
  for (long long int i = 1; i < n + 1; i++)
    cout << v[i] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n;
  cin >> n;
  long long int a[n];
  vector<long long int> v(n + 1, 0);
  for (long long int i = 0; i < n - 1; i++) {
    cin >> a[i];
    v[a[i]] += 1;
  }
  for (long long int i = 1; i < n + 1; i++)
    cout << v[i] << endl;
  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;

int freq[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    freq[x]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << freq[i] << '\n';
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

int freq[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    freq[x]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << freq[i] << '\n';
  }

  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (i = a; i < n; i++)
#define per(i, a, n) for (i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE 1000001
#define ONLINE_JUDGE
#define rd
#define PI acos(-1)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
auto clk = clock();
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int main() {

  int i, n, freq[100005];
  memset(freq, 0, sizeof(freq));
  cin >> n;
  rep(i, 1, n) {
    int x;
    cin >> x;
    freq[x - 1]++;
  }
  rep(i, 0, n) cout << freq[i] << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (i = a; i < n; i++)
#define per(i, a, n) for (i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE 1000001
#define ONLINE_JUDGE
#define rd
#define PI acos(-1)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
auto clk = clock();
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int main() {

  int i, n, freq[200005];
  memset(freq, 0, sizeof(freq));
  cin >> n;
  rep(i, 1, n) {
    int x;
    cin >> x;
    freq[x - 1]++;
  }
  rep(i, 0, n) cout << freq[i] << "\n";
  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <map>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  vector<int> cnt(n, 0);
  for (int i = 1; i < n; i++)
    cin >> a[i];

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

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

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <map>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> cnt(n, 0);
  for (int i = 1; i < n; i++)
    cin >> a[i];

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

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

  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int ar[100000] = {0};
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int temp;
    cin >> temp;
    ++ar[temp];
  }
  for (int i = 1; i <= n; i++) {
    printf("%d\n", ar[i]);
  }
}

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

int main() {
  int ar[1000000] = {0};
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int temp;
    cin >> temp;
    ++ar[temp];
  }
  for (int i = 1; i <= n; i++) {
    printf("%d\n", ar[i]);
  }
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;

int n, m, a;
string s, t;
int ans[100005];

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;

int n, m, a;
string s, t;
int ans[200005];

int main() {
  cin >> n;
  rep(i, n - 1) cin >> a, ans[a - 1]++;
  rep(i, n) cout << ans[i] << endl;
}
Problem p02707 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

result = [0] * N
for a in A:
    result[a - 1] += 1
print("\n".join(result))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

result = [0] * N
for a in A:
    result[a - 1] += 1
print("\n".join(map(str, result)))
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int mp[100200];
int s[100200];
int main() {
  int a, i;
  cin >> a;
  for (i = 2; i <= a; i++) {
    cin >> s[i];
    mp[s[i]]++;
  }
  for (i = 1; i <= a; i++) {
    cout << mp[i] << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int mp[1000200];
int s[1000200];
int main() {
  int a, i;
  cin >> a;
  for (i = 2; i <= a; i++) {
    cin >> s[i];
    mp[s[i]]++;
  }
  for (i = 1; i <= a; i++) {
    cout << mp[i] << endl;
  }
  return 0;
}
Problem p02707 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    print(a.count(i + 1))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
result = [0] * n
for x in a:
    result[x - 1] += 1
for v in result:
    print(v)
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int ara[21000];
int main() {

  int n, x, i;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> x;
    ara[x]++;
  }
  for (i = 1; i <= n; i++) {
    cout << ara[i] << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int ara[210000];
int main() {

  int n, x, i;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> x;
    ara[x]++;
  }
  for (i = 1; i <= n; i++) {
    cout << ara[i] << endl;
  }
}
Problem p02707 (C++)

Buggy submission (status: 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);
  rep(i, n - 1) cin >> a[i];
  vector<int> b(n, 0);
  rep(i, n - 1) rep(j, n) {
    if (a[i] == j + 1)
      b[j]++;
  }
  rep(i, n) cout << b[i] << endl;
}

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);
  rep(i, n - 1) cin >> a[i];
  vector<int> b(n, 0);
  int cnt = 0;
  rep(i, n - 1) { b[a[i] - 1]++; }
  rep(i, n) cout << b[i] << endl;
}
Problem p02707 (C++)

Buggy submission (status: 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[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;
}


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[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;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#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;
}


Fixed submission:
#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;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  int a[n], b[100005] = {0};
  for (i = 0; i < n - 1; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (i = 0; i < n; i++) {
    cout << b[i + 1] << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  int a[n], b[200005] = {0};
  for (i = 0; i < n - 1; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (i = 0; i < n; i++) {
    cout << b[i + 1] << endl;
  }
  return 0;
}
Problem p02707 (C++)

Buggy submission (status: 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++) {
    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;
}

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++){
(*_*; これでもできるが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;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int a, n, boss[maxn] = {0};
int main() {
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> a;
    boss[a]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << boss[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1e5 + 5;
int a, n, boss[maxn] = {0};
int main() {
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> a;
    boss[a]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << boss[i] << endl;
  }
  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
int s[100006];
int q[100006] = {0};
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> s[i];
    q[s[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << q[i] << endl;
  }
}

Fixed submission:
#include <iostream>
int s[200006];
int q[200006] = {0};
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> s[i];
    q[s[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << q[i] << endl;
  }
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MAX 1000000007
#define ll long long int
#define fo(i, n) for (int i = 0; i < n; i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //    int t;
  //    cin>>t;
  int x = 1;
  //    while(t--) {
  int n;
  cin >> n;
  int a[n - 1];
  fo(i, n - 1) { cin >> a[i]; }
  int arr[100001] = {0};
  for (int o : a) {
    arr[o]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << arr[i] << endl;
  }

  x++;
  //    }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define MAX 1000000007
#define ll long long int
#define fo(i, n) for (int i = 0; i < n; i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //    int t;
  //    cin>>t;
  int x = 1;
  //    while(t--) {
  int n;
  cin >> n;
  int a[n - 1];
  fo(i, n - 1) { cin >> a[i]; }
  int arr[200001] = {0};
  for (int o : a) {
    arr[o]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << arr[i] << endl;
  }

  x++;
  //    }
  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union {
  vector<ll> par;
  Union(ll a) { par = vector<ll>(a, -1); }
  ll find(ll a) {
    if (par[a] < 0) {
      return a;
    } else {
      return par[a] = find(par[a]);
    }
  }
  bool same(ll a, ll b) { return (find(a) == find(b)); }
  ll size(ll a) { return -par[find(a)]; }
  void unite(ll a, ll b) {
    ll c = find(a), d = find(b);
    if (c == d)
      return;
    if (size(c) < size(d)) {
      swap(c, d);
    }
    par[c] += par[d];
    par[d] = c;
  }
};

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union {
  vector<ll> par;
  Union(ll a) { par = vector<ll>(a, -1); }
  ll find(ll a) {
    if (par[a] < 0) {
      return a;
    } else {
      return par[a] = find(par[a]);
    }
  }
  bool same(ll a, ll b) { return (find(a) == find(b)); }
  ll size(ll a) { return -par[find(a)]; }
  void unite(ll a, ll b) {
    ll c = find(a), d = find(b);
    if (c == d)
      return;
    if (size(c) < size(d)) {
      swap(c, d);
    }
    par[c] += par[d];
    par[d] = c;
  }
};

int main() {
  ll n;
  cin >> n;
  ll a[n], b[n + 1];
  for (ll i = 0; i < n + 1; i++)
    b[i] = 0;
  for (ll i = 0; i < n - 1; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (ll i = 1; i <= n; i++) {
    cout << b[i] << endl;
  }
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int n, tmp;
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> tmp;
    arr[tmp]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << arr[i] << "\n";
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int arr[200005];
int n, tmp;
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> tmp;
    arr[tmp]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << arr[i] << "\n";
  }
  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int arr[100000];
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n - 1; i++)
    cin >> a[i];
  for (int i = 0; i < n - 1; i++)
    arr[a[i]]++;
  for (int i = 1; i <= n; i++)
    cout << arr[i] << endl;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int arr[200000];
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n - 1; i++)
    cin >> a[i];
  for (int i = 0; i < n - 1; i++)
    arr[a[i]]++;
  for (int i = 1; i <= n; i++)
    cout << arr[i] << endl;
  return 0;
}
Problem p02707 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {

  int N;
  cin >> N;

  long long A[N], subord[N];

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

  for (int j = 0; j < N - 1; j++) {
    for (int m = 0; m < N; m++) {
      if (j == A[m] - 1) {
        subord[j]++;
      }
    }
  }
  for (int n = 0; n < N - 1; n++) {
    cout << subord[n] << endl;
  }
  cout << 0 << endl;
}

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

int main() {

  int N;
  cin >> N;

  long long A[N], subord[N];

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

  for (int j = 0; j < N - 1; j++) {
    subord[A[j] - 1]++;
  }
  for (int n = 0; n < N - 1; n++) {
    cout << subord[n] << endl;
  }
  cout << 0 << endl;
}
Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  long long N, M, value;
  cin >> N;
  vector<int> count;
  for (int i = 0; i < N - 1; i++) {
    cin >> value;
    count[value - 1]++;
  }
  for (int i = 0; i < N; i++)
    cout << count[i] << ' ';
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  long long N, M, value;
  cin >> N;
  vector<int> count(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> value;
    count[value - 1]++;
  }
  for (int i = 0; i < N; i++)
    cout << count[i] << ' ';
}
Problem p02707 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

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

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

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

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

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