ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Runtime error on test 7):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 69;
vector <int> adj[N];
int ans = 0;
int deg[N];
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void Solve() 
{   
    int n, m; cin >> n >> m;
    int a[n];
    int b[m];
    multiset <int> s1;
    multiset <int> s2;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        s1.insert(a[i]);
    } 
    for(int i = 0; i < m; i++) {
        cin >> b[i];
        s2.insert(b[i]);
    }
    
        while(s2.size() != 0 && s1.size() != 0){
            int y = *(--s2.end());
            auto x = s1.find(y);
            if(x != s1.end()){
                s1.erase(x);
                s2.erase(s2.find(*x));
            }
            else{
                if(y == 1) {
                    cout << "No" << endl;
                    return;
                }
                s2.erase(s2.find(y));
                s2.insert(y/2);
                s2.insert((y+1)/2);
                if(s2.size() > n) {
                    cout << "No" << endl;
                    return;
                }
            }
        }
    
    if(s1.size() == 0 && s2.size() == 0) 
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
}
 
int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 998244353
void solve(){
	ll l, r;
    cin >> l >> r;
    ll k = 31 - __builtin_clz(l ^ r);
    ll a = (l | ((1ll << k) - 1)) + 1, b = a - 1, c = l;
    while(c == a or c == b){
        c++;
    }
    cout << a << " " << b << " " << c << '\n';
}
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int tests = 1;
	cin >> tests;
	for(int i = 1; i <= tests; i ++)
		solve();
}

Submission (verdict: Wrong answer on test 2):
#include <iostream>

using i64=long long;

int msb_diff(i64 x,i64 y){
    for(int i=59;i>=0;i--){
        if(((x>>i)&1)!=((y>>i)&1))return i;
    }
    return -1;
}

