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

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

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long

const int N = 2e5 + 5;
int a[N];

void fileIO() {
#ifndef ONLINE_JUDGE
  freopen("int.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}
int main() {
  IOS;
  fileIO();
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  sort(a + 1, a + n + 1);
  // for(int i = 1; i <= n; i++)cout << a[i] <<" ";
  // cout << endl;
  int cnt = 0;
  for (int i = 1; i <= n - k; i++) {
    cnt += a[i];
  }
  cout << cnt;
  return 0;
}


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

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long

const int N = 2e5 + 5;
int a[N];

void fileIO() {
#ifndef ONLINE_JUDGE
  freopen("int.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}
int main() {
  IOS;
  // fileIO();
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  sort(a + 1, a + n + 1);
  // for(int i = 1; i <= n; i++)cout << a[i] <<" ";
  // cout << endl;
  int cnt = 0;
  for (int i = 1; i <= n - k; i++) {
    cnt += a[i];
  }
  cout << cnt;
  return 0;
}
Problem p03495 (C++)

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

int main() {
  int n = 0, k = 0, some = 0;
  int ans = 0, cnt = 0;
  int a[20000] = {};
  int m[20000] = {};
  std::cin >> n >> k;
  for (int i = 0; i < n; i++) {
    std::cin >> some;
    a[i] = some;
    m[some - 1]++;
  }
  std::sort(m, m + n);
  std::reverse(m, m + n);
  for (int i = 0; i < k; i++) {
    m[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    ans += m[i];
  }
  std::cout << ans << std::endl;
}


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

int main() {
  int n = 0, k = 0, some = 0;
  int ans = 0, cnt = 0;
  int a[200009] = {};
  int m[200009] = {};
  std::cin >> n >> k;
  for (int i = 0; i < n; i++) {
    std::cin >> some;
    a[i] = some;
    m[some - 1]++;
  }
  std::sort(m, m + n);
  std::reverse(m, m + n);
  for (int i = 0; i < k; i++) {
    m[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    ans += m[i];
  }
  std::cout << ans << std::endl;
}
Problem p03495 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, m, x, y, k, w, h, ans = 0, mx = 0, mn = INF;
string s;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;
  vector<ll> cnt(n + 1);
  rep(i, n) {
    cin >> a;
    cnt[a]++;
  }
  sort(all(cnt));
  rep(i, cnt.size()) {
    if (cnt[i] == 0) {
      cnt.erase(cnt.begin() + i);
    }
  }
  rep(i, cnt.size() - k) { ans += cnt[i]; }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, m, x, y, k, w, h, ans = 0, mx = 0, mn = INF;
string s;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;
  vector<ll> cnt(n + 1);
  rep(i, n) {
    cin >> a;
    cnt[a]++;
  }
  sort(all(cnt));
  rep(i, 1, n - k + 1) { ans += cnt[i]; }
  cout << ans << endl;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
// url:
// problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
  int N;
  int K;
  cin >> N >> K;
  map<int, int> mp;
  set<int> st;
  ll ans = 0;
  REP(i, N) {
    int a;
    cin >> a;
    st.insert(a);
    if (mp.count(a))
      mp[a]++;
    else
      mp[a] = 1;
  }
  vector<P> res;
  for (P p : mp)
    res.push_back(make_pair(p.second, p.first));
  sort(res.begin(), res.end());
  if (st.size() <= 2) {
    cout << 0 << endl;
    return 0;
  } else {
    REP(i, st.size() - K) { ans += res[i].first; }
  }
  cout << ans << endl;
}

Fixed submission:
// url:
// problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
  int N;
  int K;
  cin >> N >> K;
  map<int, int> mp;
  set<int> st;
  ll ans = 0;
  REP(i, N) {
    int a;
    cin >> a;
    st.insert(a);
    if (mp.count(a))
      mp[a]++;
    else
      mp[a] = 1;
  }
  vector<P> res;
  for (P p : mp)
    res.push_back(make_pair(p.second, p.first));
  sort(res.begin(), res.end());
  if (st.size() <= K) {
    cout << 0 << endl;
    return 0;
  } else {
    REP(i, st.size() - K) { ans += res[i].first; }
  }
  cout << ans << endl;
}
Problem p03495 (C++)

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

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

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

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

  vector<pair<int, int>> P;
  pair<int, int> q;
  int type = keymap.size();
  for (auto itr = keymap.begin(); itr != keymap.end(); ++itr) {
    q.first = itr->second;
    q.second = itr->first;
    P.push_back(q);
  }

  /*for(int i = 0; i < type; i++){
      cout << P[i].first << " " << P[i].second << endl;
  }*/

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

  /*for(int i = 0; i < type; i++){
      cout << P[i].first << " " << P[i].second << endl;
  }*/

  int ans = 0;
  while (1) {
    if (type <= k) {
      break;
    }

    ans += P[0].first;
    type--;
    P.erase(P.begin());
  }

  cout << ans << endl;
}

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

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

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

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

  vector<pair<int, int>> P;
  pair<int, int> q;
  int type = keymap.size();
  for (auto itr = keymap.begin(); itr != keymap.end(); ++itr) {
    q.first = itr->second;
    q.second = itr->first;
    P.push_back(q);
  }

  /*for(int i = 0; i < type; i++){
      cout << P[i].first << " " << P[i].second << endl;
  }*/

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

  /*for(int i = 0; i < type; i++){
      cout << P[i].first << " " << P[i].second << endl;
  }*/

  int ans = 0;
  for (int i = 0; i < type - k; i++) {
    ans += P[i].first;
  }

  cout << ans << endl;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
multiset<int> a;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; n > i; i++) {
    int z;
    cin >> z;
    a.insert(z);
  }
  vector<int> b;
  for (auto i = a.begin(); a.end() != i;) {
    b.push_back(a.count(*i));
    while (*i == *++i) {
      if (i == a.end())
        break;
    }
  }
  sort(b.begin(), b.end());
  int ret = 0;
  for (int i = 0; b.size() - i != k; i++) {
    ret += b[i];
  }
  cout << ret << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
multiset<int> a;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; n > i; i++) {
    int z;
    cin >> z;
    a.insert(z);
  }
  vector<int> b;
  for (auto i = a.begin(); a.end() != i;) {
    b.push_back(a.count(*i));
    while (*i == *++i) {
      if (i == a.end())
        break;
    }
  }
  sort(b.begin(), b.end());
  int ret = 0;
  for (int i = 0; b.size() - i > k; i++) {
    ret += b[i];
  }
  cout << ret << endl;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
  int n, k, a[100009];
  while (~scanf("%d %d", &n, &k)) {
    memset(a, 0, sizeof(a));
    int num, l = 999999, r = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &num);
      a[num]++;
      l = min(l, num);
      r = max(r, num);
    }
    if (r - l + 1 <= k)
      printf("0\n");
    else {
      sort(a + l, a + r + 1);
      int ans = 0;
      while (r - l + 1 > k)
        ans += a[l++];
      printf("%d\n", ans);
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
  int n, k, a[1000009];
  while (~scanf("%d %d", &n, &k)) {
    memset(a, 0, sizeof(a));
    int num, l = 999999, r = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &num);
      a[num]++;
      l = min(l, num);
      r = max(r, num);
    }
    if (r - l + 1 <= k)
      printf("0\n");
    else {
      sort(a + l, a + r + 1);
      int ans = 0;
      while (r - l + 1 > k)
        ans += a[l++];
      printf("%d\n", ans);
    }
  }
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <unordered_map>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[]) {
  ll n, k;
  cin >> n >> k;
  map<ll, ll> m;
  for (ll i = 0; i < n; i++) {
    ll a;
    cin >> a;
    m[a]++;
  }
  vector<ll> v;
  for (auto i : m) {
    v.push_back(i.second);
  }
  sort(ALL(v));
  ll ans = 0;
  for (ll i = 0; i < v.size() - k; i++) {
    ans += v[i];
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <unordered_map>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[]) {
  ll n, k;
  cin >> n >> k;
  map<ll, ll> m;
  for (ll i = 0; i < n; i++) {
    ll a;
    cin >> a;
    m[a]++;
  }
  vector<ll> v;
  for (auto i : m) {
    v.push_back(i.second);
  }
  sort(ALL(v));
  ll ans = 0;
  ll mm = v.size() - k;
  if (mm < 0) {
    cout << 0 << endl;
    exit(0);
  }
  for (ll i = 0; i < mm; i++) {
    ans += v[i];
  }
  cout << ans << endl;
}
Problem p03495 (C++)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  map<int, int> cnt;
  int res = 0;
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }

  vector<int> q;
  for (auto x : cnt)
    q.push_back(x.second);
  sort(q.begin(), q.end());
  // for(auto x: q) cout << x << ' ';
  for (int i = 0; i < q.size() - k; i++)
    res += q[i];

  cout << res;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  map<int, int> cnt;
  int res = 0;
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }

  vector<int> q;
  for (auto x : cnt)
    q.push_back(x.second);
  sort(q.begin(), q.end());
  // for(auto x: q) cout << x << ' ';
  for (int i = 0; i < int(q.size()) - k; i++)
    res += q[i];

  cout << res;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define INF (int)1e9
