ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>

const int M = 998244353;
const int N = 2e5+10;
const int maxint = 2e9 + 1;

int binExp(int a, int b){
	int ans = 1;
	while(b){
		if(b&1){
			ans = (ans*1LL*a)%M;
		}
		a = (a*1LL*a)%M;
		b>>=1;
	}
	return ans;
}


void solve(){
	int n;
    cin>>n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    ll sum = accumulate(a.begin(), a.end(), 0);
    while(a.size() > 1){
        vector<ll> newA(a.size()-1);
        for (int i = 0; i < a.size() -1 ; ++i)
        {
            newA[i] = a[i+1] - a[i];
        }
        sum = max(sum, 1LL*abs(accumulate(newA.begin(), newA.end(), 0)));

        a = newA;
    }

    cout<<sum<<endl;
}	



int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin>>t;
	while(t--){
		solve();
	}	
}





Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>

const int M = 998244353;
const int N = 2e5+10;
const int maxint = 2e9 + 1;

int binExp(int a, int b){
	int ans = 1;
	while(b){
		if(b&1){
			ans = (ans*1LL*a)%M;
		}
		a = (a*1LL*a)%M;
		b>>=1;
	}
	return ans;
}


void solve(){
	int n;
    cin>>n;
    vector<ll> a(n);
    ll sum =0;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        sum += a[i];
    }
    
    while(a.size() > 1){
        vector<ll> newA(a.size()-1);
        ll newSum = 0;
        for (int i = 0; i < a.size() -1 ; ++i)
        {
            newA[i] = a[i+1] - a[i];
            newSum += newA[i];
        }
        sum = max(sum , abs(newSum));

        a = newA;
    }

    cout<<sum<<endl;
}	



int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin>>t;
	while(t--){
		solve();
	}	
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>

const int M = 998244353;
const int N = 2e5+10;
const int maxint = 2e9 + 1;

int binExp(int a, int b){
	int ans = 1;
	while(b){
		if(b&1){
			ans = (ans*1LL*a)%M;
		}
		a = (a*1LL*a)%M;
		b>>=1;
	}
	return ans;
}


void solve(){
	int n;
    cin>>n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    int sum = accumulate(a.begin(), a.end(), 0);
    while(a.size() > 1){
        vector<int> newA(a.size()-1);
        for (int i = 0; i < a.size() -1 ; ++i)
        {
            newA[i] = a[i+1] - a[i];
        }
        sum = max(sum, abs(accumulate(newA.begin(), newA.end(), 0)));

        a = newA;
    }

    cout<<sum<<endl;
}	



int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin>>t;
	while(t--){
		solve();
	}	
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

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

void solve(){
    int l,r;
    cin >> l >> r;
    if(l==0){
        cout << r <<" " << r-1 <<" " << l <<"\n";
    }
    else if(r-l+1==3) cout << l << " " << l+1 << " " <<r <<"\n";
    else{
        int k = __lg(l^r);
        int a = (l|(1<<k)-1), b=a+1, c = (a==l?r:l);
        cout << a << " "<<b <<" "<< c<<"\n"; 
        }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int t;
    cin>>t;
    while(t--){
       solve();
    }
    return 0; 
    
} 

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
const long long INF = (ll)1e17;

