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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, x, n) for (int i = x; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(X) (X).begin(), (X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class A, size_t N, class T> void Fill(A (&a)[N], const T &v) {
  fill((T *)a, (T *)(a + N), v);
}

const ll INF = 1e9 + 7;

int main() {
  // ios_base::sync_with_stdio(false);
  int N, K, ans = 0;
  int A[100005];

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

  map<int, int> mp;
  rep(i, N) mp[A[i]]++;

  vector<int> v;
  for (auto t : mp)
    v.emplace_back(-t.Y);

  sort(all(v));
  int sum = 0;
  rep(i, K) if (i < v.size()) sum += -v[i];

  ans = N - sum;
  cout << ans << endl;

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, x, n) for (int i = x; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(X) (X).begin(), (X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class A, size_t N, class T> void Fill(A (&a)[N], const T &v) {
  fill((T *)a, (T *)(a + N), v);
}

const ll INF = 1e9 + 7;

int main() {
  // ios_base::sync_with_stdio(false);
  int N, K, ans = 0;
  int A[200005];

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

  map<int, int> mp;
  rep(i, N) mp[A[i]]++;

  vector<int> v;
  for (auto t : mp)
    v.emplace_back(-t.Y);

  sort(all(v));
  int sum = 0;
  rep(i, K) if (i < v.size()) sum += -v[i];

  ans = N - sum;
  cout << ans << endl;

  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long int lld;

const lld mod = 1e9 + 7;
const lld INF = 1e9;
// const lld MAXN = 1e9;

int main() {
  lld n, k;
  cin >> n >> k;
  vector<lld> a(n + 1);
  for (int i = 0; i < n; i++) {
    lld x;
    cin >> x;
    a[x]++;
  }

  vector<lld> b;
  for (int i = 1; i <= n; i++) {
    if (a[i] != 0)
      b.push_back(a[i]);
  }

  sort(b.begin(), b.end(), greater<lld>());
  lld ans = accumulate(b.begin(), b.end(), (lld)0);
  for (int i = 0; i < k; i++) {
    ans -= b[i];
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long int lld;

const lld mod = 1e9 + 7;
const lld INF = 1e9;
// const lld MAXN = 1e9;

int main() {
  lld n, k;
  cin >> n >> k;
  vector<lld> a(n + 1);
  for (int i = 0; i < n; i++) {
    lld x;
    cin >> x;
    a[x]++;
  }

  vector<lld> b;
  for (int i = 1; i <= n; i++) {
    if (a[i] != 0)
      b.push_back(a[i]);
  }

  sort(b.begin(), b.end(), greater<lld>());
  lld ans = accumulate(b.begin(), b.end(), (lld)0);
  for (int i = 0; i < min(k, (lld)b.size()); i++) {
    ans -= b[i];
  }
  cout << ans << endl;

  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  map<int, ll> mp;
  rep(i, n) {
    int l;
    cin >> l;
    mp[l]++;
  }
  vector<ll> a = {};
  for (auto i = mp.begin(); i != mp.end(); i++) {
    a.push_back(i->second);
  }
  sort(a.begin(), a.end());
  ll ans = 0;
  rep(i, n - k) { ans += a[i]; }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  map<int, ll> mp;
  rep(i, n) {
    int l;
    cin >> l;
    mp[l]++;
  }
  vector<ll> a = {};
  for (auto i = mp.begin(); i != mp.end(); i++) {
    a.push_back(i->second);
  }
  sort(a.begin(), a.end());
  ll ans = 0;
  if (a.size() <= k)
    cout << 0 << endl;
  else {
    rep(i, a.size() - k) ans += a[i];
    cout << ans << endl;
  }
}
Problem p03497 (C++)

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

int main(void) {
  int n, k, ans = 0;
  map<int, int> ball;
  vector<int> count;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (!ball[a])
      ball[a] = 1;
    else
      ball[a]++;
  }
  for (auto it = ball.begin(); it != ball.end(); it++)
    count.push_back(it->second);
  sort(count.begin(), count.end());
  for (int i = 0; i < ball.size() - k; i++)
    ans += count[i];
  cout << ans << endl;
}


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

int main(void) {
  int n, k, ans = 0;
  map<int, int> ball;
  vector<int> count;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (!ball[a])
      ball[a] = 1;
    else
      ball[a]++;
  }
  for (auto it = ball.begin(); it != ball.end(); it++)
    count.push_back(it->second);
  sort(count.begin(), count.end());
  if (ball.size() <= k) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < ball.size() - k; i++)
    ans += count[i];
  cout << ans << endl;
}
Problem p03497 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

const double PI = acos(-1);

int main() {
  long n, k;
  cin >> n >> k;
  map<long, long> l;
  for (int i = 0; i < n; i++) {
    long a;
    cin >> a;
    l[a]++;
  }
  vector<pair<long, long>> m;
  for (auto i : l) {
    m.push_back(make_pair(i.first, i.second));
  }
  sort(m.begin(), m.end(),
       [](auto const &l, auto const &r) { return l.second < r.second; });
  long cnt = 0;
  while (k < m.size()) {
    cnt += m[0].second;
    m.erase(m.begin());
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

const double PI = acos(-1);

int main() {
  long n, k;
  cin >> n >> k;
  map<long, long> l;
  for (int i = 0; i < n; i++) {
    long a;
    cin >> a;
    l[a]++;
  }
  vector<pair<long, long>> m;
  for (auto i : l) {
    m.push_back(make_pair(i.first, i.second));
  }
  sort(m.begin(), m.end(),
       [](auto const &l, auto const &r) { return l.second < r.second; });
  long cnt = 0;
  for (int i = 0; i < m.size() && k < m.size() - i; i++) {
    cnt += m[i].second;
  }
  cout << cnt << endl;
  return 0;
}
Problem p03497 (C++)

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

int main() {
  int n, k;
  cin >> n >> k;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    m[l]++;
  }
  int i = 0;
  vector<int> b(m.size());
  int ans = 0;
  for (auto a : m) {
    b[i] = a.second;
    i++;
  }
  sort(b.begin(), b.end());
  for (int j = 0; j < m.size() - k; j++) {
    ans += b[j];
  }
  cout << ans << endl;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    m[l]++;
  }
  int i = 0;
  vector<int> b(m.size());
  int ans = 0;
  for (auto a : m) {
    b[i] = a.second;
    i++;
  }
  sort(b.begin(), b.end());

  if (i > k) {
    for (int j = 0; j < m.size() - k; j++) {
      ans += b[j];
    }
  }
  cout << ans << endl;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
typedef long long lint;
const int N = 1e5 + 5;
int n, q, buk[N];

namespace utils {
template <class T> inline void apn(T &x, const T y) { x = x < y ? x : y; }
template <class T> inline void apx(T &x, const T y) { x = x > y ? x : y; }
inline int nxi() {
  int x = 0;
  char c;
  while (((c = getchar()) > '9' || c < '0') && c != '-')
    ;
  const bool f = c == '-' && (c = getchar());
  while (x = x * 10 - 48 + c, (c = getchar()) >= '0' && c <= '9')
    ;
  return f ? -x : x;
}
} // namespace utils
using namespace utils;

int main() {
  n = nxi(), q = nxi();
  for (int i = 1; i <= n; ++i) {
    ++buk[nxi()];
  }
  std::sort(buk + 1, buk + n + 1);
  int ans = 0;
  for (int i = 1; i <= n - q; ++i) {
    ans += buk[i];
  }
  printf("%d\n", ans);
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
typedef long long lint;
const int N = 2e5 + 5;
int n, q, buk[N];

namespace utils {
template <class T> inline void apn(T &x, const T y) { x = x < y ? x : y; }
template <class T> inline void apx(T &x, const T y) { x = x > y ? x : y; }
inline int nxi() {
  int x = 0;
  char c;
  while (((c = getchar()) > '9' || c < '0') && c != '-')
    ;
  const bool f = c == '-' && (c = getchar());
  while (x = x * 10 - 48 + c, (c = getchar()) >= '0' && c <= '9')
    ;
  return f ? -x : x;
}
} // namespace utils
using namespace utils;

int main() {
  n = nxi(), q = nxi();
  for (int i = 1; i <= n; ++i) {
    ++buk[nxi()];
  }
  std::sort(buk + 1, buk + n + 1);
  int ans = 0;
  for (int i = 1; i <= n - q; ++i) {
    ans += buk[i];
  }
  printf("%d\n", ans);
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
// 基本テンプレート

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define int long long int

template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
  int N, K;
  cin >> N >> K;
  map<int, int> mp;
  rep(i, 0, N) {
    int p;
    cin >> p;
    mp[p]++;
  }

  vector<pii> vs;
  for (auto x : mp)
    vs.push_back(make_pair(x.second, x.first));

  int ans = 0;
  sort(vs.begin(), vs.end());
  rep(i, 0, vs.size() - K) {
    // printf("fr = %lld, se = %lld\n", vs[i].first, vs[i].second);
    ans += vs[i].first;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
// 基本テンプレート

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define int long long int

template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
  int N, K;
  cin >> N >> K;
  map<int, int> mp;
  rep(i, 0, N) {
    int p;
    cin >> p;
    mp[p]++;
  }

  vector<pii> vs;
  for (auto x : mp)
    vs.push_back(make_pair(x.second, x.first));

  int ans = 0;
  sort(vs.begin(), vs.end());
  rep(i, 0, (int)vs.size() - K) {
    // printf("fr = %lld, se = %lld\n", vs[i].first, vs[i].second);
    ans += vs[i].first;
  }
  cout << ans << endl;
  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  map<int, int> mp;
  rep(i, n) { mp[a[i]]++; }
  if (mp.size() <= k) {
    cout << 0 << endl;
    return 0;
  }
  priority_queue<int, vector<int>, greater<int>> q;
  for (auto c : mp) {
    q.push(c.second);
  }
  int ans = 0;
  rep(i, mp.size() - k) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
}

Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  map<int, int> mp;
  rep(i, n) { mp[a[i]]++; }
  if (mp.size() <= k) {
    cout << 0 << endl;
    return 0;
  }
  priority_queue<int, vector<int>, greater<int>> q;
  for (auto c : mp) {
    q.push(c.second);
  }
  int ans = 0;
  rep(i, mp.size() - k) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

map<ll, ll> a;
int main() {
  ll n, k;
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    ll x;
    cin >> x;
    a[x]++;
  }
  vector<ll> b;
  for (auto itr = a.begin(); itr != a.end(); itr++) {
    ll now = itr->second;
    b.push_back(now);
  }
  sort(b.begin(), b.end());
  ll ans = 0;
  for (ll i = 0; i < b.size() - k; i++) {
    ans += b[i];
  }
  cout << ans;
  // your code goes here
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

map<ll, ll> a;
int main() {
  ll n, k;
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    ll x;
    cin >> x;
    a[x]++;
  }
  vector<ll> b;
  for (auto itr = a.begin(); itr != a.end(); itr++) {
    ll now = itr->second;
    b.push_back(now);
  }
  sort(b.begin(), b.end());
  ll ans = 0;
  for (ll i = 0; i + k < b.size(); i++) {
    ans += b[i];
  }
  cout << ans;
  // your code goes here
  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> x = {1, -1, 0, 0};
vector<int> y = {0, 0, -1, 1};
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> data(20000);
  rep(i, 0, n) {
    int a;
    cin >> a;
    data[a]++;
  }
  sort(data.begin(), data.end());
  reverse(data.begin(), data.end());
  int sum = 0;
  rep(i, 0, k) { sum += data[i]; }
  cout << n - sum << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> x = {1, -1, 0, 0};
vector<int> y = {0, 0, -1, 1};
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> data(200000);
  rep(i, 0, n) {
    int a;
    cin >> a;
    data[a]++;
  }
  sort(data.begin(), data.end());
  reverse(data.begin(), data.end());
  int sum = 0;
  rep(i, 0, k) { sum += data[i]; }
  cout << n - sum << endl;

  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, ini, n) for (int i = ini; i < n; i++)
#define _rep(i, ini, n) for (int i = ini; i >= n; i--)
#define ToEnd(a) a.begin(), a.end()
uint64_t MOD = 1000000007;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(n, 0, N) cin >> A.at(n);

  map<int, int> mapA;
  for (auto a : A)
    mapA[a]++;

  vector<vector<int>> V(N);
  for (auto _mapa : mapA)
    V.at(_mapa.second).push_back(_mapa.first);

  int s = mapA.size();
  int64_t ans = 0;
  rep(i, 0, s - K) {
    rep(v, 0, N) {
      if (V.at(v).size()) {
        ans += v;
        V.at(v).pop_back();
        break;
      }
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, ini, n) for (int i = ini; i < n; i++)
#define _rep(i, ini, n) for (int i = ini; i >= n; i--)
#define ToEnd(a) a.begin(), a.end()
uint64_t MOD = 1000000007;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(n, 0, N) cin >> A.at(n);

  map<int, int> mapA;
  for (auto a : A)
    mapA[a]++;

  vector<vector<int>> V(N + 1);
  for (auto _mapa : mapA)
    V.at(_mapa.second).push_back(_mapa.first);

  int s = mapA.size();
  int64_t ans = 0;
  rep(i, 0, s - K) {
    rep(v, 0, N) {
      if (V.at(v).size()) {
        ans += v;
        V.at(v).pop_back();
        break;
      }
    }
  }

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

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

using namespace std;

static const int N = 100010;
int n, k, a[N], cnt[N];
priority_queue<int, vector<int>, greater<int>> que;

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i)
    cin >> a[i], ++cnt[a[i]];
  for (int i = 1; i <= n; ++i)
    if (cnt[i])
      que.push(cnt[i]);
  int ans = 0;
  while (que.size() > k)
    ans += que.top(), que.pop();
  cout << ans << endl;
  return 0;
}


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

using namespace std;

static const int N = 200010;
int n, k, a[N], cnt[N];
priority_queue<int, vector<int>, greater<int>> que;

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i)
    cin >> a[i], ++cnt[a[i]];
  for (int i = 1; i <= n; ++i)
    if (cnt[i])
      que.push(cnt[i]);
  int ans = 0;
  while (que.size() > k)
    ans += que.top(), que.pop();
  cout << ans << endl;
  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int a[200005], n, k, b[200005];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  sort(a + 1, a + n + 1);
  int tot = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] != a[i - 1] || i == 1)
      ++tot;
    ++b[tot];
  }
  sort(b + 1, b + tot + 1);
  for (int i = 1; i <= k; ++i) {
    n -= b[tot - i + 1];
  }
  cout << n << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a[200005], n, k, b[200005];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  sort(a + 1, a + n + 1);
  int tot = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] != a[i - 1] || i == 1)
      ++tot;
    ++b[tot];
  }
  sort(b + 1, b + tot + 1);
  k = min(tot, k);
  for (int i = 1; i <= k; ++i) {
    n -= b[tot - i + 1];
  }
  cout << n << endl;
  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int qt[100005];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    qt[a]++;
  }
  set<pair<int, int>> s;
  for (int i = 1; i <= n; i++) {
    s.insert({qt[i], i});
  }
  int ans = 0;
  while (s.size() > k) {
    auto a = *s.begin();
    ans += a.first;
    s.erase(s.begin());
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int qt[200005];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    qt[a]++;
  }
  set<pair<int, int>> s;
  for (int i = 1; i <= n; i++) {
    s.insert({qt[i], i});
  }
  int ans = 0;
  while (s.size() > k) {
    auto a = *s.begin();
    ans += a.first;
    s.erase(s.begin());
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03497 (C++)

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

int main() {
  ios_base::sync_with_stdio(false);
  int n, k, a[20000], x[20000];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    x[a[i] - 1]++;
  }
  sort(x, x + n);
  int ans = n;
  for (int i = 0; i < k; i++) {
    ans -= x[n - i - 1];
  }
  cout << ans;
  return 0;
}

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