#define MOD (int)1e9 + 7
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

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

  map<int, int> mp;
  REP(i, n) {
    int n;
    cin >> n;
    mp[n]++;
  }

  vi cnt;
  for (const auto &elem : mp) {
    // cout<<elem.second<<endl;//!!!
    cnt.push_back(elem.second);
  }
  sort(ALL(cnt));
  // REP(i,cnt.size()) cout<<cnt[i]<<endl;//!!!

  llong ans = 0;
  REP(i, cnt.size() - k) { ans += cnt[i]; }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define INF (int)1e9
#define MOD (int)1e9 + 7
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

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

  map<int, int> mp;
  REP(i, n) {
    int n;
    cin >> n;
    mp[n]++;
  }

  vi cnt;
  for (const auto &elem : mp) {
    // cout<<elem.second<<endl;//!!!
    cnt.push_back(elem.second);
  }
  sort(ALL(cnt));
  // REP(i,cnt.size()) cout<<cnt[i]<<endl;//!!!

  if (cnt.size() <= k) {
    cout << 0 << endl;
    return 0;
  }

  llong ans = 0;
  REP(i, cnt.size() - k) { ans += cnt[i]; }

  cout << ans << endl;
  return 0;
}
Problem p03495 (C++)

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

using namespace std;

typedef long long ll;
const ll INF = 1LL << 60;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  vector<int> cnt_A(N);

  int tmp = 0;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    tmp--; // 0indexed
    cnt_A[tmp]++;
  }

  vector<int> cnt_n0;
  for (int i = 0; i < N; i++) {
    if (cnt_A[i] > 0) {
      cnt_n0.push_back(cnt_A[i]);
    }
  }

  sort(cnt_n0.begin(), cnt_n0.end(), greater<int>());

  int sum_k = 0;
  for (int i = 0; i < K; i++) {
    sum_k += cnt_n0[i];
  }

  cout << (N - sum_k) << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL << 60;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  vector<int> cnt_A(N);

  int tmp = 0;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    tmp--; // 0indexed
    cnt_A[tmp]++;
  }

  vector<int> cnt_n0;
  for (int i = 0; i < N; i++) {
    if (cnt_A[i] > 0) {
      cnt_n0.push_back(cnt_A[i]);
    }
  }

  sort(cnt_n0.begin(), cnt_n0.end(), greater<int>());

  int sum_k = 0;
  for (int i = 0; i < min(K, int(cnt_n0.size())); i++) {
    sum_k += cnt_n0[i];
  }

  cout << (N - sum_k) << endl;

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a.at(i);
  map<int, int> mp;
  rep(i, n) mp[a.at(i)]++;
  vi vec;
  for (auto p : mp) {
    int key = p.first;
    vec.push_back(mp[key]);
  }
  sort(vec.begin(), vec.end());
  int ans = 0;
  while (vec.size() > k) {
    ans += vec.at(0);
    vec.erase(vec.begin());
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a.at(i);
  map<int, int> mp;
  rep(i, n) mp[a.at(i)]++;
  vi vec;
  for (auto p : mp) {
    int key = p.first;
    vec.push_back(mp[key]);
  }
  sort(vec.begin(), vec.end());
  int ans = 0;
  int m;
  m = vec.size();
  rep(i, m - k) ans += vec.at(i);
  cout << ans << endl;
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define RUP(a, b) ((a + b - 1) / (b))
#define ENT "\n"

typedef long long ll;
typedef tuple<int, int, bool> Tb;

int atcoder() {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  REP(i, n) {
    int a;
    cin >> a;
    mp[a]++;
  }
  int ans = n;
  vector<int> v;

  for (auto p : mp)
    v.push_back(p.second);

  sort(v.begin(), v.end(), greater<int>());
  REP(i, k) ans -= v[i];

  cout << ans << ENT;
  return 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  atcoder();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define RUP(a, b) ((a + b - 1) / (b))
#define ENT "\n"

typedef long long ll;
typedef tuple<int, int, bool> Tb;

int atcoder() {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  REP(i, n) {
    int a;
    cin >> a;
    mp[a]++;
  }
  int ans = n;
  vector<int> v;

  for (auto p : mp)
    v.push_back(p.second);

  sort(v.begin(), v.end(), greater<int>());
  k = min((int)v.size(), k);
  REP(i, k) ans -= v[i];

  cout << ans << ENT;
  return 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  atcoder();
  return 0;
}
Problem p03495 (C++)

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> count(n + 1);
  rep2(i, 1, n + 1) {
    rep(j, n) {
      if (i == a[j])
        count[i]++;
    }
  }
  sort(all(count));
  reverse(all(count));
  ll ans = 0;
  rep2(i, k, n + 1) ans += count[i];
  cout << ans << endl;
  return 0;
}


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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> count(n + 1);
  rep(i, n) count[a[i]]++;
  sort(all(count));
  reverse(all(count));
  ll ans = 0;
  rep2(i, k, n + 1) ans += count[i];
  cout << ans << endl;
  return 0;
}
Problem p03495 (C++)

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int A[11111] = {};

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

  sort(A, A + N);

  for (int i = 0; i < N - K; i++) {
    ans += A[i];
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int A[N] = {};

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

  sort(A, A + N);

  for (int i = 0; i < N - K; i++) {
    ans += A[i];
  }

  cout << ans << endl;

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define N 10
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long ll;
using namespace std;
int a[N];
int w[N];
int cmp(int x, int y) { return x > y; }
int main() {
  int n, k;
  int ans = 0;
  int t;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    w[a[i]]++;
  }
  int num = 0;

  for (int i = 1; i <= N; i++)
    if (w[i] != 0)
      ans++;
  sort(w + 1, w + 1 + N, cmp);
  if (ans > k) {
    t = ans - k;
    for (int i = k + 1; i <= ans; i++)
      num += w[i];
    cout << num << endl;
  } else
    cout << "0" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define N 200100
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long ll;
using namespace std;
int a[N];
int w[N];
int cmp(int x, int y) { return x > y; }
int main() {
  int n, k;
  int ans = 0;
  int t;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    w[a[i]]++;
  }
  int num = 0;

  for (int i = 1; i <= N; i++)
    if (w[i] != 0)
      ans++;
  sort(w + 1, w + 1 + N, cmp);
  if (ans > k) {
    t = ans - k;
    for (int i = k + 1; i <= ans; i++)
      num += w[i];
    cout << num << endl;
  } else
    cout << "0" << endl;
  return 0;
}
Problem p03495 (C++)

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

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

  vector<ll> g;
  for (auto i = m.begin(); i != m.end(); i++) {
    // cout<<"m["<<i->first<<"]="<<i->second<<endl;
    g.push_back(i->second);
  }

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

  // for (ll i=0;i<g.size();i++)
  // cout<<"g["<<i<<"]="<<g[i]<<endl;

  ll count = 0;
  for (ll i = 0; i < m.size() - K; i++) {
    count += g[i];
  }

  cout << count << endl;
}

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N + 1);
  map<ll, ll> m;
  for (ll i = 1; i <= N; i++) {
    cin >> A[i];
    m[A[i]]++;
  }
  // cout<<K-(m.size())<<endl;
  ll msize = m.size();

  if (K - msize > 0) {
    // cout<<K - msize<<endl;
    cout << 0 << endl;
    return (0);
  }

  vector<ll> g;
  for (auto i = m.begin(); i != m.end(); i++) {
    // cout<<"m["<<i->first<<"]="<<i->second<<endl;
    g.push_back(i->second);
  }

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

  // for (ll i=0;i<g.size();i++)
  // cout<<"g["<<i<<"]="<<g[i]<<endl;

  ll count = 0;
  for (ll i = 0; i < m.size() - K; i++) {
    count += g[i];
  }

  cout << count << endl;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define INF 100000000
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
vector<P> V(2005);

