ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Code 1:
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;


void solver() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int input; cin >> input;
    while(input--) {
        int n, k; cin >> n >> k;
        map<int, int> map;
        int num;
        for(int i = 0; i < n; i++) {
            cin >> num;
            map[num]++;
        }

        vector<int> vec;
        for(auto ele: map) vec.push_back(ele.second);
        sort(vec.begin(), vec.end());

        int passes = vec.size();

        for(int i = 0; k > 0 && i < vec.size() - 1; i++) {
            int temp = min(vec[i], k);
            vec[i] -= temp;
            k -= temp;
            if(vec[i] == 0) passes--;
        }

        cout << passes << "\n";
    }
}


int main(){

    solver();

}


Code 2:
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;


void solver() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int input; cin >> input;
    while(input--) {
        int n, k; cin >> n >> k;
        unordered_map<int, int> map;
        int num;
        for(int i = 0; i < n; i++) {
            cin >> num;
            map[num]++;
        }

        vector<int> vec;
        for(auto ele: map) vec.push_back(ele.second);
        sort(vec.begin(), vec.end());

        for(int i = 0; k > 0 && i < vec.size() - 1; i++) {
            int temp = min(vec[i], k);
            vec[i] -= temp;
            k -= temp;
            vec[vec.size() - 1] += temp;
        }

        int passes = 0;
        for(int i = 0; i < vec.size() - 1; i++) passes += (vec[i] > 0);
        cout << passes + 1 << "\n";
    }
}


int main(){

    solver();

}


Answer: 1
Problem: 2057B - Gorilla and the Exam
Language: c++23 

Code 1:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t ;
    cin >> t;
    while (t--)
    {
        int  n;
        int k;
        cin >> n >> k;
        int arr[n];
        for ( int i = 0 ; i < n ; i++){
            cin >> arr[i];
        }
        sort(arr, arr + n);
      	int cnt = 1;
      	vector<int> frequency;
        for( int j = 1 ; j < n ; j++){
          	if(arr[j]!=arr[j-1]){
              	frequency.push_back(cnt);
                cnt=1;
            }
        	cnt++;
    	}
      	sort(frequency.begin(), frequency.end());
      	int ans = frequency.size();
      	for( int i = 0 ; i*1ULL < frequency.size() ; i++){
          if( k >= frequency[i] ) {
            k -= frequency[i];
            ans--;
          }
        }
      cout << ans << endl;
    }
  
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t ;
    cin >> t;
    while (t--)
    {
        int  n;
        int k;
        cin >> n >> k;
        int arr[n];
        for ( int i = 0 ; i < n ; i++){
            cin >> arr[i];
        }
        sort(arr, arr + n);
      	int cnt = 1;
      	vector<int> frequency;
        for( int j = 1 ; j < n ; j++){
          	if(arr[j]!=arr[j-1]){
              	frequency.push_back(cnt);
                cnt=0;
            }
        	cnt++;
    	}
        	frequency.push_back(cnt);
      	sort(frequency.begin(), frequency.end());
      	int ans = frequency.size();
      	for( int i = 0 ; i < frequency.size() ; i++){
          if( k >= frequency[i] ) {
            k -= frequency[i];
            ans--;
          }else{
            break;
          }
        }
      cout << max(ans, 1) << endl;
    }
  
    return 0;
}

Answer: 2
Problem: 2057B - Gorilla and the Exam
Language: c++23 

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

int main(void)
{
    int T;
    cin >> T;
    while(T--)
    {
        int n,k;
        cin >> n >> k;
        vector<int> a(n);
        for(int i=0;i<n;i++)
        {
            cin >> a[i];
        }
        sort(a.begin(),a.end());
        vector<int> cnt={1};
        for(int i=1;i<n;i++)
        {
            if(a[i]==a[i-1])
            {
                cnt.back()++;
            }else
            {
                cnt.emplace_back(1);
            }
        }
        sort(cnt.begin(),cnt.end());
        int m=cnt.size();
        for(int i=0;i<m;i++)
        {
            if(k<cnt[i])
            {
                cout << m-i << endl;
                continue;
            }
            k-=cnt[i];
        }
        cout << 1 << endl;
    }
}

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