int main() {
  ios_base::sync_with_stdio(false);
  int n, k, a[200000], x[200000];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    x[a[i] - 1]++;
  }
  sort(x, x + n);
  int ans = n;
  for (int i = 0; i < k; i++) {
    ans -= x[n - i - 1];
  }
  cout << ans;
  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void solve() {
  ll n, k;
  cin >> n >> k;
  vector<ll> v(20002);
  rep(i, n) {
    ll a;
    cin >> a;
    v[a]++;
  }
  sort(ALL(v), greater<>());
  ll num = 0;
  rep(i, k) { num += v[i]; }
  cout << n - num << endl;
}

int main() {
  solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void solve() {
  ll n, k;
  cin >> n >> k;
  vector<ll> v(200002);
  rep(i, n) {
    ll a;
    cin >> a;
    v[a]++;
  }
  sort(ALL(v), greater<>());
  ll num = 0;
  rep(i, k) { num += v[i]; }
  cout << n - num << endl;
}

int main() {
  solve();
  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T> void print(const T &v);

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  map<int, int> mp;
  rep(i, N) { mp[A[i]]++; }
  vector<int> v;
  for (auto m : mp) {
    v.push_back(m.second);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  int ans = N;
  for (int i = 0; i < K; i++) {
    ans -= v[i];
  }
  cout << ans << endl;
  return 0;
}

// Use For Debug
template <typename T> void print(T const &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << " ";
    cout << v[i];
  }
  cout << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T> void print(const T &v);

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  map<int, int> mp;
  rep(i, N) { mp[A[i]]++; }
  vector<int> v;
  for (auto m : mp) {
    v.push_back(m.second);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  int ans = N;
  for (int i = 0; i < K; i++) {
    if (v.size() <= i) {
      cout << 0 << endl;
      return 0;
    }
    ans -= v[i];
  }
  cout << ans << endl;
  return 0;
}

// Use For Debug
template <typename T> void print(T const &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << " ";
    cout << v[i];
  }
  cout << endl;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 2e9
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];

  sort(ALL(a));
  vector<int> cnt;
  int c = 1;
  REP(i, n) {
    if (i == 0)
      continue;
    if (a[i - 1] == a[i])
      c++;
    if (a[i - 1] != a[i] || i == n - 1) {
      cnt.push_back(c);
      c = 1;
    }
  }
  sort(ALL(cnt), greater<int>());
  int ans = n;
  REP(i, k) ans -= cnt[i];
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 2e9
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];

  sort(ALL(a));
  vector<int> cnt;
  int c = 1;
  REP(i, n) {
    if (i == 0)
      continue;
    if (a[i - 1] == a[i])
      c++;
    if (a[i - 1] != a[i] || i == n - 1) {
      cnt.push_back(c);
      c = 1;
    }
  }
  sort(ALL(cnt), greater<int>());
  int ans = n;
  if (cnt.size() < k)
    cout << 0 << endl;
  else {
    REP(i, k) ans -= cnt[i];
    cout << ans << endl;
  }

  return 0;
}
Problem p03497 (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> cnt;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    ++cnt[a];
  }
  vector<int> a;
  for (auto &p : cnt)
    a.push_back(p.second);
  sort(begin(a), end(a));

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

  return 0;
}


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