bool comp(const P &a, const P &b) {
  // if (a.second > b.second) return (a.second > b.second);
  return a.second > b.second;
}
int main() {
  int N, K;
  cin >> N >> K;
  // memset(&V[0], 0, sizeof(V[0])*V.size());
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    V[x].first = x;
    V[x].second++;
  }
  sort(V.begin(), V.end(), comp);

  int cnt = 0;
  for (int i = 0;; i++) {
    if (V[i].second == 0)
      break;
    if (i + 1 > K) {
      cnt += V[i].second;
    }
  }
  cout << cnt << endl;
  // for (int i = 0; i < N+1; i++) {
  //	cout << V[i].first << " " << V[i].second << endl;
  // }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define INF 100000000
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
vector<P> V(200005);

bool comp(const P &a, const P &b) {
  // if (a.second > b.second) return (a.second > b.second);
  return a.second > b.second;
}
int main() {
  int N, K;
  cin >> N >> K;
  // memset(&V[0], 0, sizeof(V[0])*V.size());
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    V[x].first = x;
    V[x].second++;
  }
  sort(V.begin(), V.end(), comp);

  int cnt = 0;
  for (int i = 0;; i++) {
    if (V[i].second == 0)
      break;
    if (i + 1 > K) {
      cnt += V[i].second;
    }
  }
  cout << cnt << endl;
  // for (int i = 0; i < N+1; i++) {
  //	cout << V[i].first << " " << V[i].second << endl;
  // }

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000    // 10^9

