ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: c++23 

Code 1:
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define double long double
#define popcount __builtin_popcount
#define fal (fa<<1)
#define far (fa<<1|1)
#define endl '\n'
int const N=2e3+5,M=2e3+5,inf=0x7fffffffffffffff,mod=998244353;
int n,m,a[N],b[N],c[N],d[N],cnt=0;
string s[5];
bool vis=0;
void solve(){
	int i,j,k,h,t,x=0,y=0,z,ans=0,minn=inf,maxn=-inf;
	cin>>n;
	for(i=1;i<=n;i++){
		c[i]=i;
	}
	for(i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	for(i=n;i>=1;i--){
		int now=lower_bound(c+1,c+1+i,a[i])-c;
		for(j=now;j>1;j--){
			ans++;
			swap(c[j],c[j-1]);
		}
		for(j=1;j<=now-1;j++){
			ans++;
			swap(c[j],c[j+1]);
		}
		for(j=now;j<=i-1;j++){
			ans++;
			swap(c[j],c[j+1]);
		}
	}
	for(i=1;i<=n;i++){
		c[i]=i;
	}
	cout<<ans<<endl;
	for(i=n;i>=1;i--){
		int now=lower_bound(c+1,c+1+i,a[i])-c;
		for(j=now;j>1;j--){
			cout<<c[j]<<" "<<c[j-1]<<endl;
			swap(c[j],c[j-1]);
		}
		for(j=1;j<=now-1;j++){
			cout<<c[j+1]<<" "<<c[j]<<endl;
			swap(c[j],c[j+1]);
		}
		for(j=now;j<=i-1;j++){
			cout<<c[j+1]<<" "<<c[j]<<endl;
			swap(c[j],c[j+1]);
		}
	}
	return;
}
signed main(void){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t;
//	cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define int long long
using i64 = long long;
#define print(...) std::cerr << format(__VA_ARGS__) << std::endl
void solve()
{
    int n;
    std::cin >> n;
    std::vector<int> c(n + 1), a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        a[i] = i;
        std::cin >> c[i];
    }
    std::vector<pair<int,int>> ttt;
    for(int i = n;i>=1;i--){
        int t = c[i];
        for(int j = t+1;j<=i;j++){
            ttt.push_back(pair<int,int>(a[j],a[j-1]));
            // std::cout << a[j] << " " << a[j-1] << "\n";
            swap(a[j],a[j-1]);
        }
    }
    std::cout << ttt.size() << "\n";
    for(int i = 0;i<ttt.size();i++) std::cout << ttt[i].first << " " << ttt[i].second << "\n";
    
}

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

    solve();
    return 0;
}
/* stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?)
 * do smth instead of nothing and stay organized
 * WRITE STUFF DOWN
 * DON'T GET STUCK ON ONE APPROACH
 */

Answer: 2
Problem: 2052A - Adrenaline Rush
Language: c++23 

Code 1:
#include <bits/stdc++.h>
using namespace std;
 