int main(void)
{
    int T;
    cin >> T;
    while(T--)
    {
        int n,k;
        cin >> n >> k;
        vector<int> a(n);
        for(int i=0;i<n;i++)
        {
            cin >> a[i];
        }
        sort(a.begin(),a.end());
        vector<int> cnt={1};
        for(int i=1;i<n;i++)
        {
            if(a[i]==a[i-1])
            {
                cnt.back()++;
            }else
            {
                cnt.emplace_back(1);
            }
        }
        sort(cnt.begin(),cnt.end());
        int m=cnt.size();
        for(int i=0;i<m;i++)
        {
            if(k<cnt[i])
            {
                cout << m-i << endl;
                k=-1;
                break;
            }
            k-=cnt[i];
        }
        if(k>=0) cout << 1 << endl;
    }
}

Answer: 2
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Code 1:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t; // number of test cases
    cin >> t;
    while (t--) {
        int n, k;
        cin>>n>>k;
        vector<int> a(n);
        map<int , int> n2r; 
        for(int i = 0; i<n; i++){
            cin>>a[i];
            n2r[a[i]] += 1;
        }
        vector<int> f;
        for(auto pr : n2r){
            f.push_back(pr.second);
        }
        sort(f.begin(), f.end(), greater<int>());
        int ans = 0;
        if(k == 0){
            cout<<n2r.size()<<endl;
        }
        else if(k == n){
            cout<<1<<endl;
        }
        else{
            if((n - f[0]) %k !=0){
                ans = ((n - f[0])/k)  + 1;
            }
            else{
                ans = (n - f[0])/k;
            }
            

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

Code 2:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t; // number of test cases
    cin >> t;
    while (t--) {
        int n, k;
        cin>>n>>k;
        vector<int> a(n);
        
        for(int i = 0; i<n; i++){
            cin>>a[i];           
        }
        sort(a.begin(), a.end());
        vector<int> fq;
        fq.push_back(1);
        for(int i = 1; i<n; i++){
            if(a[i] == a[i-1]){
                fq.back()++;
            }
            else{
                fq.push_back(1);
            }
        }
        sort(fq.begin(), fq.end());
        int s = fq.size();
        bool done = false;
        int tk = k;
        for(int i = 0; i<s-1; i++){
            
            if(fq[i] > k){
                cout<<s-i<<endl;
                done = true;
                break;
            }
            k -= fq[i];
        }
        if(!done){
            cout<<1<<endl;
        }
        
        
        
        
    }
    return 0;
}

Answer: 2
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Code 1:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod=1e9+7;
void solve(){
    int n,k;cin>>n>>k;
    vector<int>a(n);
    vector<int>cnt={1};
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1]){
            cnt.back()++;
        }
        else{
            cnt.emplace_back(1);
        }
    }
    sort(cnt.begin(),cnt.end());
    for(int i=0;i<cnt.size()-1;i++){
        if(cnt[i]>k){
            cout<<cnt.size()-i<<'\n';
            return;
        }
        k-=cnt[i];
    }
    cout<<1<<'\n';
}
int main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod=1e9+7;
void solve(){
    int n,k;cin>>n>>k;
    vector<int>a(n);
    vector<int>cnt(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    if(k>=n)cout<<1<<'\n';
    else{
        sort(a.begin(),a.end());
        int j=0;
        for(int i=0;i<n;){
            while(a[j]==a[i]){
                cnt[j]++;
                i++;
            }
            j++;
        }
        int ans=0;
        sort(cnt.begin(),cnt.begin()+j);
        for(int i=0;i<cnt.size();i++){
            if(cnt[i])ans++;
        }

        for(int i=0;i<cnt.size();i++){
            if(cnt[i]!=0&&k>=cnt[i]){
                k-=cnt[i];
                ans--;
            }
        }
        cout<<ans<<'\n';
    }
}
int main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Answer: 1
Problem: 2057B - Gorilla and the Exam
Language: c++20 

Code 1:
#include <bits/stdc++.h>
#define int long long
using namespace std;

void solve()
{
    int n, k;
    cin >> n >> k;
    
    unordered_map<int, int> mp;
    for(int i = 0; i < n; i++) {
        int el;
        cin >> el;
        
        mp[el]++;
    }
    
    if(k == n || k == n-1){
        cout << 1 << '\n';
        return ;
    }
    
    vector<int> a;
    for(auto [i, cnt] : mp){
        a.push_back(cnt);
    }
    
    sort(a.begin(), a.end());
    
    int cnt = 0;
    for(int i = 0; i < a.size(); i++){
        
        if(k <= 0) {
            cnt++;
            continue;
        }
        
        if(a[i] >= k){
            a[i] -= k;
            k = 0;
        }else{
            k -= a[i];
            a[i] = 0;
        }
        
        if(a[i] != 0) {
            cnt++;
        }
    }
    
    cout << cnt << '\n';
}

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

    int t = 1;
    cin >> t;

    while (t--)
    {
        solve();
    }

    return 0;
}