int Bucket[200001]; // グローバル変数はデフォルトで0に初期化される

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

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

  vector<int> v;

  for (int i = 0; i <= 200000; i++) {
    if (Bucket[i] != 0)
      v.push_back(Bucket[i]);
  }

  if (v.size() <= K) {
    cout << 0 << endl;
    return 0;
  }

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

  int ans = 0;

  while (v.size() > K) {
    ans += v[0];
    v.erase(v.begin());
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000    // 10^9

int Bucket[200001]; // グローバル変数はデフォルトで0に初期化される

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

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

  vector<int> v;

  for (int i = 0; i <= 200000; i++) {
    if (Bucket[i] != 0)
      v.push_back(Bucket[i]);
  }

  if (v.size() <= K) {
    cout << 0 << endl;
    return 0;
  }

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

  int ans = 0;

  for (int i = 0; i < v.size() - K; i++) {
    ans += v[i];
  }

  cout << ans << endl;

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

const int N_MAX = 200005;
int N, K;
int A[N_MAX];
map<int, int> m;

struct sort_pred {
  bool operator()(const std::pair<int, int> &left,
                  const std::pair<int, int> &right) {
    return left.second < right.second;
  }
};

int main() {
  int a;
  int k;
  cin >> N;
  cin >> K;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    A[i] = a;
    if (m.find(A[i]) == m.end()) {
      m[A[i]] = 1;
      k++;
    } else {
      m[A[i]] += 1;
    }
  }

  vector<pair<int, int>> v;
  for (pair<int, int> p : m) {
    v.push_back(p);
  }

  sort(v.begin(), v.end(), sort_pred());

  int count = 0;
  for (pair<int, int> p : v) {
    if (k <= K)
      break;

    count += p.second;
    k--;
  }

  cout << count << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

const int N_MAX = 200005;
int N, K;
int A[N_MAX];
map<int, int> m;

struct sort_pred {
  bool operator()(const std::pair<int, int> &left,
                  const std::pair<int, int> &right) {
    return left.second < right.second;
  }
};

int main() {
  int a;
  int k = 0;
  cin >> N;
  cin >> K;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    A[i] = a;
    if (m.find(A[i]) == m.end()) {
      m[A[i]] = 1;
      k++;
    } else {
      m[A[i]] += 1;
    }
  }

  vector<pair<int, int>> v;
  for (pair<int, int> p : m) {
    v.push_back(p);
  }

  sort(v.begin(), v.end(), sort_pred());

  int count = 0;
  for (pair<int, int> p : v) {
    if (k <= K)
      break;

    count += p.second;
    k--;
  }

  cout << count << endl;

  return 0;
}
Problem p03495 (C++)

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]]++;
  }
  // cout<<mp.size()<<endl;
  int fr[mp.size()];
  int c = 0;
  map<int, int>::iterator it = mp.begin();
  while (it != mp.end()) {
    //   cout<<it->second<<"   ";
    fr[c] = it->second;
    it++;
    c++;
  }
  sort(fr, fr + mp.size());
  int sum = 0;
  for (int i = 0; i < mp.size() - k; i++)
    sum += fr[i];

  cout << sum;

  return 0;
}


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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]]++;
  }
  // cout<<mp.size()<<endl;
  int fr[mp.size()];
  int c = 0;
  map<int, int>::iterator it = mp.begin();
  while (it != mp.end()) {
    //   cout<<it->second<<"   ";
    fr[c] = it->second;
    it++;
    c++;
  }
  sort(fr, fr + mp.size());
  int sum = 0;
  for (int i = 0; i < (int)mp.size() - k; i++)
    sum += fr[i];

  cout << sum;

  return 0;
}
Problem p03495 (C++)

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