int main(void) {
  int N, K;
  cin >> N >> K;
  map<int, int> cnt;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    ++cnt[a];
  }
  vector<int> a;
  for (auto &p : cnt)
    a.push_back(p.second);
  sort(begin(a), end(a));

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

  return 0;
}
Problem p03497 (C++)

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

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  unordered_map<int, int> m;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    m[a]++;
  }

  vector<int> c;
  for (auto p : m)
    c.push_back(p.second);
  sort(c.begin(), c.end(), greater<int>());

  int s = 0;
  for (int i = 0; i < n && i < k; i++)
    s += c[i];
  printf("%d\n", n - s);

  return 0;
}

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

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  unordered_map<int, int> m;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    m[a]++;
  }

  vector<int> c;
  for (auto p : m)
    c.push_back(p.second);
  sort(c.begin(), c.end(), greater<int>());

  int s = 0;
  for (int i = 0; i < c.size() && i < k; i++)
    s += c[i];
  printf("%d\n", n - s);

  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
// by sdfzchy
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long LL;
const int inf = (1 << 30), N = 100010;
int n, m;
inline int in() {
  char ch = getchar();
  int f = 1, tmp = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    tmp = (tmp << 1) + (tmp << 3) + (ch - '0');
    ch = getchar();
  }
  return tmp * f;
}
int cnt[N], k, ans;
int main() {
  n = in(), k = in();
  for (int i = 1; i <= n; i++)
    cnt[in()]++;
  sort(cnt + 1, cnt + n + 1);
  for (int i = n; i >= n - k + 1; i--)
    ans += cnt[i];
  printf("%d\n", n - ans);
  return 0;
}