void solve(){
    int n; cin >> n;
    vector<int> vt(n);
    for (int &i : vt) cin >> i;
    set<pair<int, int>> ans;
    vector<pair<int, int>> vtans;
    // 1, 2, 3 -> 2, 1, 3
    vector<int> form(n);
    for (int i = 0; i < n; i++)
        form[i] = i + 1;
    for (int i = 0; i < n; i++){
        int idx = i;
        for (; idx < n; idx++)
            if (form[idx] == vt[i])
                break;
        if (idx + 1 < n){
            if (!ans.count({form[idx + 1], form[idx]})){
                vtans.push_back({form[idx + 1], form[idx]});
                ans.insert({form[idx + 1], form[idx]});
            }
            if (!ans.count({form[idx], form[idx + 1]})){
                vtans.push_back({form[idx], form[idx + 1]});
                ans.insert({form[idx], form[idx + 1]});
            }
            
        }
        for (int j = idx; j > i; j--){
            if (!ans.count({form[j], form[j - 1]})){
                vtans.push_back({form[j], form[j - 1]});
                ans.insert({form[j], form[j - 1]});
            }
            swap(form[j], form[j - 1]);
        }
    }
    cout << ans.size() << '\n';
    for (auto &p : vtans)
        cout << p.first << " " << p.second << '\n';
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
 
void solve(){
    int n; cin >> n;
    vector<int> vt(n);
    for (int &i : vt) cin >> i;
    vector<pair<int, int>> ans;
    for (int i = 1; i < n; i++)
        for (int j = i + 1; j <= n; j++)
            ans.push_back({j, i});
    vector<bool> b(n + 1, false);
    for (int i = n - 1; ~i; i--){
        for (int j = vt[i] - 1; j >= 1; j--){
            if (!b[j])
                ans.push_back({j, vt[i]});
        }
        b[vt[i]] = true;
    }
    cout << ans.size() << '\n';
    for (auto &[x, y] : ans)
        cout << x << ' ' << y << '\n';
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}

Answer: 2
Problem: 2052A - Adrenaline Rush
Language: c++20 

Code 1:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vll=vector<ll>;
using pii=pair<ll,ll>;
using pll=pair<ll,ll>;
#define all(v) (v).begin(),(v).end()
#define sz(v) (ll)(v).size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define f(i,a,b) for(ll i=(a);i<(b);i++)
#define fr(i,a,b) for(ll i=(a);i>=(b);i--)
void solve(){
  ll n;cin>>n;
  vll a(n);
  f(i,0,n){cin>>a[i];}
  vector<pair<ll,ll>>ans;
  vll x(n+1,0);
  fr(i,n-1,0)
  {
    ll val=a[i];
    x[a[i]]=1;
    fr(j,val-1,1)
    {
      if(x[j]==0){ans.pb({val,j});}
    }
   f(i,1,n+1)
   {
     if(x[i]!=1)
     {
       ans.pb({i,val});
     }
   }
    
  }
  cout<<ans.size()<<endl;
  f(i,0,ans.size())
  {
    cout<<ans[i].F<<" "<<ans[i].S<<endl;
  }
  cout<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;t=1;
    while(t--)solve();
    return 0;
}


Code 2:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vll=vector<ll>;
using pii=pair<ll,ll>;
using pll=pair<ll,ll>;
#define all(v) (v).begin(),(v).end()
#define sz(v) (ll)(v).size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define f(i,a,b) for(ll i=(a);i<(b);i++)
#define fr(i,a,b) for(ll i=(a);i>=(b);i--)

ll ck(ll x,ll y,ll z){
    return (x-y)*(x-y) + (y-z)*(y-z) + (x-z)*(x-z);
}

void solve(){
    ll n;cin>>n;
    vll a(n);
    vll hsh(n+1,0);
    f(i,0,n){cin>>a[i];
      hsh[a[i]]=(i+1);
    }
    map<pair<ll,ll>,ll>m;
    f(i,1,n+1)
    {
      ll pos=hsh[i];
      f(j,0,pos)
      {
        if(a[j]>i){m[{a[j],i}]++;}
      }
    }
    // auto it=m.begin();
    // cout<<"sz"<<m.size()<<endl;
    // while(it!=m.end())
    // {
    //   pair<ll,ll>p=it->F;
    //   cout<<p.F<<" "<<p.S<<endl;it++;
    // }
    vector<pair<ll,ll>>ans;
    f(i,1,n+1)
    {
      f(j,1,n+1)
      {
        if(i!=j)
        {
          pair<ll,ll>now={i,j};
          if(m[{i,j}]==0){ans.pb({i,j});}
        }
      }
    }
    cout<<ans.size()<<endl;
    f(i,0,ans.size())
    {
      cout<<ans[i].S<<" "<<ans[i].F<<endl;
    }
    
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;t=1;
    while(t--)solve();
    return 0;
}


Answer: 1
Problem: 2052A - Adrenaline Rush
Language: c++23 

Code 1:
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#define ll long long int
using namespace std;
    
int main() {
   int z;
   cin>>z;
    int a[z];
    int b[z];
    vector<vector<int>> v(z,vector<int> (z,0));
    for(int i=0;i<z;i++){
      cin>>a[i];
      b[i]=i+1;
    }
    vector<pair<int,int>> ans;
    for(int i=0;i<z;i++){
      if(b[i]!=a[i]){
         ans.push_back({a[i],b[i]});
         v[a[i]-1][b[i]-1]=1;
         v[b[i]-1][a[i]-1]=1;
         b[a[i]-1]=b[i];
         b[i]=a[i];
      }
    }
   for(int i=0;i<z-1;i++){
         if(v[b[i]-1][b[i+1]-1]==0){
            ans.push_back({b[i+1],b[i]});
            ans.push_back({b[i],b[i+1]});
         }
   }
   cout<<ans.size()<<endl;
   for(int i=0;i<ans.size();i++){
      cout<<ans[i].first<<" "<<ans[i].second<<endl;
   }
   
    return 0;
}

Code 2:
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#define ll long long int
using namespace std;
    
int main() {
   int z;
   cin>>z;
    int a[z];
    int b[z];
    for(int i=0;i<z;i++){
      cin>>a[i];
      b[i]=z-i;
    }
    vector<pair<int,int>> ans;
    for(int i=z;i>=2;i--){
      for(int j=i-1;j>=1;j--){
         ans.push_back({i,j});
      }
    }
    for(int i=0;i<z-1;i++){
      int j=i;
      while(a[i]!=b[j]){
         j++;
      }
      while(j>i){
         ans.push_back({a[i],b[j-1]});
         swap(b[j],b[j-1]);
         j--;
      }
    }
   cout<<ans.size()<<endl;
   for(int i=0;i<ans.size();i++){
      cout<<ans[i].first<<" "<<ans[i].second<<endl;
   }
   
    return 0;
}

Answer: 2
Problem: 2052A - Adrenaline Rush
Language: python

Code 1:
import io,os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline




def main():
    n = int(input())
    arr = list(map(int,input().split()))

    ans = []
    for i in range(n-1):
        for j in range(i+1,n):
            if arr[i] < arr[j]:
                ans.append((arr[j],arr[i]))
                ans.append((arr[i],arr[j]))
            else:
                ans.append((arr[i],arr[j]))

    print(len(ans))
    for ele in ans:
        print(*ele)



main()


Code 2:
import io,os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline




def main():
    n = int(input())
    arr = list(map(int,input().split()))
    for i in range(n):
        arr[i] -= 1


    curr = [i for i in range(n)]

    ans = []


    for i in range(n):
        index = -1
        for j in range(n):
            if curr[j]==arr[i]:  
                index = j   
                break

        for j in range(index,n-1):
            curr[j],curr[j+1] = curr[j+1],curr[j]
            ans.append((curr[j]+1,curr[j+1]+1))
        for j in range(n-2,i-1,-1):
            curr[j],curr[j+1] = curr[j+1],curr[j]
            ans.append((curr[j]+1,curr[j+1]+1))        



    print(len(ans))
    for ele in ans:
        print(*ele)



main()


Answer: 2
Problem: 2052A - Adrenaline Rush
Language: c++17 

Code 1:
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1010;
int a[N];
int st[N];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int cut=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(a[i]>a[j]){
				cut++;
			}
		}
	}
	int ans=n*(n-1)-cut;
	printf("%d\n",ans);
	reverse(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		int p=a[i];
		for(int j=p-1;j>0;j--){
			if(st[j]) continue;
			printf("%d %d\n",p,j);
		}
		for(int j=n;j>=i+1;j--){
			if(st[a[j]]) continue;
			printf("%d %d\n",a[j],p);
		}
		st[p]=1;
	}
	return 0;
}