int main() {
  int N, K, a, temp, cnt, kind, num, sum, minn;
  temp = 0;
  cnt = 1;
  num = 0;
  sum = 0;
  cin >> N >> K;
  minn = N;
  vector<int> ball(N);
  vector<int> kindball(N);
  for (int i = 0; i < N; i++) {
    cin >> a;
    ball.at(i) = a;
    //  kindball.at(i) = 0;
  }

  sort(ball.begin(), ball.end());
  temp = ball.at(0);
  for (int i = 0; i < N; i++) {
    if (temp != ball.at(i)) {
      temp = ball.at(i);
      cnt++;
      num++;
      kindball.at(num) = 1;
    } else {
      kindball.at(num) += 1;
    }
  }
  kind = cnt - K;
  temp = 0;

  sort(kindball.begin(), kindball.end());
  for (int j = N - cnt; j < N - kind - 1; j++) {
    sum += kindball.at(j);
  }
  cout << sum << endl;
}


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

int main() {
  int N, K, a, temp, cnt, kind, num, sum, minn;
  temp = 0;
  cnt = 1;
  num = 0;
  sum = 0;
  cin >> N >> K;
  minn = N;
  vector<int> ball(N);
  vector<int> kindball(N);
  for (int i = 0; i < N; i++) {
    cin >> a;
    ball.at(i) = a;
    //  kindball.at(i) = 0;
  }

  sort(ball.begin(), ball.end());
  temp = ball.at(0);
  for (int i = 0; i < N; i++) {
    if (temp != ball.at(i)) {
      temp = ball.at(i);
      cnt++;
      num++;
      kindball.at(num) = 1;
    } else {
      kindball.at(num) += 1;
    }
  }
  kind = cnt - K;
  temp = 0;

  sort(kindball.begin(), kindball.end());
  for (int j = N - cnt; j < N - cnt + kind; j++) {
    sum += kindball.at(j);
  }
  cout << sum << endl;
}
Problem p03495 (C++)

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