void solve() {
    ll L, R;
    cin >> L >> R;
    bitset<32> l = L, r = R;
    string left = l.to_string(), right = r.to_string();
    string ans;
    ll T = 1, e = 0;
    for (int i = 0; i < 32; i++) {
        if (left[i] == right[i] && T) {
            ans += left[i];
        } else if (T == 1) {
            for (int j = i + 1; j < 32; j++) if (right[j] == '1') e = 1;
            e = 0;
            if (e) ans += '1';
            else ans += '0';
            T = 0;
        } else {
            if (left[i] != right[i]) {
                if (e) ans += '0';
                else ans += '1';
            } else if (left[i] == '0') ans += '1';
            else ans += '0';
        }
    }
    vector<ll> st(33, 1ll);
    for (int i = 1; i < 33; i++) st[i] = st[i - 1] * 2ll;
    ll sr = 0;
    for (int i = 0; i < 32; i++) {
        sr += st[31 - i] * (ans[i] - '0');
    }
    if (sr <= L || sr >= R) {
        T = 1, e = 1;
        for (int i = 0; i < 32; i++) {
            if (left[i] == right[i] && T) {
                ans += left[i];
            } else if (T == 1) {
                //for (int j = i + 1; j < 32; j++) if (right[j] == '1') e = 1;
                //e = 0;
                if (e) ans += '1';
                else ans += '0';
                T = 0;
            } else {
                if (left[i] != right[i]) {
                    if (e) ans += '0';
                    else ans += '1';
                } else if (left[i] == '0') ans += '1';
                else ans += '0';
            }
        }
        ll sr = 0;
        for (int i = 0; i < 32; i++) {
            sr += st[31 - i] * (ans[i] - '0');
        }
    }
    cout << L << " " << sr << " " << R << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll q;
    cin >> q;
    while (q--) {
        solve();
    }
    cout.flush();
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace __gnu_pbds;
using namespace std;
using namespace chrono;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// A.find_by_order(x), A.order_of_key(x)
#define int long long
#define pb push_back
#define pbb pop_back
#define float long double
#define mp make_pair
#define MOD 1000000007 // 998244353
#define INF 1e18
#define set_bits(x) __builtin_popcountll(x)
#define sp " "
#define endl "\n"
#define all(v) (v).begin(), (v).end()
#define PIE acos(-1)
#define F first
#define S second
#define rez(v, n) v.resize(n);
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = b; i >= a; i--)
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<vector<int>> vvi;

int ansg = INF;

int rec(vector<int> a, int revallowed){
    if(a.size()==1)
        return a[0];
    
    ansg = max(ansg,accumulate(all(a),0LL));
    int n=a.size();
    int ans = -INF;
    vector<int> b;
    for(int i=0;i<=n-2;i++){
        b.pb(a[i + 1] - a[i]);
    }

    ans=max(ans,rec(b,1));
    if(revallowed){
        reverse(all(a));
        ans=max(ans,rec(a,0));
    }
    return ans;
}

void solve()
{
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,0,n) cin>>a[i];
    ansg = -INF;
    cout<<max(ansg,rec(a,1))<<endl;



}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    auto start1 = high_resolution_clock::now();
    int t;
    t = 1;
     cin >> t;
    rep(testcase, 0, t) solve();
    auto stop1 = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop1 - start1);
    #ifndef ONLINE_JUDGE
        cerr << "Time: " << duration.count() / 1000 << " ms" << endl;
    #endif
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
using namespace std;

#include <iostream>

#include <string>

#include <bits/stdc++.h>

#include <algorithm>

#include <cctype>

#define ll long long

const ll N=2e5+10;

bool prime[N];

ll factor(ll n) {

    ll ans=n;

    for (int i = 2; i * i <= n; ++i) {

        if(n%i==0) {

            while (n % i == 0) {

                n /= i;

            }

            ans -= ans / i;

        }

    }

    if (n > 1) { ans-=ans/n; }

    return ans;

}

vector<ll> prime_divisors(int n){

    vector<ll>ret;

    if(prime[n])ret.push_back(n);

    for(int i=2;i*i<=n;i++){

        if(n%i==0&&prime[i]){

            ret.push_back(i);

            if((n/i!=i)&&prime[n/i])ret.push_back(n/i);

        }

    }

    return ret;

}

void Sieve(ll n)

{

    memset(prime,true,sizeof(prime));

    for(ll p=2; p*p<=n; p++)

    {

        if(prime[p])

        {

            for(ll i=p*p; i<=n; i+=p)

            {

                prime[i]=false;

            }

        }

    }

}

