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

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

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

Error: -6
double free or corruption (out)


Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  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;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;
int main() {

  int S[200000] = {0};
  int M;
  int W;
  cin >> M;

  for (int i = 0; i < M - 1; i++) {
    cin >> W;
    S[W - 1]++;
  }
  cout << "";
  for (int i = 0; i < M; i++) {
    cout << S[i] << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

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

using namespace std;
int main() {

  int S[100000] = {0};
  int M;
  int W;
  cin >> M;

  for (int i = 0; i < M - 1; i++) {
    cin >> W;
    S[W - 1]++;
  }
  cout << "";
  for (int i = 0; i < M; i++) {
    cout << S[i] << "\\n";
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (ll i = 0; i < n; i++)

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

  rep(i, n) { cout << a[i] << "\\n"; }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (ll i = 0; i < n; i++)

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n - 1);
  rep(i, n - 1) cin >> a[i];
  vector<ll> b(n, 0);
  rep(i, n - 1) { b[i] = count(a.begin(), a.end(), i + 1); }

  rep(i, n) { cout << b[i] << "\\n"; }

  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> ans(N);
  for (int i = 0; i < N - 1; i++) {
    int a;
    cin >> a;
    ans.at(a - 1) += 1;
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

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

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

int buka[2 * pow10(5)];

void solve() {
  int N;
  cin >> N;

  FOR(i, 2, N + 1) {
    int a;
    cin >> a;
    buka[a]++;
  }

  REP1(i, N) { std::cout << buka[i] << endl; }
}

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  solve();
  return 0;
}


Error: 0

Fixed submission:

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

int buka[pow10(5)];

void solve() {
  int N;
  cin >> N;

  FOR(i, 2, N + 1) {
    int a;
    cin >> a;
    buka[a]++;
  }

  REP1(i, N) { std::cout << buka[i] << endl; }
}

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  solve();
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define MAX 10000000
int arr[MAX];
int ans[MAX];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  //  int arr[n];

  for (int i = 1; i <= n - 1; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= n - 1; i++) {
    // if(arr[i]==)
    ans[arr[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:


#include <bits/stdc++.h>
using namespace std;
#define MAX 10000000
int arr[MAX];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  //  int arr[n];

  for (int i = 1; i <= n - 1; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= n; i++) {
    int count = 0;
    for (int j = 1; j <= n; j++) {
      if (arr[j] == i) {
        count++;
      }
    }
    cout << count << endl;
  }

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

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long
using namespace std;
int main() {
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i, n - 1) {
    int a;
    cin >> a;
    vec[a - 1]++;
  }
  rep(i, n) { cout << vec[i] << endl; }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long
using namespace std;
int main() {
  ll n;
  cin >> n;
  vector<ll> vec(n);
  vec[0] = 0;
  for (ll i = 1; i < n; i++) {
    cin >> vec[i];
  }
  vector<ll> vec2(n);
  for (ll i = 1; i < n + 1; i++) {
    vec2[i] = count(vec.begin(), vec.end(), i);
    cout << vec2[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPM(i, n) for (ll i = (n - 1); 0 = < i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());
#define V_SORT_D(x) sort(x.begin(), x.end(), greater<int>());
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);

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

  VL A_i(N - 1); // 2-N

  REP(i, N - 1) { cin >> A_i.at(i); }

  ll count = 0;
  ll match = 1;
  ll nokori = N;

  V_SORT_U(A_i);

  REP(i, N - 1) {
    if (A_i.at(i) == match) {
      count++;
      if (i == N - 2) {
        cout << count << endl;
        nokori--;
        break;
      }

    } else {
      cout << count << endl;
      match = A_i.at(i);
      if (match > (A_i.at(i - 1) + 1)) {
        // 2以上大きかったら間を埋める
        REP(j, (match - A_i.at(i - 1) - 1)) {
          cout << 0 << endl;
          nokori--;
        }
      }

      nokori--;
      count = 1;
      if (i == N - 2) {
        cout << count << endl;
        nokori--;
        break;
      }
    }
  }

  REP(i, nokori) { cout << 0 << endl; }

  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPM(i, n) for (ll i = (n - 1); 0 = < i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());
#define V_SORT_D(x) sort(x.begin(), x.end(), greater<int>());
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);

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

  VL A_i(N + 1);

  REP(i, N - 1) { cin >> A_i.at(i + 1); }

  A_i.at(0) = 1;

  for (ll i = 1; i < N + 1; i++) {
    int count = 0;
    for (ll j = i; j < N; j++) {
      if (A_i.at(j) == i)
        count++;
    }

    cout << count << endl;
  }

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

// In the name of God
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  unordered_map<long long int, long long int> mp;
  for (long long int i = 0; i < (n - 1); i++) {
    long long int k;
    cin >> k;
    mp[k]++;
  }
  for (int i = 1; i <= n; i++)
    cout << mp[i] << "\\n";
}

Error: TLE

Fixed submission:

// In the name of God
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  vector<long long int> vec;
  for (int i = 0; i < (n - 1); i++) {
    long long int k;
    cin >> k;
    vec.push_back(k);
  }
  for (int i = 1; i <= n; i++)
    cout << count(vec.begin(), vec.end(), i) << "\\n";
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <deque>         // deque
#include <iostream>      // cout, endl, cin
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> syainn(N);
  vector<int> buka(N, 0);
  syainn.at(0) = 0;
  for (int i = 1; i < N; i++) {
    cin >> syainn.at(i);
  }
  int count = 0;
  for (int i = 1; i < N; i++) {
    buka.at(syainn.at(i) - 1) += 1;
  }
  for (int i = 0; i < N; i++) {
    cout << buka.at(i) << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <deque>         // deque
#include <iostream>      // cout, endl, cin
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < ll(b); i++)
#define repr(i, a, b) for (ll i = a; i >= ll(b); i--)
#define endl "\\n"
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define INF 1e9
#define DEBUG(x) cout << "debug: " << x << endl
using namespace std;

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


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < ll(b); i++)
#define repr(i, a, b) for (ll i = a; i >= ll(b); i--)
#define endl "\\n"
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define INF 1e9
#define DEBUG(x) cout << "debug: " << x << endl
using namespace std;

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

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

int main(void) {
  int n, m;
  cin >> n;
  // cin>>m;
  int a[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    a[i] = 0;
  }

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

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

Error: TLE

Fixed submission:

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

int main(void) {
  int n, m;
  cin >> n;
  // cin>>m;
  int a[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    a[i] = 0;
  }

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

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

#include <bits/stdc++.h>
#define ll long long;
#define dbg(x) cout << #x << "--------------" << x << endl;
#define dl cout << "LINE" << __LINE__ << endl;
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n;
  int a[999999];
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << a[i] << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long;
#define dbg(x) cout << #x << "--------------" << x << endl;
#define dl cout << "LINE" << __LINE__ << endl;
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n;
  int a[9999];
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << a[i] << endl;
  }

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

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> vec.at(i);
  }
  vector<int> ans(n, 0);
  for (int i = 0; i < n - 1; i++) {
    ans.at(vec.at(i) - 1)++;
  }
  cout << ans.at(0);
  for (int i = 1; i < n; i++) {
    cout << endl << ans.at(i);
  }
}

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 <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> vec.at(i);
  }
  vector<int> ans(n, 0);
  for (int i = 0; i < n - 1; i++) {
    ans.at(vec.at(i) - 1)++;
  }
  // cout << ans.at(0);
  for (int i = 0; i <= n; i++) {
    cout << ans.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long n;
  cin >> n;
  vector<long long> nums;
  nums.push_back(0);
  for (long long i = 1; i < n; i++) {
    nums.push_back(0);
    long long a;
    cin >> a;
    nums[a - 1]++;
  }
  for (long long i = 0; i < n; i++) {
    cout << nums[i] << endl;
  }
}

Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  long n;
  cin >> n;
  vector<long> nums;
  for (long i = 0; i < n; i++) {
    nums.push_back(0);
    long a;
    cin >> a;
    nums[a - 1]++;
  }
  for (long i = 0; i < n; i++) {
    if (nums[i + 1] == 0) {
      if (nums[i] == 0) {
        cout << nums[i] << endl;
      } else {
        cout << nums[i] - 1 << endl;
      }
    } else {
      cout << nums[i] << endl;
    }
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  int A[N]{};
  for (int i = 1; i < N; i++) {
    cin >> A[i];
  }
  int b[N]{};
  for (int i = 1; i < N; i++) {
    b[A[i] - 1]++;
  }
  for (int i : b) {
    cout << i << "\\n";
  }
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  vector<int> s;
  int n, i, j, count = 0;

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

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

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

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

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

  sort(A.begin(), A.end());

  vector<int> ans(N);

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

    cout << ans.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

#define rep(i, N) for (int i = 0; i < N; i++)
#define ll long long

using namespace std;

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

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

  for (int x : ans) {
    cout << x << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"

#define rep(i, N) for (int i = 0; i < N; i++)
#define ll long long

using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<vector<bool>> adj(N, vector<bool>(N, false));

  rep(i, N - 1) {
    int a;
    cin >> a;
    a--;
    adj[i + 1][a] = true;
  }
  rep(i, N) {
    int cnt = 0;
    rep(j, N) { cnt += (int)(adj[j][i]); }
    cout << cnt << 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;
  int a;

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

  for (int i = 0; i < N; i++) {
    cout << A.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);
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N - 1; j++) {
      if (i == A.at(j) - 1) {
        count++;
      }
    }
    cout << count << endl;
    count = 0;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int buf;
  int ans[200000] = {0};
  for (int i = 1; i <= n - 1; i++) {
    cin >> buf;
    ans[buf - 1]++;
  }
  for (int i = 0; i < n - 1; i++) {
    cout << ans[i] << endl;
  }
  cout << 0 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n;
  int *a;
  int *ans;
  cin >> n;
  a = new int[n - 1];
  ans = new int[n];
  for (int i = 0; i <= n - 2; i++) {
    cin >> a[i];
    ans[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < n - 1; j++) {
      if (a[j] == i) {
        ans[i - 1]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }

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

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
vector<ll> to[200005];
vector<ll> memo(200005);
vector<ll> done(200005);
ll dp(int v, int p = -1) {
  if (done[v] == 1) {
    return memo[v];
  }

  // ll max1 = -1;
  // ll min1 = 1000000000;
  ll g = 0;
  for (ll x : to[v]) {
    if (x == p) {
      continue;
    }
    g++;
    // max1 = max(dp(x, v), max1);
    // min1 = min(min1, dp(x, v));
    // res += dp(x, v);
  }

  memo[v] = g;
  done[v] = 1;
  return g;
}
int main() {
  ll n;
  cin >> n;
  vector<ll> B(n);
  rep(i, n - 1) {
    int b;
    cin >> b;
    B[i] = b - 1;
    to[b - 1].push_back(i + 1); // 上司の親に部下の子供。
  }
  rep(i, n) {
    cout << dp(i) << endl; // 一番上司を与えた時に答えを返す。
  }
}

Error: 0

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
vector<ll> to[30];
vector<ll> memo(30);
vector<ll> done(30);
ll dp(int v, int p = -1) {
  if (done[v] == 1) {
    return memo[v];
  }

  // ll max1 = -1;
  // ll min1 = 1000000000;
  ll g = 0;
  for (ll x : to[v]) {
    if (x == p) {
      continue;
    }
    g++;
    // max1 = max(dp(x, v), max1);
    // min1 = min(min1, dp(x, v));
    // res += dp(x, v);
  }

  memo[v] = +g;
  done[v] = 1;
  return g;
}
int main() {
  ll n;
  cin >> n;
  vector<ll> B(n);
  rep(i, n - 1) {
    int b;
    cin >> b;
    B[i] = b - 1;
    to[b - 1].push_back(i + 1); // 上司の親に部下の子供。
  }
  rep(i, n) {
    cout << dp(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> v(n);
  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    v[a - 1]++;
  }
  for (int x : v) {
    cout << x << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  a[0] = 0;
  vector<int> b(n);
  b[0] = 0;
  b[n] = 0;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  sort(a.begin(), a.end());

  for (int i = 1; i <= n; i++) {
    cout << b[i] << '\\n';
  }
  return 0;
}