Code 2:
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1010;
int a[N];
int b[N];
int st[N];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=i;
	}
	int cut=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(a[i]>a[j]){
				cut++;
			}
		}
	}
	int ans=n*(n-1)-cut;
	printf("%d\n",ans);
	reverse(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		int p=a[i];
		for(int j=p-1;j>0;j--){
			if(st[j]) continue;
			printf("%d %d\n",p,j);
		}
		st[p]=1;
		for(int j=1;j<=n;j++){
			if(st[j]) continue;
			printf("%d %d\n",j,p);
		}
		
	}
	return 0;
}

Answer: 2
Problem: 2052A - Adrenaline Rush
Language: c++17 

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define len(a) (int) a.size()


signed main() {
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if (n == 1) {
        return cout << 0, 0;
    }

    vector<pll> ans;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i] > a[j]) {
                ans.push_back({a[i], a[j]});
            } else {
                ans.push_back({a[j], a[i]});
                ans.push_back({a[i], a[j]});
            }
        }
    }
   
    cout << len(ans) << '\n';
    for (auto [l, r]: ans) {
        cout << l << ' ' << r << '\n';
    }

    return 0;

}



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

typedef long long ll;
typedef pair<ll, ll> pll;

#define len(a) (int) a.size()


signed main() {
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n), b(n+1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[a[i]] = i;
    }
    if (n == 1) {
        return cout << 0, 0;
    }


    vector<pll> ans1, ans2, ans3;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i] < a[j]) {
                ans1.push_back({a[i], a[j]});
            }
        }
    }
   
    cout << (len(ans1) + (n * (n - 1)) / 2) << '\n';

    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            cout << j << ' ' << i << '\n';
        }
    }

    // vector<ll> b(n);
    // iota(b.begin(), b.end(), 1);
    // reverse(b.begin(), b.end());

    // for (int i = 0; i < n; i++) {
    //     for (int j = i - 1; j >= 0; j--) {
    //         ans1.push_back({a[i], a[j]});
    //         swap
    //     }
    // }

    sort(ans1.begin(), ans1.end(), [&](pll i, pll j) {
        if (b[i.first] == b[j.first])
            return i.second < j.second;
        return b[i.first] < b[j.first];

    });
    for (auto [l, r]: ans1) {
        cout << l << ' ' << r << '\n';
    }

    return 0;


}