Code 2:
#include <bits/stdc++.h>
#define int long long
using namespace std;

void solve()
{
    int n, k;
    cin >> n >> k;
    
    vector<int> a(n, 0);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    if(k == n || k == n-1){
        cout << 1 << '\n';
        return ;
    }
    
    sort(a.begin(), a.end());
    vector<int> b = {1};
    for(int i = 1; i < n; i++){
        if(a[i] == a[i-1]){
            b.back()++;
        }else b.push_back(1);
    }
    
    sort(b.begin(), b.end());
    
    int cnt = 0;
    for(int i = 0; i < b.size(); i++){
        
        if(k <= 0) {
            cnt++;
            continue;
        }
        
        if(b[i] >= k){
            b[i] -= k;
            k = 0;
        }else{
            k -= b[i];
            b[i] = 0;
        }
        
        if(b[i] != 0) {
            cnt++;
        }
    }
    
    cout << cnt << '\n';
}

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

    int t = 1;
    cin >> t;

    while (t--)
    {
        solve();
    }

    return 0;
}

Answer: 2
Problem: 2057B - Gorilla and the Exam
Language: c++20 

Code 1:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    while(t --)
    {
        int n,m;

        unordered_map<ll,ll> cnt;
        vector<pair<ll,ll>> s;

        cin >> n >> m;
        int idx = 0;

        for(int i = 0;i<n;i++)
        {
            ll a;
            cin >> a;
            if(cnt[a] == 0)
            {
                cnt[a] = idx+1;
                s.push_back({0,a});
                idx ++;
            }
            s[cnt[a] - 1].first ++;
        }

        sort(s.begin(),s.begin()+idx);


        int idx2 = 0;

        int ans = 0;
        while(idx2 < idx && m > 0)
        {
            if(m >= s[idx2].first)
            {
                m -= s[idx2].first;
                s[idx2 ++].first = 0;
            }
        }
        
        for(int i = 0;i<idx;i++)
        {
            if(s[i].first != 0) ans ++;
        }

        cout << max(ans,1) << "\n";

    }
    
    return 0;
}

Code 2:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    while(t --)
    {
        int n,m;

        map<ll,ll> cnt;
        vector<pair<ll,ll>> s;

        cin >> n >> m;
        int idx = 0;

        for(int i = 0;i<n;i++)
        {
            ll a;
            cin >> a;
            if(cnt[a] == 0)
            {
                cnt[a] = idx+1;
                s.push_back({0,a});
                idx ++;
            }
            s[cnt[a] - 1].first ++;
        }

        sort(s.begin(),s.end());
        int idx2 = 0;

        int ans = 0;
        while(idx2 < idx && m > 0)
        {
            if(m >= s[idx2].first)
            {
                m -= s[idx2].first;
                s[idx2].first = 0;
            }
            idx2 ++;
        }
        
        for(int i = 0;i<idx;i++)
        {
            if(s[i].first != 0) ans ++;
        }

        cout << max(ans,1) << "\n";

    }
    
    return 0;
}