int main(int argc, char const *argv[]) {
  int n, k;
  std::cin >> n >> k;
  //       <ball index, count>
  std::map<int, int> mm;

  for (int i = 0; i < n; ++i) {
    int tmp;
    std::cin >> tmp;

    auto count = mm.count(tmp);
    if (count == 0) {
      mm[tmp] = 1;
    } else {
      mm[tmp]++;
    }
  }

  std::vector<int> nums;
  for (auto &pair : mm) {
    nums.push_back(pair.second);
  }

  std::sort(nums.begin(), nums.end());
  /* nums.sort(); */
  int result = 0;
  for (int i = 0; i < nums.size() - k; ++i) {
    result += nums[i];
  }
  std::cout << result << std::endl;
  /*
  while (k < nums.size()) {
      result += nums.front();
      nums.pop_front();
  }
  std::cout << result << std::endl;
  */
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <vector>

int main(int argc, char const *argv[]) {
  int n, k;
  std::cin >> n >> k;
  //       <ball index, count>
  std::map<int, int> mm;

  for (int i = 0; i < n; ++i) {
    int tmp;
    std::cin >> tmp;

    auto count = mm.count(tmp);
    if (count == 0) {
      mm[tmp] = 1;
    } else {
      mm[tmp]++;
    }
  }

  std::vector<int> nums;
  for (auto &pair : mm) {
    nums.push_back(pair.second);
  }

  std::sort(nums.begin(), nums.end());
  /* nums.sort(); */
  int result = 0;
  if (k >= nums.size()) {
    std::cout << 0 << std::endl;
    return 0;
  }

  for (int i = 0; i < nums.size() - k; ++i) {
    result += nums[i];
  }
  std::cout << result << std::endl;
  /*
  while (k < nums.size()) {
      result += nums.front();
      nums.pop_front();
  }
  std::cout << result << std::endl;
  */
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <stdio.h>

int main() {
  int n, k, ans = 0;
  std::array<int, 20000> a = {0};
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    ++a[x];
  }
  int norma = 0;
  for (auto &&x : a) {
    if (x > 0)
      ++norma;
  }
  norma -= k;
  std::sort(a.begin(), a.end());
  for (int i = 0; norma > 0; ++i) {
    if (a[i] > 0) {
      --norma;
      ans += a[i];
    }
  }
  printf("%d", ans);
}

Fixed submission:
#include <algorithm>
#include <array>
#include <stdio.h>

int main() {
  int n, k, ans = 0;
  std::array<int, 200000> a = {0};
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    ++a[x];
  }
  int norma = 0;
  for (auto &&x : a) {
    if (x > 0)
      ++norma;
  }
  norma -= k;
  std::sort(a.begin(), a.end());
  for (int i = 0; norma > 0; ++i) {
    if (a[i] > 0) {
      --norma;
      ans += a[i];
    }
  }
  printf("%d", ans);
}
Problem p03495 (C++)

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

int main(void) {
  int N, K, V;
  std::cin >> N >> K;

  std::unordered_map<int, int> mymap;

  for (int i = 0; i < N; i++) {
    std::cin >> V;
    if (mymap.find(V) == mymap.end()) {
      mymap[V] = 1;
    } else {
      int v = mymap[V];
      mymap[V] = v + 1;
    }
  }

  std::vector<int> count;
  for (std::unordered_map<int, int>::iterator it = mymap.begin();
       it != mymap.end(); ++it) {
    count.push_back(it->second);
  }
  std::sort(count.begin(), count.end());
  int res = 0;
  for (int i = 0; i < count.size() - K; i++) {
    res += count[i];
  }
  std::cout << res;
  return 0;
}

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