Answer: 2
Problem: 2052A - Adrenaline Rush
Language: c++23 

Code 1:
#include<iostream>
#include <map>
#include<set>
#include <vector>
#define mod 998244353
#include <algorithm>
#include <limits>
using namespace std;


int main() {
   int n;
   cin>>n;
   vector<int> v(n);
   for(int i=0;i<n;i++) {
      cin>>v[i];
   }
  vector<int> v2(n);
    for(int i =0;i<n;i++) {
        v2[i] =i+1;
    }
    vector<pair<int,int>> ans(n*n);
    int ans2=0;
    for(int i =0;i<n;i++) {
        for(int j =0;j<n-i-1;j++) {
            ans[ans2] = {v2[j+1],v2[j]};
            ans2++;
            int temp = v2[j+1];
            v2[j+1] = v2[j];
            v2[j] = temp;
        }
    }
    for(int i =0;i<n;i++) {
        int element = v[i];
        int k=0;
        for(int j =i;j<n;j++) {
            if(v2[j] == element) {
                k = j;
            }
        }
        for(int j =k;j>i;j--) {
            ans[ans2] = {v2[j],v2[j-1]};
            ans2++;
            int temp = v2[j-1];
            v2[j-1] = v2[j];
            v2[j] = temp;
        }
    }
    cout<<ans2<<endl;
    for(auto i:ans) {
        if(i.first ==i.second&& i.second==0) {
            break;
        }else {
            cout<<i.first<<" "<<i.second<<endl;
        }
    }
}