Answer: 2
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Code 1:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef pair<int,int> PII;
const int N=1e5+10;
int n,k;
void solve(){
	scanf("%d%d",&n,&k);
	map<int,int> mp;
	int mx=0;
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		mp[x]++;
	}
	vector<int> v;
	for(auto &a:mp) v.push_back(a.second);
	sort(v.begin(),v.end());
	for(int i=0;i<v.size()-1;i++,k-=v[i]){
		if(k<v[i]){
			printf("%d\n",v.size()-i);
			return;
		}
	}
	puts("1");
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) solve();
} 


Code 2:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef pair<int,int> PII;
const int N=1e5+10;
int n,k;
void solve(){
	scanf("%d%d",&n,&k);
	map<int,int> mp;
	int mx=0;
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		mp[x]++;
	}
	vector<int> v;
	for(auto &a:mp) v.push_back(a.second);
	sort(v.begin(),v.end());
	int m=v.size();
	for(int i=0;i<m-1;i++){
		if(k<v[i]){
			printf("%d\n",m-i);
			return;
		}
		k-=v[i];
	}
	puts("1");
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) solve();
} 


Answer: 2
Problem: 2057B - Gorilla and the Exam
Language: python

Code 1:
import sys
from collections import Counter

input = sys.stdin.readline
output = sys.stdout.write
str_input = lambda: input().strip()
int_input = lambda: int(input())
multi_int_input = lambda: map(int, input().split())
list_input = lambda: list(map(int, input().split()))
P1 = lambda X: result_array.append(f"{X}\n")
P2 = lambda X,Y: result_array.append(f"{X} {Y}\n")
P3 = lambda X,Y,Z: result_array.append(f"{X} {Y} {Z}\n")
PA = lambda X: result_array.append(f"{' '.join(map(str,X))}\n")


def solve(test_case):
    N,K = multi_int_input()
    arr = list_input()

    check = Counter()
    for i in arr:
        check[str(i)] += 1
    check = sorted(check.values(),reverse=True)

    while check:
        if check[-1] <= K:
            K -= check.pop()
        else:
            break
    
    P1(max(1,len(check)))


tc = 1
tc = int_input()
result_array = []
for test_case in range(1,tc+1):
    solve(test_case)
output(''.join(result_array))

Code 2:
import sys
from collections import Counter

input = sys.stdin.readline
output = sys.stdout.write
str_input = lambda: input().strip()
int_input = lambda: int(input())
multi_int_input = lambda: map(int, input().split())
list_input = lambda: list(map(int, input().split()))
P1 = lambda X: result_array.append(f"{X}\n")
P2 = lambda X,Y: result_array.append(f"{X} {Y}\n")
P3 = lambda X,Y,Z: result_array.append(f"{X} {Y} {Z}\n")
PA = lambda X: result_array.append(f"{' '.join(map(str,X))}\n")


def solve(test_case):
    N,K = multi_int_input()
    arr = list_input()

    check = sorted(Counter(arr).values(),reverse=True)

    while check:
        if check[-1] <= K:
            K -= check.pop()
        else:
            break
    
    P1(max(1,len(check)))


tc = 1
tc = int_input()
result_array = []
for test_case in range(1,tc+1):
    solve(test_case)
output(''.join(result_array))

Answer: 1
Problem: 2057B - Gorilla and the Exam
Language: java

Code 1:
// Gorilla and the exam

import java.util.*;

public class _2057B {
    public static void sovle(int k, int arr[]) {
        Arrays.sort(arr);
        List<Integer> cnt = new ArrayList<>();
        cnt.add(1);
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] == arr[i - 1]) {
                cnt.set(cnt.size() - 1, cnt.get(cnt.size() - 1) + 1);
            } else {
                cnt.add(1);
            }
        }

        Collections.sort(cnt);
        int m = cnt.size();
        for (int i = 0; i < m - 1; i++) {
            if (cnt.get(i) > k) {
                System.out.println(m - i);
                return;
            }
            k -= cnt.get(i);
        }
        System.out.println(1);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();

            int arr[] = new int[n];

            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }

            sovle(k, arr);

            t--;
        }
        sc.close();
    }
}

Code 2:
// Gorilla and the exam

import java.util.*;

