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

#include <bits/stdc++.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <vector>
#define endl "\\n"
#define ll long long
#define int long long
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cin.exceptions(cin.failbit);                                                 \\
  cout.tie(NULL);
using namespace std;
bool isPrime(int n) {
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;
  if (n % 2 == 0 || n % 3 == 0)
    return false;
  for (int i = 5; i * i <= n; i += 6) {
    if ((n % i == 0) || (n % (i + 2) == 0))
      return false;
  }
  return true;
}

int32_t main() {
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n - 1; i++) {
      cin >> a[i];
    }
    int x = 2;
    vector<int> v[n + 2];
    for (int i = 0; i < n - 1; i++) {
      v[a[i]].push_back(x);
      x++;
    }
    for (int i = 1; i <= n; i++) {
      cout << v[i].size() << endl;
    }
  }
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <vector>
#define endl "\\n"
#define ll long long
#define int long long
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cin.exceptions(cin.failbit);                                                 \\
  cout.tie(NULL);
using namespace std;
bool isPrime(int n) {
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;
  if (n % 2 == 0 || n % 3 == 0)
    return false;
  for (int i = 5; i * i <= n; i += 6) {
    if ((n % i == 0) || (n % (i + 2) == 0))
      return false;
  }
  return true;
}

int32_t main() {
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int x = 2;
    vector<int> v[n + 2];
    for (int i = 0; i < n; i++) {
      v[a[i]].push_back(x);
      x++;
    }
    for (int i = 1; i <= n + 1; i++) {
      cout << v[i].size() << endl;
    }
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<int> staff_ids(n);

  for (int i = 1; i < n; i++) {
    int boss;
    cin >> boss;
    staff_ids.at(boss - 1)++;
  }

  rep(i, n) cout << staff_ids.at(i) << endl;

  /* Output */
  return 0;
}

Error: TLE

Fixed submission:

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

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

  vector<int> boss_ids(n);
  vector<int> staff_ids(n);

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

  /* Main Logic */
  int ans = 0;
  // 自分の部下を検索
  rep(i, n) {
    for (int j = i + 1; j < n; j++)
      if (i + 1 == boss_ids.at(j))
        staff_ids.at(i)++;
    cout << staff_ids.at(i) << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
using in6 = int64_t;
using ind = double;
using vi = vector<in6>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<in6, in6>;
using psi = pair<string, in6>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i, a, n) for (in6 i = a; i < (in6)(n); i++)
#define repdown(i, n) for (in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() { cout << "Yes"; }

void no() { cout << "No"; }

int main() {
  kyun;
  in6 n;
  cin >> n;
  vi data(n - 1);
  rep(i, n - 1) cin >> data[i];
  vi ans(n, 0);
  rep(i, n - 1) { ans[data[i] - 1]++; }
  rep(i, n) cout << ans[i] << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int, int>;
using psi = pair<string, int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i, a, n) for (in6 i = a; i < (in6)(n); i++)
#define repdown(i, n) for (in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() { cout << "Yes"; }

void no() { cout << "No"; }

int main() {
  kyun;
  int n;
  cin >> n;
  vi data(n - 1);
  rep(i, n - 1) cin >> data[i];
  vi buka(n);
  rep(i, n) {
    rep(j, n - 1) {
      if (data[j] == i + 1)
        buka[i]++;
    }
  }
  rep(i, n) cout << buka[i] << "\\n";
}
Problem p02707 (C++) — buggy submission, verdict: 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[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;
}