Fixed submission:
// by sdfzchy
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long LL;
const int inf = (1 << 30), N = 300010;
int n, m;
inline int in() {
  char ch = getchar();
  int f = 1, tmp = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    tmp = (tmp << 1) + (tmp << 3) + (ch - '0');
    ch = getchar();
  }
  return tmp * f;
}
int cnt[N], k, ans;
int main() {
  n = in(), k = in();
  for (int i = 1; i <= n; i++)
    cnt[in()]++;
  sort(cnt + 1, cnt + n + 1);
  for (int i = n; i >= n - k + 1; i--)
    ans += cnt[i];
  printf("%d\n", n - ans);
  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (n); i++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n, k;

int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  map<int, int> mp;
  FOR(i, n) {
    int x;
    cin >> x;
    mp[x]++;
  }
  vector<int> v;
  FORR(x, mp) v.push_back(x.second);
  sort(ALL(v));
  int ret = 0;
  FOR(i, v.size() - k) ret += v[i];
  cout << ret << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (n); i++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n, k;

int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  map<int, int> mp;
  FOR(i, n) {
    int x;
    cin >> x;
    mp[x]++;
  }
  vector<int> v;
  FORR(x, mp) v.push_back(x.second);
  sort(ALL(v));
  int ret = 0;
  FOR(i, (int)v.size() - k) ret += v[i];
  cout << ret << endl;
  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
inline int D() {
  int m;
  cin >> m;
  return m;
}
inline ll lD() {
  ll m;
  cin >> m;
  return m;
}
inline double dD() {
  double m;
  cin >> m;
  return m;
}
int fr[100006];
int main() {
  int n = D(), k = D();
  for (int i = 0; i < n; ++i) {
    int a = D();
    fr[a]++;
  }
  vector<int> v;
  for (int i = 1; i <= n; ++i) {
    if (fr[i] != 0)
      v.push_back(fr[i]);
  }
  sort(v.rbegin(), v.rend());
  int c = 0;
  for (int i = k; i < v.size(); ++i)
    c += v[i];
  cout << c << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
inline int D() {
  int m;
  cin >> m;
  return m;
}
inline ll lD() {
  ll m;
  cin >> m;
  return m;
}
inline double dD() {
  double m;
  cin >> m;
  return m;
}
int fr[1000006];
int main() {
  int n = D(), k = D();
  for (int i = 0; i < n; ++i) {
    int a = D();
    fr[a]++;
  }
  vector<int> v;
  for (int i = 1; i <= n; ++i) {
    if (fr[i] != 0)
      v.push_back(fr[i]);
  }
  sort(v.rbegin(), v.rend());
  int c = 0;
  for (int i = k; i < v.size(); ++i)
    c += v[i];
  cout << c << endl;
}
Problem p03497 (C++)

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

using namespace std;

set<int> s;
int n, k, t;
int cnt[200001];

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

  cin >> n >> k;

  for (int i = 0; i < n; i++) {
    cin >> t;
    s.insert(t);
    cnt[t]++;
  }

  vector<int> v;
  for (auto it : s) {
    v.push_back(cnt[it]);
  }
  sort(v.begin(), v.end());

  int res = 0;

  for (int i = 0; i < s.size() - k; i++) {
    // cout << v[i] << '\n';
    res += v[i];
  }

  cout << res << '\n';

  return 0;
}

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

using namespace std;

set<int> s;
int n, k, t;
int cnt[200001];

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

  cin >> n >> k;

  for (int i = 0; i < n; i++) {
    cin >> t;
    s.insert(t);
    cnt[t]++;
  }

  vector<int> v;
  for (auto it : s) {
    v.push_back(cnt[it]);
  }
  sort(v.begin(), v.end());

  int res = 0;
  int m = s.size();
  for (int i = 0; i < m - k; i++) {
    // cout << v[i] << '\n';
    res += v[i];
  }

  cout << res << '\n';

  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <complex>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010

int main() {
  int n, k;
  int counter[SIZE] = {};

  scanf("%d%d", &n, &k);

  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    counter[a]++;
  }

  sort(counter, counter + SIZE, greater<int>());

  int ans = n;

  for (int i = 0; i < SIZE; i++) {
    if (k) {
      ans -= counter[i];
      k -= counter[i] > 0;
    }
  }

  printf("%d\n", ans);

  return 0;
}


Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <complex>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 200010