int main(void) {
  int N, K, V;
  std::cin >> N >> K;

  std::unordered_map<int, int> mymap;

  for (int i = 0; i < N; i++) {
    std::cin >> V;
    if (mymap.find(V) == mymap.end()) {
      mymap[V] = 1;
    } else {
      int v = mymap[V];
      mymap[V] = v + 1;
    }
  }

  std::vector<int> count;
  for (std::unordered_map<int, int>::iterator it = mymap.begin();
       it != mymap.end(); ++it) {
    count.push_back(it->second);
  }
  std::sort(count.begin(), count.end());
  int res = 0;
  if (count.size() > K)
    for (int i = 0; i < count.size() - K; i++) {
      res += count[i];
    }
  std::cout << res;
  return 0;
}
Problem p03495 (C++)

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

using namespace std;

int main(void) {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    mp[a]++;
  }
  vector<int> vec;
  for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {
    vec.push_back(it->second);
  }
  int ans = 0;
  sort(vec.begin(), vec.end());
  for (int i = 0; i < mp.size() - k; i++) {
    ans += vec[i];
  }
  cout << ans;
}

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

using namespace std;

int main(void) {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    mp[a]++;
  }
  vector<int> vec;
  for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {
    vec.push_back(it->second);
  }
  int ans = 0;
  sort(vec.begin(), vec.end());
  for (int i = 0; i < (int)mp.size() - k; i++) {
    ans += vec[i];
  }
  cout << ans;
}
Problem p03495 (C++)

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

int main() {
  uint32_t N = 0, K = 0;
  std::cin >> N >> K;

  std::vector<uint32_t> count(N + 1, 0);
  for (size_t i = 0; i < N; i++) {
    uint32_t a = 0;
    std::cin >> a;
    count[a]++;
  }

  std::sort(count.begin(), count.end(), std::greater_equal<uint32_t>());

  uint32_t sum = 0;
  for (size_t i = K; i < count.size() && count[i] != 0; i++)
    sum += count[i];

  std::cout << sum << std::endl;

  return 0;
}

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

int main() {
  uint32_t N = 0, K = 0;
  std::cin >> N >> K;

  std::vector<uint32_t> count(N + 1, 0);
  for (size_t i = 0; i < N; i++) {
    uint32_t a = 0;
    std::cin >> a;
    count[a]++;
  }

  std::sort(count.begin(), count.end(), std::greater<uint32_t>());

  uint32_t sum = 0;
  for (size_t i = K; i < count.size() && count[i] != 0; i++)
    sum += count[i];

  std::cout << sum << std::endl;

  return 0;
}
Problem p03495 (C++)

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

using namespace std;

int main() {
  int N, K, A[2200] = {}, Baket[2200] = {};
  int Ans = 0;

  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    Baket[A[i]]++;
  }
  sort(Baket, Baket + N + 1, greater<>());

  for (int i = 0; i < N - K; i++) {
    Ans += Baket[K + i];
  }
  cout << Ans << endl;

  return 0;
}

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

using namespace std;