ll FastExpo (ll base, ll power) {

    ll result = 1;

    while (power) {

        if (power%2) {

            result *= base;

        }

        base *= base;

        power /= 2;

    }

    return result;

}

ll OddSum(ll n){

    if(n%2){

        ll k=(n+1)/2;

        return (k*k);

    }

    else{

        ll k=(n)/2;

        return (k*k);

    }

}

ll CeilDivision(ll a,ll b){

    return (a+b-1) / b;

}

int dx[]={-1, 0, 1, 0};

int dy[]= {0, -1, 0, 1};

void fast()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

}

bool comp(const pair<ll,ll>&a , const pair<ll,ll>&b){

    return b.second>a.second;

}

vector<bool>visited(N,false);

vector<int>AdjList[N];

void dfs(int node){

    if(visited[node]){

        return;

    }

    visited[node]=true;

    for(int n: AdjList[node]){

        dfs(n);

    }

}

queue<int>qu;

vector<int>dis(N,0);

void bfs(int node){



    if (!visited[node]) {

        queue<int> q;

        q.push(node);

        visited[node] = true;

        while (!q.empty()) {

            int current_node = q.front();

            q.pop();

            for (int neighbor : AdjList[current_node]) {

                if (!visited[neighbor]) {

                    visited[neighbor] = true;

                    q.push(neighbor);

                }

            }

        }

    }

}

void solve() {

    ll n,l,r;cin>>n>>l>>r;

    ll a[n];

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

        cin>>a[i];

    }

    sort(a,a+n);

    ll ans=0;

    for(int i=0;i<r-l+1;i++){

        ans+=a[i];

    }

    cout<<ans<<endl;

}

int main() {

/*

#ifndef ONLINE_JUDGE

    freopen("art.in", "r", stdin);

    freopen("art.out", "w", stdout);

#endif

*/

    fast();

    int t=1;cin>>t;

    while(t--){

        solve();

    }

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


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

using namespace std;

void solve(){

	int n,t=0;

	cin>>n;

	int a[n];

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

		cin>>a[i];

	}

	for (int i=0;i<n-1;++i){

		int mi=min(a[i],a[i+1]);

		if (a[i]>a[i+1]){

			cout<<"NO"<<endl;

			t=1;

			break;

		}

		if (a[i+2]<=a[i+1]){

			a[i]-=mi;

			a[i+1]-=mi;

		}

	}

	if (t==0){

		cout<<"YES"<<endl;

	}

}

int main(){

	int T;

	cin>>T;

	while (T--){

		solve();

	}

	return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;

void solve(){

	int n,t=0;

	cin>>n;

	int a[n];

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

		cin>>a[i];

	}

	for (int i=0;i<n-1;++i){

		int mi=min(a[i],a[i+1]);

		if (a[i]>a[i+1]){

			cout<<"NO"<<endl;

			t=1;

			break;

		}

		if (a[i+2]<=a[i+1]){

			a[i]-=mi;

			a[i+1]-=mi;

		}

	}

	if (t==0){

		cout<<"YES"<<endl;

	}

}

int main(){

	int T;

	cin>>T;

	while (T--){

		solve();

	}

	return 0;

}

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

using namespace std;

void solve(){

	int n,t=0;

	cin>>n;

	int a[n];

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

		cin>>a[i];

	}

	for (int i=0;i<n-2;++i){

		int mi=min(a[i],a[i+1]);

		if (a[i]>a[i+1]){

			cout<<"NO"<<endl;

			t=1;

			break;

		}

		if (a[i+2]<=a[i+1]){

			a[i]-=mi;

			a[i+1]-=mi;

		}

	}

	for (int i=0;i<n-1;++i){

		if (a[i+1]<a[i]){

			cout<<"NO"<<endl;

			t=1;

			break;

		}

	}

	if (t==0){

		cout<<"YES"<<endl;

	}

}