int main() {
  int n, k;
  int counter[SIZE] = {};

  scanf("%d%d", &n, &k);

  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    counter[a]++;
  }

  sort(counter, counter + SIZE, greater<int>());

  int ans = n;

  for (int i = 0; i < SIZE; i++) {
    if (k) {
      ans -= counter[i];
      k -= counter[i] > 0;
    }
  }

  printf("%d\n", ans);

  return 0;
}
Problem p03497 (C++)

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

#define ll long long
#define INF 99999999
#define rep(i, n) for (int i = 0, temp = (int)(n); i < temp; ++i)
#define repi(i, start, end) for (int i = start, temp = (int)(end); i < end; ++i)
#define rfor(v, x) for (const auto &x : v) // xは値を表す
#define all(x) (x).begin(), (x).end()
#define SORT(v, n) sort(v, v + n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v, lambda) sort(v.begin(), v.end(), lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v)                                                                 \
  rep(i, v.size()) { cin >> v[i]; }
// 最終奥義
// #define int long long
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int ctoi(char c) { return c - '0'; }
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }

signed main(void) {
  int n, k;
  cin >> n >> k;
  multiset<int> a;
  vint ans;
  rep(i, n) {
    int t;
    cin >> t;
    a.insert(t);
  }
  rep(i, n + 1) {
    if (a.find(i) != a.end()) {
      ans.push_back(a.count(i));
      // cout << ans.back() << endl;
    }
  }
  vfsort(ans, ([](int x, int y) -> int { return x > y; }));
  int res = n;
  rep(i, k) { res -= ans[i]; }
  cout << res << endl;

  return 0;
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for (int i = 0, temp = (int)(n); i < temp; ++i)
#define repi(i, start, end) for (int i = start, temp = (int)(end); i < end; ++i)
#define rfor(v, x) for (const auto &x : v) // xは値を表す
#define all(x) (x).begin(), (x).end()
#define SORT(v, n) sort(v, v + n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v, lambda) sort(v.begin(), v.end(), lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v)                                                                 \
  rep(i, v.size()) { cin >> v[i]; }
// 最終奥義
// #define int long long
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int ctoi(char c) { return c - '0'; }
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }

signed main(void) {
  int n, k;
  cin >> n >> k;
  multiset<int> a;
  vint ans;
  rep(i, n) {
    int t;
    cin >> t;
    a.insert(t);
  }
  rep(i, n + 1) {
    if (a.find(i) != a.end()) {
      ans.push_back(a.count(i));
      // cout << ans.back() << endl;
    }
  }
  vfsort(ans, ([](int x, int y) -> int { return x > y; }));
  if (ans.size() < k) {
    cout << 0 << endl;
    return 0;
  }
  int res = n;
  rep(i, k) { res -= ans[i]; }
  cout << res << endl;

  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MAIN 200010
using namespace std;
int main() {
  int n, k;
  while (cin >> n >> k) {
    map<int, int> mps;
    for (int i = 1; i <= n; i++) {
      int tmp;
      cin >> tmp;
      mps[tmp]++;
    }
    vector<int> vec;
    for (auto ret : mps)
      vec.push_back(ret.second);
    sort(vec.begin(), vec.end());
    int ans = 0;
    if (mps.size() - k > 0)
      for (int i = 0; i < mps.size() - k; i++)
        ans += vec[i];
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define MAIN 200010
using namespace std;
int main() {
  int n, k;
  while (cin >> n >> k) {
    map<int, int> mps;
    for (int i = 1; i <= n; i++) {
      int tmp;
      cin >> tmp;
      mps[tmp]++;
    }
    vector<int> vec;
    for (auto ret : mps)
      vec.push_back(ret.second);
    sort(vec.begin(), vec.end());
    int ans = 0, num = mps.size();
    if (num <= k) {
      cout << "0" << endl;
      continue;
    }
    for (int i = 0; i < num - k; i++)
      ans += vec[i];
    cout << ans << endl;
  }
  return 0;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define N 100010
int k, n, m, p, a[N], c[N];
int Ans, x;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &x), c[x]++;
  for (int i = 1; i <= n; i++)
    if (c[i])
      a[++m] = c[i];
  sort(a + 1, a + m + 1);
  for (int i = 1; i <= m - k; i++)
    Ans += a[i];
  cout << Ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define N 200010
int k, n, m, p, a[N], c[N];
int Ans, x;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &x), c[x]++;
  for (int i = 1; i <= n; i++)
    if (c[i])
      a[++m] = c[i];
  sort(a + 1, a + m + 1);
  for (int i = 1; i <= m - k; i++)
    Ans += a[i];
  cout << Ans << endl;
  return 0;
}
Problem p03497 (C++)

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

int main() {
  long n, k;
  cin >> n >> k;
  map<int, int> a;
  vector<int> b;
  long ans = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a[t]++;
  }
  if (a.size() <= k) {
    cout << 0;
  } else {
    for (auto i = a.begin(); i != a.end(); i = next(i, 1)) {
      b.push_back(i->second);
    }
    sort(b.begin(), b.end());
    while (b.size() > k) {
      ans += b.front();
      b.erase(b.begin());
    }
    cout << ans;
  }

  return 0;
}


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