int main() {
  int N, K, A[220000] = {}, Baket[220000] = {};
  int Ans = 0;

  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    Baket[A[i]]++;
  }
  sort(Baket, Baket + N + 1, greater<>());

  for (int i = 0; i < N - K; i++) {
    Ans += Baket[K + i];
  }
  cout << Ans << endl;

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
int main(int argc, char *argv[]) {
  int N, K;
  std::cin >> N >> K;
  int k[1 << 11]{};
  int n;
  for (int i = 0; i < N; ++i) {
    std::cin >> n;
    ++k[n];
  }

  std::sort(k, k + N + 1, std::greater<int>());

  long sum{};
  for (int i = K; i <= N; ++i)
    sum += k[i];

  std::cout << sum << std::endl;
}


Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
int main(int argc, char *argv[]) {
  int N, K;
  std::cin >> N >> K;
  int k[1 << 21]{};
  int n;
  for (int i = 0; i < N; ++i) {
    std::cin >> n;
    ++k[n];
  }

  std::sort(k, k + N + 1, std::greater<int>());

  long sum{};
  for (int i = K; i <= N; ++i)
    sum += k[i];

  std::cout << sum << std::endl;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll boal[200005] = {};
int main() {
  int n, k;
  cin >> n >> k;
  int boalnumber;
  for (int i = 0; i < n; i++) {
    cin >> boalnumber;
    boal[boalnumber]++;
  }
  sort(boal, boal + n);
  reverse(boal, boal + n);
  ll count = 0;
  int index;
  for (int i = 1; i <= 200005; i++) {
    if (boal[i] > 0) {
      count++;
    }
    if (count == k) {
      index = i;
      break;
    }
  }
  if (count < k) {
    cout << "0" << endl;
    return 0;
  }
  ll ans = 0;
  for (int i = index; i <= 200000; i++) {
    ans += boal[i];
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll boal[200005] = {};
int main() {
  int n, k;
  cin >> n >> k;
  int boalnumber;
  for (int i = 0; i < n; i++) {
    cin >> boalnumber;
    boal[boalnumber]++;
  }
  sort(boal, boal + n);
  reverse(boal, boal + n);
  ll count = 0;
  int index;
  for (int i = 1; i <= 200000; i++) {
    if (boal[i] > 0) {
      count++;
    }
    if (count == k) {
      index = i;
      break;
    }
  }
  if (count < k) {
    cout << "0" << endl;
    return 0;
  }
  ll ans = 0;
  for (int i = index; i <= 200000; i++) {
    ans += boal[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#define MAXN 200000 + 5

typedef long long ll;

const int INF = 0x7fffffff;

using namespace std;

int a[MAXN];
int sit[MAXN];
struct NUM {
  int number, time;
};

vector<NUM> c;
bool cmp(NUM N, NUM M) {
  return N.time > M.time; // 出现次数的的拍在前面
}
int main() {
  int n, k, num = 0;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    if (a[x] == 0) { // 来了一个新的数
      // 记录开始的位置
      sit[x] = num;
      num++;
      // 插入新元素
      NUM k;
      k.number = x;
      k.time = 1;
      c.push_back(k);
    } else {
      c[sit[x]].time++;
    }
    a[x]++;
  }
  if (n <= k) {
    printf("0");
    return 0;
  }
  sort(c.begin(), c.end(), cmp);
  int ans = 0;
  for (int i = 0; i < k; i++) {
    ans += c[i].time;
  }
  printf("%d", n - ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#define MAXN 200000 + 5

typedef long long ll;

const int INF = 0x7fffffff;

using namespace std;

int a[MAXN];
int sit[MAXN];
struct NUM {
  int number, time;
};

vector<NUM> c;
bool cmp(NUM N, NUM M) {
  return N.time > M.time; // 出现次数的的拍在前面
}
int main() {
  int n, k, num = 0;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    if (a[x] == 0) { // 来了一个新的数
      // 记录开始的位置
      sit[x] = num;
      num++;
      // 插入新元素
      NUM k;
      k.number = x;
      k.time = 1;
      c.push_back(k);
    } else {
      c[sit[x]].time++;
    }
    a[x]++;
  }
  if (n <= k) {
    printf("0");
    return 0;
  }
  sort(c.begin(), c.end(), cmp);
  int ans = 0;
  for (int i = 0; i < k && i < num; i++) {
    ans += c[i].time;
  }
  printf("%d", n - ans);
  return 0;
}
Problem p03495 (Python)

Buggy submission (status: Time Limit Exceeded):
n, k = map(lambda x: int(x), input().split(" "))
a = list(map(lambda x: int(x), input().split(" ")))

num_dups = []
a_set = set(a)
for elem in a_set:
    num_dups.append(a.count(elem))

num_dups.sort(reverse=True)

ball_to_replace = len(a_set) - k

result = 0
for i in range(ball_to_replace):
    result += num_dups.pop()

print(result)


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A1 = set(A)
AN = {}
for a in A:
    if not a in AN:
        AN[a] = 0
    AN[a] += 1
AN = sorted(AN.items(), key=lambda x: x[1])
ans = 0
K1 = len(A1) - K
if K1 > 0:
    for k in range(K1):
        ans += AN[k][1]
    print(ans)
else:
    print("0")
Problem p03495 (C++)

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

int N, K, H[200001];
vector<int> A;

int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; i++) {
    int val;
    scanf("%d", &val);
    H[val]++;
  }
  for (int i = 1; i < 200001; i++)
    if (H[i] > 0)
      A.push_back(H[i]);
  int sum = 0;
  sort(A.begin(), A.end());
  for (int i = 0; i < A.size() - K; i++)
    sum += A[i];
  printf("%d\n", sum);
  return 0;
}


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

int N, K, H[200001];
vector<int> A;

int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; i++) {
    int val;
    scanf("%d", &val);
    H[val]++;
  }
  for (int i = 1; i < 200001; i++)
    if (H[i] > 0)
      A.push_back(H[i]);
  int sum = 0;
  sort(A.begin(), A.end());
  if (A.size() > K)
    for (int i = 0; i < A.size() - K; i++)
      sum += A[i];
  printf("%d\n", sum);
  return 0;
}