Code 2:
#include<iostream>
#include <map>
#include<set>
#include <vector>
#define mod 998244353
#include <algorithm>
#include <limits>
using namespace std;


int main() {
   int n;
   cin>>n;
   vector<int> v(n);
   for(int i=0;i<n;i++) {
      cin>>v[i];
   }
  vector<int> v2(n);
    for(int i =0;i<n;i++) {
        v2[i] =i+1;
    }
    vector<pair<int,int>> ans(n*n);
    int ans2=0;
    for(int i =0;i<n;i++) {
        for(int j =0;j<n-i-1;j++) {
            ans[ans2] = {v2[j+1],v2[j]};
            ans2++;
            int temp = v2[j+1];
            v2[j+1] = v2[j];
            v2[j] = temp;
        }
    }
    for(int i =0;i<n;i++) {
        int element = v[i];
        for(int j =n-element;j>i;j--) {
            ans[ans2] = {v2[j],v2[j-1]};
            ans2++;
            int temp = v2[j-1];
            v2[j-1] = v2[j];
            v2[j] = temp;
        }
    }
    cout<<ans2<<endl;
    for(auto i:ans) {
        if(i.first ==i.second&& i.second==0) {
            break;
        }else {
            cout<<i.first<<" "<<i.second<<endl;
        }
    }
}


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

Code 1:
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
 
int main()
{
    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];
        }
        unordered_map<int , int>mpp;
        for(int i =0 ; i < n ; i++){
            mpp[a[i]]++;
        }
        vector<int>freq;
        for(auto p : mpp){
            freq.push_back(p.second);
        }
        sort(freq.begin(), freq.end());
        int min_req = 0 ;
        int cnt = k;
        int res = 0;
        int m = freq.size();
        for(int i = 0 ; i < m ; i++){
            if(cnt>=freq[i]){
                cnt-=freq[i];
            }
            else{
                res++;
            }
        }
        if(res == 0 ){
            res =1 ;
        }
        cout<<res<<endl;
    }

    return 0;
}

Code 2:
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);

int main()
{
    Code By
    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> freq;
        int cnt = 1;
        for (int i = 1; i < n; i++) {
            if (a[i - 1] == a[i]) {
                cnt++;
            } else {
                freq.push_back(cnt);
                cnt = 1;
            }
        }
        freq.push_back(cnt);

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

        int res = 0;
        for (int f : freq) {
            if (k >= f) {
                k -= f;
            } else {
                res++;
            }
        }
        if(res == 0 ){
            res =1 ;
        }
        cout << res << 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() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vector<int> a(n);
        //set<int> s;
      
        map<int,int> m;
        vector<int> freq;
        for(int i=0;i<n;i++){
            cin>>a[i];
            m[a[i]]++;
            
            //s.insert(a[i]);
        }
        for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
            freq.push_back(it->second);
        }
        sort(freq.begin(),freq.end());

        int ans=m.size();
        for(int i=0;i<freq.size();i++){
            if(k>=freq[i]){
                k=k-freq[i];
                ans--;
            }
            else {
                break;
            }
        }
        if(ans==0) cout<<"1"<<endl;
       else  cout<<ans<<endl;


    }
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    
    while (t--) {
        int n, k;
        cin >> n >> k;
        
        unordered_map<int, int> m;
        for (int i = 0; i < n; i++) {
            int num;
            cin >> num;
            m[num]++;
        }

    
        priority_queue<int, vector<int>, greater<int>> minHeap;
        for (auto& p : m) {
            minHeap.push(p.second);
        }

        int distinct = m.size();
        
       
        while (!minHeap.empty() && k >= minHeap.top()) {
            k -= minHeap.top();
            minHeap.pop();
            distinct--;
        }

        cout << max(1, distinct) <<endl;
    }
    
  
}


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

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