int main() {
  long n, k;
  cin >> n >> k;
  map<int, int> a;
  vector<int> b;
  long ans = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a[t]++;
  }
  if (a.size() <= k) {
    cout << 0;
  } else {
    for (auto i = a.begin(); i != a.end(); i = next(i, 1)) {
      b.push_back(i->second);
    }
    sort(b.begin(), b.end());
    ans = accumulate(b.begin(), b.begin() + b.size() - k, 0);
    cout << ans;
  }

  return 0;
}
Problem p03497 (C++)

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

using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);

  int n, k;
  cin >> n >> k;

  map<int, int> mp;

  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;

    mp[x]++;
  }

  vi v;

  for (auto &pr : mp)
    v.push_back(pr.second);

  sort(v.rbegin(), v.rend());

  int ans = 0;

  for (int i = k; i < n; i++)
    ans += v[i];

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

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

using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);

  int n, k;
  cin >> n >> k;

  map<int, int> mp;

  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;

    mp[x]++;
  }

  vi v;

  for (auto &pr : mp)
    v.push_back(pr.second);

  sort(v.rbegin(), v.rend());

  int ans = 0;

  for (int i = k; i < int(v.size()); i++)
    ans += v[i];

  cout << ans << endl;
  return 0;
}
Problem p03497 (Python)