int main(){

	int T;

	cin>>T;

	while (T--){

		solve();

	}

	return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;

void solve(){

	int n,t=0;

	cin>>n;

	int a[n];

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

		cin>>a[i];

	}

	for (int i=0;i<n-2;++i){

		int mi=min(a[i],a[i+1]);

		if (a[i]>a[i+1]){

			t=1;

			break;

		}

		if (a[i+2]<=a[i+1]){

			a[i]-=mi;

			a[i+1]-=mi;

		}

	}

	if (t==1){

		cout<<"NO"<<endl;

	}

	if (t==0){

		cout<<"YES"<<endl;

	}

}

int main(){

	int T;

	cin>>T;

	while (T--){

		solve();

	}

	return 0;

}

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

using namespace std;

void solve(){

	int n,t=0;

	cin>>n;

	int a[n];

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

		cin>>a[i];

	}

	for (int i=0;i<n-1;++i){

		int mi=min(a[i],a[i+1]);

		if (a[i]>a[i+1]){

			t=1;

			break;

		}

		a[i]-=mi;

		a[i+1]-=mi;

	}

	if (t==1){

		cout<<"NO"<<endl;

	}

	if (t==0){

		cout<<"YES"<<endl;

	}

}

int main(){

	int T;

	cin>>T;

	while (T--){

		solve();

	}

	return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;

void solve(){

	int n,t=0;

	cin>>n;

	int a[n];

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

		cin>>a[i];

	}

	for (int i=0;i<n-2;++i){

		int mi=min(a[i],a[i+1]);

		if (a[i]>a[i+1]){

			cout<<"NO"<<endl;

			t=1;

			break;

		}

		if (a[i+2]<=a[i+1]){

			a[i]-=mi;

			a[i+1]-=mi;

		}

	}

	for (int i=0;i<n-1;++i){

		if (a[i+1]<a[i]){

			cout<<"NO"<<endl;

			t=1;

			break;

		}

	}

	if (t==0){

		cout<<"YES"<<endl;

	}

}

int main(){

	int T;

	cin>>T;

	while (T--){

		solve();

	}

	return 0;

}

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

using namespace std;

void solve(){

	int n,t=0;

	cin>>n;

	int a[n];

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

		cin>>a[i];

	}

	for (int i=0;i<n-2;++i){

		int mi=min(a[i],a[i+1]);

		if (a[i]>a[i+1]){

			t=1;

			break;

		}

		if (a[i+2]<=a[i+1]){

			a[i]-=mi;

			a[i+1]-=mi;

		}

	}

	if (t==1){

		cout<<"NO"<<endl;

	}

	if (t==0){

		cout<<"YES"<<endl;

	}

}