#define int long long
#define dub long double
typedef vector<int> vint;
typedef vector<string> vstr;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef unordered_map<int,int> umap;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(a) a.begin(),a.end()
#define endl '\n'
#define INF 2147483647
//#define INF 9223372036854775807
#define null '\0'
const int N = 1e5 + 10, Mod = 1e9 + 7;
int n,m,k;
void solve(){
    cin >> n >> k;
    vint a(n);
    rep(i,0,n) cin >> a[i];
    map<int,int> mp;
    rep(i,0,n) mp[a[i]] ++;
    int ans = 0;
    for(auto i : mp) {
        if(i.second <= k) k-= i.second;
        else ans++;
    }
    cout << max(1LL,ans) << endl;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test_n = 1;
    cin>>test_n;
    for(int t_c = 1;t_c <= test_n;t_c ++){
        solve();
    }
    return 0;
}

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

#define int long long
#define dub long double
typedef vector<int> vint;
typedef vector<string> vstr;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef unordered_map<int,int> umap;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(a) a.begin(),a.end()
#define endl '\n'
#define INF 2147483647
//#define INF 9223372036854775807
#define null '\0'
const int N = 1e5 + 10, Mod = 1e9 + 7;
int n,m,k;
void solve(){
    cin >> n >> k;
    vint a(n);
    rep(i,0,n) cin >> a[i];
    map<int,int> mp;
    rep(i,0,n) mp[a[i]] ++;
    int ans = 0;
    vii v;
    for(auto i : mp) {
        v.push_back({i.second , i.first});
        ans++;
    }
    sort(all(v));
    for(auto i : v) {
        if(i.first <= k) k -= i.first , ans--;
    }
    cout << max(1LL,ans) << endl;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test_n = 1;
    cin>>test_n;
    for(int t_c = 1;t_c <= test_n;t_c ++){
        solve();
    }
    return 0;
}

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

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

using namespace std;

int main() {
	int t;
	cin>>t;
	while(t>0) {
		int n,k;
		cin>>n>>k;
		vector<int> v;
		map<int,int> st;
		for(int i=0;i<n;i++) {
			 int x;cin>>x;
			 v.push_back(x);
			 st[x]++;
		}
		if(k==0) {
			cout<<st.size()<<endl;
		}
		else if(k==n) {
			cout<<1<<endl;
		}
		else {
			int ans= st.size();
			vector<int> v;
			for(auto it:st) {
				v.push_back(it.second);
			}
			sort(v.begin(),v.end());
			int i=0;
			int m= v.size();
			while(k>0 && i<m) {
				if(v[i]<=k) {k-=v[i]; ans--;}
				i++;
			}
			cout<<ans<<endl;
		}
		t--;
	}
}

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

using namespace std;

int main() {
	int t;
	cin>>t;
	while(t>0) {
		int n,k;
		cin>>n>>k;
		vector<int> v;
		set<int> st;
		for(int i=0;i<n;i++) {
			 int x;cin>>x;
			 v.push_back(x);
			 st.insert(x);
		}
		if(k==0) {
			cout<<st.size()<<endl;
		}
		else if(k==n) {
			cout<<1<<endl;
		}
		else {
			sort(v.begin(),v.end());
			int k1=k;
			set<int> uqp;
			int unqp=0;
			if(v[k1-1]==v[k1]) {unqp--;}
			while(k1>0) {
				uqp.insert(v[k1-1]); k1--;
			}	
			unqp+=uqp.size();
			k1=n-k;
			set<int> uqs;
			int unqs=0;
			if(v[k1+1]==v[k1]) {unqs--;}
			while(k1<n) {
				uqs.insert(v[k1]); k1++;
			}
			unqs+=uqs.size();
			cout<<st.size()-(max(unqp,unqs))<<endl;
		}
		t--;
	}
}

Answer: 1