Buggy submission (status: Time Limit Exceeded):
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
c = Counter(A).most_common()[::-1]

ans = 0
while len(c) > K:
    res = c.pop(0)
    ans += res[1]
print(ans)


Fixed submission:
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
c = Counter(A).most_common()[::-1]

ans = 0
if len(c) > K:
    for i in range(len(c) - K):
        ans += c[i][1]

print(ans)
Problem p03497 (Python)

Buggy submission (status: Runtime Error):
from collections import Counter

n, m = map(int, input().split())
dic = Counter(map(int, input().split()))
lis = sorted(dic.items(), key=lambda x: x[1], reverse=True)

res = 0
for i in range(m):
    res += lis[i][1]
print(n - res)


Fixed submission:
from collections import Counter

n, m = map(int, input().split())
dic = Counter(map(int, input().split()))
lis = sorted(dic.items(), key=lambda x: x[1], reverse=True)

res = 0
for i in range(min(m, len(lis))):
    res += lis[i][1]
print(n - res)
Problem p03497 (Python)

Buggy submission (status: Time Limit Exceeded):
n, k = map(int, input().split())
L = list(map(int, input().split()))
d = {}
for a in L:
    if a not in d:
        d[a] = 1
    else:
        d[a] += 1
l = []
for v in d.values():
    l.append(v)

if len(l) <= k:
    print(0)
else:
    ans = float("inf")
    for i in range(2 ** len(l)):
        b = [0] * len(l)
        for j in range(len(l)):
            if (i >> j) & 1:
                b[j] = 1
        if b.count(1) <= k:
            cnt = 0
            for m in range(len(l)):
                if b[m] == 0:
                    cnt += l[m]
            ans = min(ans, cnt)
    print(ans)


Fixed submission:
n, k = map(int, input().split())
L = list(map(int, input().split()))
d = {}
for a in L:
    if a not in d:
        d[a] = 1
    else:
        d[a] += 1
l = []
for v in d.values():
    l.append(v)
l.sort(reverse=True)
print(n - sum(l[:k]))
Problem p03497 (Python)

Buggy submission (status: Runtime Error):
from collections import Counter

n, k = map(int, input().split())
(*a,) = map(int, input().split())

c = Counter(a)
kv = sorted(c.items(), key=lambda x: x[1], reverse=True)

if n <= k:
    print(0)
else:
    ans = n
    for i in range(k):
        ans -= kv[i][1]
    print(ans)


Fixed submission:
from collections import Counter

n, k = map(int, input().split())
(*a,) = map(int, input().split())

c = Counter(a)
kv = sorted(c.items(), key=lambda x: x[1], reverse=True)

if n <= k:
    print(0)
else:
    ans = n
    for i in range(k):
        try:
            ans -= kv[i][1]
        except:
            pass
    print(ans)
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
inline int read() // 不管是正负数，都可以
{
  int x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      positive = 0;
  for (; isdigit(ch); ch = getchar())
    x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(int a) {
  if (a >= 10)
    write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(int a) {
  write(a);
  puts("");
}
#include <cmath>
#include <map>
const int N = 100005;
map<int, int> M;
map<int, int>::iterator it;
int n, k, a[N], que[N], r, ans;
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; i++)
    a[i] = read();
  for (int i = 1; i <= n; i++)
    M[a[i]]++;
  for (it = M.begin(); it != M.end(); it++) {
    que[++r] = it->second;
  }
  sort(&que[1], &que[r + 1]);
  for (int i = 1; i + k <= r; i++) {
    ans += que[i];
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
inline int read() // 不管是正负数，都可以
{
  int x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      positive = 0;
  for (; isdigit(ch); ch = getchar())
    x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(int a) {
  if (a >= 10)
    write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(int a) {
  write(a);
  puts("");
}
#include <cmath>
#include <map>
const int N = 200005;
map<int, int> M;
map<int, int>::iterator it;
int n, k, a[N], que[N], r, ans;
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; i++)
    a[i] = read();
  for (int i = 1; i <= n; i++)
    M[a[i]]++;
  for (it = M.begin(); it != M.end(); it++) {
    que[++r] = it->second;
  }
  sort(&que[1], &que[r + 1]);
  for (int i = 1; i + k <= r; i++) {
    ans += que[i];
  }
  cout << ans << endl;
}