public class _2057B {
    public static void sovle(int k, int arr[]) {
        Arrays.sort(arr);
        List<Integer> cnt = new ArrayList<>();
        cnt.add(1);
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] == arr[i - 1]) {
                cnt.set(cnt.size() - 1, cnt.get(cnt.size() - 1) + 1);
            } else {
                cnt.add(1);
            }
        }

        Collections.sort(cnt);
        for (int i = 0; i < cnt.size(); i++) {
            System.out.println(cnt.get(i));
        }
        int m = cnt.size();
        for (int i = 0; i < m - 1; i++) {
            if (cnt.get(i) > k) {
                System.out.println(m - i);
                return;
            }
            k -= cnt.get(i);
        }
        System.out.println(1);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();

            int arr[] = new int[n];

            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }

            sovle(k, arr);

            t--;
        }
        sc.close();
    }
}

Answer: 1
Problem: 2057B - Gorilla and the Exam
Language: c++23 

Code 1:
#include<iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main(){
    int t ; cin>>t;
    while(t--){
        int n , k ; cin>>n>>k ;
        vector<int> a ;
        map<int,int> m ; 
        for(int i = 0 ; i< n ; i++) {
            int x ; cin>>x ;
            a.push_back(x);
            m[x]++ ;
        }
        vector<int> x ; 
        for(auto i : m){
            x.push_back(i.second);
        }
        sort(x.begin() , x.end());
        int ans = x.size();
        for(auto i : x){
            if(k >= i){
                ans--;
                k-=i;
            }
        }
        cout<<ans<<endl;

    }
    return 0 ;
}

Code 2:
#include<iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main(){
    int t ; cin>>t;
    while(t--){
        int n , k ; cin>>n>>k ;
        vector<int> a ;
        map<int,int> m ; 
        for(int i = 0 ; i< n ; i++) {
            int x ; cin>>x ;
            a.push_back(x);
            m[x]++ ;
        }
        vector<int> x ; 
        for(auto i : m){
            x.push_back(i.second);
        }
        sort(x.begin() , x.end());
        int ans = x.size();
        for(auto i : x){
            if(k >= i){
                ans--;
                k-=i;
            }
        }
        cout<<max(ans,1)<<endl;

    }
    return 0 ;
}

Answer: 2
Problem: 2057B - Gorilla and the Exam
Language: c++23 

Code 1:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, k;
        cin >> n >> k;
        int a[n];
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        sort(a, a + n);
        int y = a[0];
        int countt = 1;
        int b[n] = {0};
        for (int i = 1; i < n; i++)
        {
            if(y == a[i])
            {
                countt++;
            }
            else
            {
                b[countt - 1]++;
                y = a[i];
                countt = 1;
            }
        }
        b[countt - 1]++;
        int ans = 0;
        for (int i = 0; i < int(sizeof(b) / sizeof(int)); i++)
        {
            ans += b[i];
        }
        // cout << ans << endl;
        for (int i = 0; i < int(sizeof(b) / sizeof(int)); i++)
        {
            if(k == 0)
            {
                break;
            }
            if(k < b[i]*(i+1))
            {
                ans -= k/(i+1);
                k = 0;
            }
            else
            {
                k -= b[i]*(i+1);
                ans -= b[i];
            }
        }
        if(ans == 0)
        {
            ans = 1;
        }
        cout << ans << endl;
    }
    return 0;
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, k;
        cin >> n >> k;
        int a[n];
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        sort(a, a + n);
        int y = a[0];
        int countt = 1;
        int b[n] = {0};
        for (int i = 1; i < n; i++)
        {
            if(y == a[i])
            {
                countt++;
            }
            else
            {
                b[countt - 1]++;
                y = a[i];
                countt = 1;
            }
        }
        b[countt - 1]++;
        int ans = 0;
        for (int i = 0; i < int(sizeof(b) / sizeof(int)); i++)
        {
            ans += b[i];
        }
        // cout << ans << endl;
        for (int i = 0; i < int(sizeof(b) / sizeof(int)); i++)
        {
            if(k == 0)
            {
                break;
            }
            if(k < b[i])
            {
                ans -= k;
            }
            else
            {
                k -= b[i]*(i+1);
                ans -= b[i];
            }
        }
        if(ans == 0)
        {
            ans = 1;
        }
        cout << ans << endl;
    }
    return 0;
}

Answer: 1