int main(){
    int T;std::cin>>T;
    while(T--){
        i64 l,r,a,b,c;std::cin>>l>>r;
        i64 d=1LL<<msb_diff(l,r);
        a=l,c=r;
        if(l + d<=r&&l + d!=a&&l + d!=c){
            b=l + d;
        }else{
            b=r - d;
        }
        std::cout<<a<<" "<<b<<" "<<c<<"\n";
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 998244353
void solve(){
	ll l, r;
    cin >> l >> r;
    ll k = 31 - __builtin_clz(l ^ r);
    ll a = (l | ((1ll << k) - 1)) + 1, b = a - 1, c = l;
    while(c == a or c == b){
        c++;
    }
    cout << a << " " << b << " " << c << '\n';
}
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int tests = 1;
	cin >> tests;
	for(int i = 1; i <= tests; i ++)
		solve();
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>

using i64=long long;

int msb_diff(i64 x,i64 y){
    for(int i=59;i>=0;i--){
        if(((x>>i)&1)!=((y>>i)&1))return i;
    }
    return -1;
}

int main(){
    int T;std::cin>>T;
    while(T--){
        i64 l,r,a,b,c;std::cin>>l>>r;
        i64 d=1LL<<msb_diff(l,r);
        a=l,c=r;
        if(l + d<=r&&l + d!=a&&l + d!=c){
            b=l + d;
        }else{
            b=r - d;
        }
        std::cout<<a<<" "<<b<<" "<<c<<"\n";
    }
    return 0;
}

Submission (verdict: Accepted):
for _ in range(int(input())):
    l,r=map(int,input().split())
    low=1
    pow=0
    while low<=l:
        low*=2
        pow+=1
    l2=pow-1
    while r>=low:
        low*=2
        pow+=1
    r2=pow-1
    if l2==-1:
        print(0,1<<r2,(1<<r2)-1)
    elif r2==l2:
        x=set()
        k=r-1<<r2
        t=l
        i=0
        while k>0:
            if k&1==0:
                x.add(i)
            if t&1:
                x.add(i)
            i+=1
            k>>=1
            t>>=1
        num=0
        for k in x:
            num+=1<<k
        print(l,r,num+(1<<r2))
    elif r2-l2==1:
        a=1<<r2
        b=a-1
        if a-l>1:
            print(a-2,a-1,a)
        else:
            print(b,a,a+1)
    else:
        a=1<<r2
        b=(1<<r2) -1
        c=l
        print(c,b,a)
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

	for(auto x:s){

		m[x]++;

	}

	if(m.size()==1){

		cout<<"YES\n";

	}

	else if(m.size()==2){

		if(m.find('.')!=m.end()){

			cout<<"YES\n";

		}

		else{

			int k = m['p'];

		if(k>1){

			cout<<"NO\n";

		}

		else{

			if(s[n-1]!='p'){

				cout<<"NO\n";

			}

			else{

				cout<<"YES\n";	

			}

		}

		}

	}

	else{

		int k = m['p'];

		if(k>1){

			cout<<"NO\n";

		}

		else{

			if(s[n-1]!='p'){

				cout<<"NO\n";

			}

			else{

				cout<<"YES\n";	

			}

		}

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

	for(auto x:s){

		m[x]++;

	}

	if(m.find('s')!=m.end()&&m.find('p')!=m.end()){

		int a = m['s'];

		int b = m['p'];

		if(a>1&&b>1){

			cout<<"NO\n";

		}

		else{

			if(a==1){

				if(s[0]=='s'){

					cout<<"YES\n";

				}

				else cout<<"NO\n";

			}

			else{

				if(s[n-1]=='p'){

					cout<<"YES\n";

				}

				else cout<<"NO\n";

			}

		}

	}

	else{

		cout<<"YES\n";

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

	for(auto x:s){

		m[x]++;

	}

	if(m.size()==1){

		cout<<"YES\n";

	}

	else if(m.size()==2){

		if(m.find('.')!=m.end()){

			cout<<"YES\n";

		}

		else{

			int k = m['p'];

		if(k>1){

			cout<<"NO\n";

		}

		else{

			if(s[n-1]!='p'){

				cout<<"NO\n";

			}

			else{

				cout<<"YES\n";	

			}

		}

		}

	}

	else{

		int k = m['p'];

		if(k>1){

			cout<<"NO\n";

		}

		else{

			if(s[n-1]!='p'){

				cout<<"NO\n";

			}

			else{

				cout<<"YES\n";	

			}

		}

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

	for(auto x:s){

		m[x]++;

	}

	if(m.find('s')!=m.end()&&m.find('p')!=m.end()){

		int a = m['s'];

		int b = m['p'];

		if(a>1&&b>1){

			cout<<"NO\n";

		}

		else{

			if(a==1){

				if(s[0]=='s'){

					cout<<"YES\n";

				}

				else cout<<"NO\n";

			}

			else{

				if(s[n-1]=='p'){

					cout<<"YES\n";

				}

				else cout<<"NO\n";

			}

		}

	}

	else{

		cout<<"YES\n";

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

	for(auto x:s){

		m[x]++;

	}

	if(m.find('s')!=m.end()&&m.find('p')!=m.end()){

		int a = m['s'];

		int b = m['p'];

		if(a>1&&b>1){

			cout<<"NO\n";

		}

		else{

			int i=0,j=n-1;

			while(i<n){

				if(s[i]=='.') i++;

				else break;

			}

			while(j>=0){

				if(s[j]=='.') j--;

				else break;

			}

			if(a==1){

				if(s[i]=='s'){

					cout<<"YES\n";

				}

				else cout<<"NO\n";

			}

			else{

				if(s[j]=='p'){

					cout<<"YES\n";

				}

				else cout<<"NO\n";

			}

		}

	}

	else{

		cout<<"YES\n";

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

	for(auto x:s){

		m[x]++;

	}

	if(m.find('s')!=m.end()&&m.find('p')!=m.end()){

		int a = m['s'];

		int b = m['p'];

		if(a>1&&b>1){

			cout<<"NO\n";

		}

		else{

			int i=0,j=n-1;

			while(i<n){

				if(s[i]=='.') i++;

				else break;

			}

			while(j>=0){

				if(s[j]=='.') j--;

				else break;

			}

			if(i>0&&j<n-1){

				cout<<"NO\n";

				return;

			}

			if(a==1){

				if(s[i]=='s'){

					cout<<"YES\n";

				}

				else cout<<"NO\n";

			}

			else{

				if(s[j]=='p'){

					cout<<"YES\n";

				}

				else cout<<"NO\n";

			}

		}

	}

	else{

		cout<<"YES\n";

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}

Submission (verdict: Accepted):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

	if(s[0]=='s') s[0]= '.';

	if(s[n-1]=='p') s[n-1]='.';

	for(auto x:s){

		m[x]++;

	}

	if(m.find('s')!=m.end()&&m.find('p')!=m.end()){

		cout<<"NO\n";

	}

	else{

		cout<<"YES\n";

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

	for(auto x:s){

		m[x]++;

	}

	if(m.find('s')!=m.end()&&m.find('p')!=m.end()){

		int a = m['s'];

		int b = m['p'];

		if(a>1&&b>1){

			cout<<"NO\n";

		}

		else{

			int i=0,j=n-1;

			while(i<n){

				if(s[i]=='.') i++;

				else break;

			}

			while(j>=0){

				if(s[j]=='.') j--;

				else break;

			}

			if(a==1){

				if(s[i]=='s'){

					cout<<"YES\n";

				}

				else cout<<"NO\n";

			}

			else{

				if(s[j]=='p'){

					cout<<"YES\n";

				}

				else cout<<"NO\n";

			}

		}

	}

	else{

		cout<<"YES\n";

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve(){

	int n;

	cin>>n;

	string s;

	cin>>s;

	map<char,int> m;

	for(auto x:s){

		m[x]++;

	}

	if(m.find('s')!=m.end()&&m.find('p')!=m.end()){

		int a = m['s'];

		int b = m['p'];

		if(a>1&&b>1){

			cout<<"NO\n";

		}

		else{

			int i=0,j=n-1;

			while(i<n){

				if(s[i]=='.') i++;

				else break;

			}

			while(j>=0){

				if(s[j]=='.') j--;

				else break;

			}

			if(i>0&&j<n-1){

				cout<<"NO\n";

				return;

			}

			if(a==1){

				if(s[i]=='s'){

					cout<<"YES\n";

				}

				else cout<<"NO\n";

			}

			else{

				if(s[j]=='p'){

					cout<<"YES\n";

				}

				else cout<<"NO\n";

			}

		}

	}

	else{

		cout<<"YES\n";

	}

}

signed main(){

	pranavbansal21();

	int t;

	cin>>t;

	while(t--){

		solve();

	}

	return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Compilation error):
#include <iostream>

using namespace std;

int main() {
    int t;  // number of testcases

    cin >> t;

    for (int i = 0; i < t; i++) {
        int n, k, A, changes = 0;

        cin >> n >> k;

        vector<int> a, unique, occurence;

        for (int j = 1; j < n; j++) {
            cin >> A;
            a.push_back(A);
        }

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

        unique.push_back(a[0]);
        occurence.push_back(a[0]);

        for (int j = 1; j < n; j++) {

            if (unique.back() != a[j]) {
                unique.push_back(a[j]);
                occurence.push_back(1);
            } else {
                occurence.back() += 1;
            }
        }

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

        for (int j = 0; j < occurence.size() - 1; j++) {
            if (k - occurence[j] >= 0) {
                changes++;
                k -= occurence[j];
            } else {
                break;
            }
        }

        cout << occurence.size() - changes << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int t;  // number of testcases

    cin >> t;

    for (int i = 0; i < t; i++) {
        int n, k, A, changes = 0;

        cin >> n >> k;

        vector<int> a, unique, occurence;

        for (int j = 1; j < n; j++) {
            cin >> A;
            a.push_back(A);
        }

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

        unique.push_back(a[0]);
        occurence.push_back(a[0]);

        for (int j = 1; j < n; j++) {

            if (unique.back() != a[j]) {
                unique.push_back(a[j]);
                occurence.push_back(1);
            } else {
                occurence.back() += 1;
            }
        }

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

        for (int j = 0; j < occurence.size() - 1; j++) {
            if (k - occurence[j] >= 0) {
                changes++;
                k -= occurence[j];
            } else {
                break;
            }
        }

        cout << occurence.size() - changes << endl;
    }
}

Submission (verdict: Runtime error on test 1):
#include <bits/stdc++.h>

using namespace std;

int main() {
    int t;  // number of testcases

    cin >> t;

    for (int i = 0; i < t; i++) {
        int n, k, A, changes = 0;

        cin >> n >> k;

        vector<int> a, unique, occurence;

        for (int j = 1; j < n; j++) {
            cin >> A;
            a.push_back(A);
        }

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

        unique.push_back(a[0]);
        occurence.push_back(a[0]);

        for (int j = 1; j < n; j++) {

            if (unique.back() != a[j]) {
                unique.push_back(a[j]);
                occurence.push_back(1);
            } else {
                occurence.back() += 1;
            }
        }

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

        for (int j = 0; j < occurence.size() - 1; j++) {
            if (k - occurence[j] >= 0) {
                changes++;
                k -= occurence[j];
            } else {
                break;
            }
        }

        cout << occurence.size() - changes << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

int main() {
    int t;  // number of testcases

    cin >> t;

    for (int i = 0; i < t; i++) {
        int n, k, A, changes = 0;

        cin >> n >> k;

        vector<int> a, unique, occurence;

        for (int j = 0; j < n; j++) {
            cin >> A;
            a.push_back(A);
        }

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

        unique.push_back(a[0]);
        occurence.push_back(a[0]);

        for (int j = 1; j < n; j++) {

            if (unique.back() != a[j]) {
                unique.push_back(a[j]);
                occurence.push_back(1);
            } else {
                occurence.back() += 1;
            }
        }

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

        for (int j = 0; j < occurence.size() - 1; j++) {
            if (k - occurence[j] >= 0) {
                changes++;
                k -= occurence[j];
            } else {
                break;
            }
        }

        cout << occurence.size() - changes << endl;
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;

int main() {
    int t;  // number of testcases

    cin >> t;

    for (int i = 0; i < t; i++) {
        int n, k, A, changes = 0;

        cin >> n >> k;

        vector<int> a, unique, occurence;

        for (int j = 0; j < n; j++) {   // input array
            cin >> A;
            a.push_back(A);
        }

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

        unique.push_back(a[0]);
        occurence.push_back(1);

        for (int j = 1; j < n; j++) {

            if (unique.back() != a[j]) {
                unique.push_back(a[j]);
                occurence.push_back(1);
            } else {
                occurence.back() += 1;
            }
        }

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

        for (int j = 0; j < occurence.size() - 1; j++) {
            if (k - occurence[j] >= 0) {
                changes++;
                k -= occurence[j];
            } else {
                break;
            }
        }

        cout << occurence.size() - changes << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include <iostream>

using namespace std;

int main() {
    int t;  // number of testcases

    cin >> t;

    for (int i = 0; i < t; i++) {
        int n, k, A, changes = 0;

        cin >> n >> k;

        vector<int> a, unique, occurence;

        for (int j = 1; j < n; j++) {
            cin >> A;
            a.push_back(A);
        }

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

        unique.push_back(a[0]);
        occurence.push_back(a[0]);

        for (int j = 1; j < n; j++) {

            if (unique.back() != a[j]) {
                unique.push_back(a[j]);
                occurence.push_back(1);
            } else {
                occurence.back() += 1;
            }
        }

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

        for (int j = 0; j < occurence.size() - 1; j++) {
            if (k - occurence[j] >= 0) {
                changes++;
                k -= occurence[j];
            } else {
                break;
            }
        }

        cout << occurence.size() - changes << endl;
    }
}

Submission (verdict: Compilation error):
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int t;  // number of testcases

    cin >> t;

    for (int i = 0; i < t; i++) {
        int n, k, A, changes = 0;

        cin >> n >> k;

        vector<int> a, unique, occurence;

        for (int j = 1; j < n; j++) {
            cin >> A;
            a.push_back(A);
        }

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

        unique.push_back(a[0]);
        occurence.push_back(a[0]);

        for (int j = 1; j < n; j++) {

            if (unique.back() != a[j]) {
                unique.push_back(a[j]);
                occurence.push_back(1);
            } else {
                occurence.back() += 1;
            }
        }

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

        for (int j = 0; j < occurence.size() - 1; j++) {
            if (k - occurence[j] >= 0) {
                changes++;
                k -= occurence[j];
            } else {
                break;
            }
        }

        cout << occurence.size() - changes << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 1):
#include <bits/stdc++.h>

using namespace std;

int main() {
    int t;  // number of testcases

    cin >> t;

    for (int i = 0; i < t; i++) {
        int n, k, A, changes = 0;

        cin >> n >> k;

        vector<int> a, unique, occurence;

        for (int j = 1; j < n; j++) {
            cin >> A;
            a.push_back(A);
        }

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

        unique.push_back(a[0]);
        occurence.push_back(a[0]);

        for (int j = 1; j < n; j++) {

            if (unique.back() != a[j]) {
                unique.push_back(a[j]);
                occurence.push_back(1);
            } else {
                occurence.back() += 1;
            }
        }

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

        for (int j = 0; j < occurence.size() - 1; j++) {
            if (k - occurence[j] >= 0) {
                changes++;
                k -= occurence[j];
            } else {
                break;
            }
        }

        cout << occurence.size() - changes << endl;
    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

int main() {
    int t;  // number of testcases

    cin >> t;

    for (int i = 0; i < t; i++) {
        int n, k, A, changes = 0;

        cin >> n >> k;

        vector<int> a, unique, occurence;

        for (int j = 0; j < n; j++) {
            cin >> A;
            a.push_back(A);
        }

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

        unique.push_back(a[0]);
        occurence.push_back(a[0]);

        for (int j = 1; j < n; j++) {

            if (unique.back() != a[j]) {
                unique.push_back(a[j]);
                occurence.push_back(1);
            } else {
                occurence.back() += 1;
            }
        }

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

        for (int j = 0; j < occurence.size() - 1; j++) {
            if (k - occurence[j] >= 0) {
                changes++;
                k -= occurence[j];
            } else {
                break;
            }
        }

        cout << occurence.size() - changes << endl;
    }
}