int main(){

	int T;

	cin>>T;

	while (T--){

		solve();

	}

	return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;



#define int long long int

#define endl "\n"

#define fori(a, n) for(int i = a; i < n; i++)

#define vi vector<int> 



void solve() {





	int n; cin >> n;



	vi a(n);



	for(auto &x : a) {

		cin >> x;

	}



	for(int i = 0; i < n; i += 2) {

		if(a[i] > a[i + 1]) {

			cout << "NO" << endl;

			return;

		}	

	}

	





	cout << "YES" << endl;



	return;

}



signed main() {



	ios_base::sync_with_stdio(false);

	cin.tie(NULL); cout.tie(NULL);



	int t = 1;

	cin >> t;



	while(t--) 

		solve();



	return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;



#define int long long int

#define endl "\n"

#define fori(a, n) for(int i = a; i < n; i++)

#define vi vector<int> 



void solve() {





	int n; cin >> n;



	vi a(n);



	for(auto &x : a) {

		cin >> x;

	}



	for(int i = 0; i < n; i += 2) {

		if((i + 1) < n && a[i] > a[i + 1]) {

			cout << "NO" << endl;

			return;

		}	

	}

	

	if(n > 2 && a[n - 2] > a[n - 1]) {

		cout << "NO" << endl;

		return;

	}





	cout << "YES" << endl;



	return;

}



signed main() {



	ios_base::sync_with_stdio(false);

	cin.tie(NULL); cout.tie(NULL);



	int t = 1;

	cin >> t;



	while(t--) 

		solve();



	return 0;

}

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

using namespace std;



#define int long long int

#define endl "\n"

#define fori(a, n) for(int i = a; i < n; i++)

#define vi vector<int> 



void solve() {





	int n; cin >> n;



	bool flag = true;

	deque<int> dq(n);



	for(auto &x : dq)

		cin >> x;



	while((int)dq.size() > 1) {

		if(dq[0] > dq[1]) {

			flag = false;

			break;

		} else if(dq[0] < dq[1]) {

			dq[1] -= dq[0];

			dq.pop_front();

		} else {

			dq.pop_front();

			dq.pop_front();

		}

	}



	cout << (flag ? "YES" : "NO");

	cout << endl;



	return;

}



signed main() {



	ios_base::sync_with_stdio(false);

	cin.tie(NULL); cout.tie(NULL);



	int t = 1;

	cin >> t;



	while(t--) 

		solve();



	return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;



#define int long long int

#define endl "\n"

#define fori(a, n) for(int i = a; i < n; i++)

#define vi vector<int> 



void solve() {





	int n; cin >> n;



	vi a(n);



	for(auto &x : a) {

		cin >> x;

	}



	for(int i = 0; i < n; i += 2) {

		if(a[i] > a[i + 1]) {

			cout << "NO" << endl;

			return;

		}	

	}

	





	cout << "YES" << endl;



	return;

}



signed main() {



	ios_base::sync_with_stdio(false);

	cin.tie(NULL); cout.tie(NULL);



	int t = 1;

	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 int

#define endl "\n"

#define fori(a, n) for(int i = a; i < n; i++)

#define vi vector<int> 



void solve() {





	int n; cin >> n;



	vi a(n);



	for(auto &x : a) {

		cin >> x;

	}



	for(int i = 0; i < n; i += 2) {

		if((i + 1) < n && a[i] > a[i + 1]) {

			cout << "NO" << endl;

			return;

		}	

	}

	

	if(n > 2 && a[n - 2] > a[n - 1]) {

		cout << "NO" << endl;

		return;

	}





	cout << "YES" << endl;



	return;

}



signed main() {



	ios_base::sync_with_stdio(false);

	cin.tie(NULL); cout.tie(NULL);



	int t = 1;

	cin >> t;



	while(t--) 

		solve();



	return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: PyPy 3-64


Submission (verdict: Time limit exceeded on test 17):
for q in range(int(input())):
    n,k=list(map(int,input().split(' ')))
    a=list(map(int,input().split(' ')))
    d={}
    for i in range(n):
        if(a[i] not in d):
            d[a[i]]=1
        else:
            d[a[i]]+=1
    l=[]
    for i in d:
        l.append(d[i])
    pre=0
    ans=len(l)
    l.sort()
    for i in range(len(l)):
        if(pre+l[i]<=k):
            pre+=l[i]
            ans-=1
    print(max(ans,1))
Problem: 2057B - Gorilla and the Exam
Language: Python 3

Previous submission (verdict: Time limit exceeded on test 17):
for q in range(int(input())):
    n,k=list(map(int,input().split(' ')))
    a=list(map(int,input().split(' ')))
    d={}
    for i in range(n):
        if(a[i] not in d):
            d[a[i]]=1
        else:
            d[a[i]]+=1
    l=[]
    for i in d:
        l.append(d[i])
    pre=0
    ans=len(l)
    l.sort()
    for i in range(len(l)):
        if(pre+l[i]<=k):
            pre+=l[i]
            ans-=1
    print(max(ans,1))




Submission (verdict: Time limit exceeded on test 12):
for q in range(int(input())):
    n,k=list(map(int,input().split(' ')))
    a=list(map(int,input().split(' ')))
    d={}
    for i in range(n):
        if(a[i] not in d):
            d[a[i]]=1
        else:
            d[a[i]]+=1
    l=[]
    for i in d:
        l.append(d[i])
    pre=0
    ans=len(l)
    l.sort()
    for i in range(len(l)):
        if(pre+l[i]<=k):
            pre+=l[i]
            ans-=1
    print(max(ans,1))
Problem: 2057B - Gorilla and the Exam
Language: Python 3

Previous submission (verdict: Time limit exceeded on test 12):
for q in range(int(input())):
    n,k=list(map(int,input().split(' ')))
    a=list(map(int,input().split(' ')))
    d={}
    for i in range(n):
        if(a[i] not in d):
            d[a[i]]=1
        else:
            d[a[i]]+=1
    l=[]
    for i in d:
        l.append(d[i])
    pre=0
    ans=len(l)
    l.sort()
    for i in range(len(l)):
        if(pre+l[i]<=k):
            pre+=l[i]
            ans-=1
    print(max(ans,1))


Submission (verdict: Accepted):
for q in range(int(input())):
    n,k=list(map(int,input().split(' ')))
    a=list(map(int,input().split(' ')))
    b=set(a)
    d={}
    for i in b:
        d[i]=0
    for i in a:
        d[i]+=1
    l=[]
    for i in d:
        l.append(d[i])
    pre=0
    ans=len(l)
    l.sort()
    for i in range(len(l)):
        if(pre+l[i]<=k):
            pre+=l[i]
            ans-=1
    print(max(ans,1))
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):

#include<bits/stdc++.h>
#define int long long 
#define float long double
#define in2(x,y);  long long x,y; cin>>x>>y;
#define in3(x,y,z);  long long x,y,z; cin>>x>>y>>z;
#define fi(a,n) for(int i=a;i<n;i++)
#define fj(a,n) for(int j=a;j<n;j++)
#define fk(a,n) for(int k=a;k<n;k++)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back

using namespace std;

signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<set<int>> graph(n+1);
        fi(0,n-1)
        {
            in2(x,y);
            graph[x].insert(y);
            graph[x].insert(x);
            graph[y].insert(x);
            graph[y].insert(y);
        }
        int maxi=0;
        int ind=-1;
        fi(1,n+1)
        {
            if(maxi<graph[i].size())
           { maxi = max(maxi , (int)graph[i].size());
                ind = i;
           }
            
        }
        graph[ind].clear();
        fi(1,n+1)
        {
            graph[i].erase(ind);
        }
        maxi=0;
        fi(1,n+1)
        {
            if(maxi<graph[i].size())
           { maxi = max(maxi , (int)graph[i].size());
                ind = i;
           }
            
        }
        graph[ind].clear();
        fi(1,n+1)
        {
            graph[i].erase(ind);
        }
        // fi(0,n+1)
        // {
        //     for(auto value:graph[i])
        //     cout<<value<<" ";
        //     cout<<endl;
        // }
        queue<int> q;
        map<int,int> vis;
        int conn=0;
        int k=0;
        for(int i=1;i<=n ; i++)
        {
            if(vis[i]==0 && !graph[i].empty())
            {
            q.push(i);
            }
            else
            continue;

            vis[i]=1;
            while(!q.empty())
            {
                int first = q.front();
                q.pop();
                
                if(!graph[first].empty())
                {
                    for(auto value:graph[first])
                    {
                        if(vis[value]==0)
                        q.push(value);
                        vis[value]=1;
                    }
                    k=1;
                }
            }
            conn+=k;
            k=0;
        }
        cout<<conn<<endl;
    }
    return 0;
}