Error: 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[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;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {

  int n, i, t;
  cin >> n;
  multiset<int> a, b;

  for (i = 0; i < n - 1; i++) {
    cin >> t;
    a.insert(t);
  }
  for (int i = 1; i <= n; i++) {
    cout << a.count(i) << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {

  unsigned int n, i;
  cin >> n;
  vector<unsigned int> a(n), b(n);

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

/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
#define pb push_back
#define pop pop_back
#define mp make_pair
#define vii vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpi vector<pii>
#define vpl vector<pll>
#define fi first
#define sz size
#define len length
#define se second

const ll mod = 1e9 + 7;
const ll inf = 1e18 + 1e17;
// const ll mod = 998244353;

ll modInverse(ll a, ll m) {
  ll m0 = m;
  ll y = 0, x = 1;
  if (m == 1)
    return 0;
  while (a > 1) {
    ll q = a / m;
    ll t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0)
    x += m0;
  return x;
}
ll powm(ll a, ll b) {
  a = a % mod;
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return (res % mod);
}

const ll N = 2e5 + 6;
const long double pi = 3.14159265358979323;

vii v[N];
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int aa;
    cin >> aa;
    v[aa].pb(i + 2);
  }
  for (int i = 1; i <= n; i++)
    cout << v[i].sz() << '\\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1;
  //	cin>>t;
  for (int i = 1; i <= t; i++) {
    //	cout<<"Case #"<<i<<": ";
    solve();
  }
}


Error: 0

Fixed submission:

/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
#define pb push_back
#define pop pop_back
#define mp make_pair
#define vii vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpi vector<pii>
#define vpl vector<pll>
#define fi first
#define sz size
#define len length
#define se second

const ll mod = 1e9 + 7;
const ll inf = 1e18 + 1e17;
// const ll mod = 998244353;

ll modInverse(ll a, ll m) {
  ll m0 = m;
  ll y = 0, x = 1;
  if (m == 1)
    return 0;
  while (a > 1) {
    ll q = a / m;
    ll t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0)
    x += m0;
  return x;
}
ll powm(ll a, ll b) {
  a = a % mod;
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return (res % mod);
}

const ll N = 1e5 + 6;
const long double pi = 3.14159265358979323;

vii v[N];
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int aa;
    cin >> aa;
    v[aa].pb(i + 2);
  }
  for (int i = 1; i <= n; i++)
    cout << v[i].sz() << '\\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1;
  //	cin>>t;
  for (int i = 1; i <= t; i++) {
    //	cout<<"Case #"<<i<<": ";
    solve();
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <array>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, c, s;
  vector<int> b;
  cin >> N;
  b.push_back(0);
  for (int i = 1; i < N; i++) {
    cin >> c;
    b.push_back(0);

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

Error: TLE

Fixed submission:

#include <array>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, c, s;
  vector<int> a, b;
  cin >> N;
  for (int i = 1; i < N; i++) {
    cin >> c;
    a.push_back(c);
  }
  for (int i = 1; i <= N; i++) {
    c = 0;
    for (auto &p : a) {
      if (i == p)
        c++;
    }
    cout << c << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N];
int main() {
  int n, t;
  cin >> n;
  for (int i = 1; i < n; i++)
    cin >> t, a[t]++;

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 2e7 + 10;
int a[N];
int main() {
  int n, t;
  cin >> n;
  for (int i = 1; i < n; i++)
    cin >> t, a[t]++;
  int ans = n;
  for (int i = 1; i <= N; i++) {
    if (a[i] != 0)
      cout << a[i] << endl, ans--;
  }
  while (ans--)
    cout << 0 << endl;

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

#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

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

  vector<long long> ANS(N, 0);
  for (int i = 1; i < N; i++)
    ANS[A[i] - 1]++;
  for (int i = 0; i < N; i++)
    cout << ANS[i] << endl;
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

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

  vector<long long> ANS(N, 0);
  for (int i = 0; i < N; i++)
    ANS[A[i] - 1]++;
  for (int i = 0; i < N; i++)
    cout << ANS[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 1; i < n; i++)
    cin >> A[i];

  vector<int> ans(n);
  for (int i = 1; i < n; i++) {
    int supervisor = A[i] - 1;
    ans[supervisor] += 1;
  }

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


Error: -6
double free or corruption (out)


Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 1; i < n; i++)
    cin >> A[i];

  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    ans[(A[i] - 1)] += 1;
  }

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

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

int main() {
  int a;
  int K;
  cin >> a;
  vector<int> v(a + 1);
  int tmp;
  for (int i = 0; i < a - 1; i++) {
    cin >> tmp;
    K = v.at(tmp) + 1;
    v.at(tmp) = K;
  }
  for (int i = 1; i < a + 1; i++) {
    cout << v.at(i) << endl;
  }
}


Error: WA

Fixed submission:

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

int main() {
  int a;
  int K;
  cin >> a;
  vector<int> v(a + 1);
  int tmp;
  for (int i = 0; i < a; i++) {
    cin >> tmp;
    K = v.at(tmp) + 1;
    v.at(3) = K;
  }
  for (int i = 0; i < a + 1; i++) {
    cout << v.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  for (int i = 1; i < N; i++) {
    sum[A[i] - 1] = sum[A[i] - 1] + 1;
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

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

  for (int i = 1; i < N; i++) {
    for (int j = 1; j <= i; j++) {
      if (j == A[i]) {
        sum[A[i] - 1] = sum[A[i] - 1] + 1;
      }
    }
  }

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

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

#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;
}


Error: 0

Fixed submission:

#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;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

// BISMILLAHIR RAHMANIR RAHIM
// ALLAH HU AKABR
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n];
  int s[n + 1] = {0};
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    s[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << s[i] << endl;
  }
}


Error: TLE

Fixed submission:

// BISMILLAHIR RAHMANIR RAHIM
// ALLAH HU AKABR
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < n - 1; j++) {
      if (a[j] == i) {
        cnt++;
      }
    }
    cout << cnt << endl;
    cnt = 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> vi(n + 1, 0);
  int p = n - 1;
  while (p--) {
    int u;
    cin >> u;
    vi[u] += 1;
  }
  for (int i = 1; i <= vi.size() - 1; i++) {
    cout << vi[i] << "\\n";
  }
}

Error: TLE

Fixed submission:


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

int main() {
  vector<int> vi;
  int n;
  cin >> n;
  int p = n - 1;
  while (p--) {
    int u;
    cin >> u;
    vi.push_back(u);
  }
  for (int i = 1; i <= vi.size() + 1; i++) {
    cout << count(vi.begin(), vi.end(), i) << "\\n";
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int cnt[300001];
int main() {
  int n;
  cin >> n;
  int a[300001];
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << cnt[i] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int cnt[100001];
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << cnt[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: 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 - 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;
}

Error: -11

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; 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, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}

int main() {
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    m.insert(make_pair(i + 1, 0));
  }

  int a;
  for (int i = 0; i < n - 1; i++) {
    cin >> a;
    m[a - 1]++;
  }
  m.erase(n);
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->second << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}

int main() {
  int N;
  cin >> N;
  vector<int> vec;
  int B;
  for (int i = 0; i < N - 1; ++i) {
    cin >> B;
    vec.push_back(B);
  }

  for (int i = 0; i < N - 1; ++i) {
    cout << count(vec.begin(), vec.end(), i + 1) << endl;
  }
  cout << 0 << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;

ll GCD(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}

ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }

const int MOD = 1000000007;

int main() {
  int x;
  cin >> x;
  multimap<int, int> m;
  for (int i = 1; i <= x; i++) {
    m.insert(make_pair(i, 0));
  }
  for (int i = 0; i < x - 1; i++) {
    int y;
    cin >> y;
    auto z = m.find(y);
    z->second++;
  }
  for (int i = 1; i <= x; i++) {
    auto z = m.find(i);
    cout << z->second << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;

ll GCD(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}

ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }

const int MOD = 1000000007;

int a[1000] = {0};

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

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)

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> res(n, 0);
  rep(i, n - 1) { res[a[i] - 1]++; }
  rep(i, n) { cout << res[i] << endl; }

  return 0;
}


Error: -6
double free or corruption (out)


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);
  rep(i, n - 1) cin >> a[i];

  vector<int> res(n, 0);
  rep(i, n) { res[a[i] - 1]++; }
  rep(i, n) { cout << res[i] << endl; }

  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: 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];
    b[a[i]]++;
  }
  for (int i = 1; i < n + 1; i++)
    cout << b[i] << endl;
}

Error: TLE

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

  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    ans.at(i) = 0;
  }
  for (int i = 0; i < N - 1; i++) {
    ans.at(A.at(i) - 1) = ans.at(A.at(i) - 1) + 1;
  }
  for (int i = 0; i < N; i++) {
    cout << ans.at(i) << endl;
  }
  return 0;
}

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


Fixed submission:

#include <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; i++) {
    ans.at(i) = 0;
  }
  for (int i = 0; i < N; i++) {
    ans.at(A.at(i)) = ans.at(A.at(i)) + 1;
  }
  for (int i = 0; i < N; i++) {
    cout << ans.at(i) << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

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

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

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

Error: WA

Fixed submission:

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

int main() {

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

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

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

  return 0;
}