ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define endl "\n"
#define inf LLONG_MAX
#define _inf LLONG_MIN
#define fors(i, a, b) for (long long i = a; i <= b; i++)
#define fors_(i, a, b) for (long long i = a; i >= b; i--)


int myMax(int a, int b) {
    return (a > b) ? a : b;
}
 
void Aastik(){
   string s; cin>>s;
   if(s.length()==1) cout<<s<<endl;
   else{
   fors(i,0,s.length()-2){
    int curr=s[i]-'0';
    int new1=curr; int ind=-1;
    for(int j=i+1;j<=i+9;j++){
        if(j<s.length()){
        int new2=s[j]-'0';
        if(new2-(j-i)>new1) {new1=new2-(j-i);
        ind=j;}
        }

    }
    if(ind!=-1){
        for(int j=ind;j>i;j--){
            char k=s[j-1];
            s[j]=s[j]-1;
            s[j-1]=s[j];
            s[j]=k;
        }

    }
   }

   cout<<s<<endl;
   }
}
  

   

signed main() {
    int t;
    cin >> t;
    while (t--) {
        Aastik();
    }
    return 0;
}

Solution 2 (runtime: 140 ms):
#include<iostream>

using namespace std;

 int  main()

 {

     int  test;

     cin>>test;

     

     while(test--)

     {

         string arr;

         cin>>arr;

         int n=arr.size();

         

      for(int i=0;i<arr.size()-1;i++)

     {

         int max=arr[i];

         int index=i;

         for(int j=i+1;j< min(i+10,n);j++)

         {

             

             

             if((arr[j]-j+i)>max)

             {

                 max=arr[j]-j+i;

                 index=j;

                 

                 

                 

                 

             }

         }

         if(index>i)

         {

             int a=index;

             while(a>i)

             {

                 arr[a]=arr[a-1];

                 a--;

             }

             arr[i]=max;

         }

     }

     

     

     for(int i=0;i<arr.size();i++)

     {

         cout<<arr[i];

     }

     cout<<endl;

        

        

        

     }

 }
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 311 ms):
#include<bits/stdc++.h>
using namespace std;
#define maxn 1005
int id[maxn];


int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) {
        int x;
        cin>>x;
        id[x]=i;
    }
    vector<pair<int,int>>ans;
    vector<int>a;
    a.push_back(n);
    for(int i=n-1;i>=1;i--) {
        vector<int>b;
        for(int j=0;j<a.size();j++) {
           // cout<<a[j]<<' '<<i<<'\n';
            if(id[a[j]]<id[i]) {
               // cout<<"fuc"<<' '<<a[j]<<' '<<i<<' '<<a.size()<<'\n';
                ans.push_back({a[j],i});
                b.push_back(a[j]);
                //cout<<1<<'\n';
            }else {
               // cout<<"wa"<<'\n';
                b.push_back(i);
                for(int k=j;k<a.size();k++) {
                    ans.push_back({a[k],i});
                    b.push_back(a[k]);
                }
                for(int k=a.size()-1;k>=j;k--) {
                    ans.push_back({i,a[k]});
                }
                break;
            }
            if(j==(a.size()-1))
            b.push_back(i);
        }
        a=b;
        // for(auto x:a) {
        //     cout<<x<<' ';
        // }cout<<'\n';
    }
    cout<<ans.size()<<'\n';
    for(auto [x,y]:ans) {
        cout<<x<<' '<<y<<'\n';
    }
}

Solution 2 (runtime: 1546 ms):
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define INF LLONG_MAX
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<int,int>>
#define all(v) v.begin(),v.end()

void solve() {
    int n;
    cin>>n;
    vi a(n);
    map<int,int>pos;
    for(int i=0;i<n;i++){
        cin>>a[i];
        pos[a[i]]=i;
    }
    if(n==1){
        cout<<0<<endl;
        return;
    }
    map<pair<int,int>,int>flag;
    int cnt=0;
    int n1=n;
    vi temp(n);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(a[i]<a[j]){
                flag[{a[i],a[j]}]=2;
                cnt+=2;
            }else{
                flag[{a[j],a[i]}]=1;
                cnt++;
            }
        }
    }
    for(int i=0;i<n;i++)temp[i]=i+1;
    // for(auto i : temp)cout<<i<<" ";
    // cout<<endl;
    vp ans;
    cout<<cnt<<endl;
    while(n1--){
        for(int i=0;i<n-1;i++){
            int mn=min(temp[i],temp[i+1]);
            int mx=max(temp[i],temp[i+1]);
            if(flag[{mn,mx}]>0){
                // cout<<"dhdh"<<endl;
                flag[{mn,mx}]--;
                ans.pb({temp[i+1],temp[i]});
                swap(temp[i],temp[i+1]);
            }
            
        }
        // for(auto i : temp)cout<<i<<" ";
        // cout<<endl;
    }
    // cout<<cnt<<endl;
    // for(auto i : flag){
    //     cout<<i.first.first<<" "<<i.first.second<<endl;
    //     cout<<i.second<<endl;
    // }
    for(auto i : ans){
        cout<<i.first<<" "<<i.second<<endl;
    }
}

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

    int t;
    // cin >> t;
    t=1;

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

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 1311 ms):
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>// find_by_order, order_of_key
#define int long long
#define vsort(t) sort(t.begin(),t.end())
#define asort(t,n) sort(t,t+n)
#define tw(n) (1ll<<n)
void solve(){
    int n;
    cin>>n;
    int a[n];
    int b[n];
    vector<pair<int,int>>ans;
    unordered_map<int,int>pos;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=i+1;
        pos[b[i]]=i;
    }
    // cout<<pos[a[n-1]]<<endl;
    for(int i=n-1;i>=0;i--){
        int ind=pos[a[i]];
        for(int j=ind-1;j>=0;j--){
            ans.push_back({b[j+1],b[j]});
            swap(b[j],b[j+1]);           
        }
        for(int j=1;j<=i;j++){
            ans.push_back({b[j],b[j-1]});
            swap(b[j],b[j-1]); 
        }
        for(int j=0;j<n;j++){
            pos[b[j]]=j;
            // cout<<b[j]<<" ";
        }
        // cout<<endl;
    }
    cout<<ans.size()<<endl;
    if(!ans.empty()){
        for(auto i :ans){
            cout<<i.first<<" "<<i.second<<endl;
        }
    }
}

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

Solution 2 (runtime: 1062 ms):
//#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define MAX 1050
#define inf 0x7fffffff
using namespace std;
typedef long long ll;

int datas[MAX];
int choiced[MAX];
int n;
vector<pair<int,int>> ans;

void calcu()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        choiced[x]=1;
        for(int i=x;i<=n;i++)
        {
            if(choiced[i]==0)
            {
                ans.push_back({i,x});
            }
        }
        for(int i=n;i>=1;i--)
        {
            if(choiced[i]==0)
            {
                ans.push_back({x,i});
            }
        }
    }
    cout<<ans.size()<<endl;
    for(auto [x,y]:ans)
    {
        cout<<x<<' '<<y<<endl;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); 
    cout.tie(0);
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        calcu();
    }
    system("pause");
    return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 218 ms):
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int MAXN = 1e6 + 5;
const int inf = 2147483627;
const int mod = 998244353;
int a[MAXN],b[MAXN],c[MAXN];
signed main () {

	int N,n,l,r;
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>n>>l>>r;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			b[i]=a[i];
			c[i]=a[i];
		}
		sort(b+1,b+1+r);
		sort(c+l,c+1+n);
		int ans1=0,ans2=0;;
		for(int i=1;i<=r-l+1;i++)
		{
			ans1+=b[i];
		}
		for(int i=l;i<=r;i++)
		{
			ans2+=c[i];
		}
		cout<<min(ans1,ans2)<<endl;
	}
	return 0;
}



Solution 2 (runtime: 78 ms):
#include<bits/stdc++.h>
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long int
#define dec greater<int>()
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
void solve()
{
    int n,l,r,sum=0;
    cin>>n>>l>>r;
    vector<int>v(n),a;
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        if(i>=l-1 && i<r)
        {
            sum += v[i];
            a.push_back(v[i]);
        }
    }
    sort(v.begin(),v.begin()+l-1);
    sort(all(a),dec);
    int tmp=sum,res=sum;
    for(int i=0; i<min(l-1,(long long)a.size()); i++)
    {
        tmp -= a[i];
        tmp += v[i];
        res=min(res,tmp);
    }
    sort(v.begin()+r,v.end());
    tmp=sum;
    int bound=min(n-r,(long long)a.size());
    for(int i=0; i<bound; i++)
    {
        tmp-=a[i];
        tmp+=v[i+r];
        res=min(res,tmp);
    }
    cout<<res<<'\n';
}
 
signed main()
{
    fast;    
    int t=1;
    cin>>t;
    while(t--)
      solve();
}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 718 ms):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

// https://codeforces.com/blog/entry/62393
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

void solve() {
	int n;
	cin >> n;
	vector<vector<int>> adjList(n);
	vector<int> deg(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adjList[u].push_back(v);
		adjList[v].push_back(u);
		deg[u]++;
		deg[v]++;
	}
	int ans = 0;
	multiset<int> cnt(deg.begin(), deg.end());
	for (int i = 0; i < n; i++) {
		for (int x : adjList[i]) {
			cnt.erase(cnt.find(deg[x]));
			cnt.insert(deg[x] - 1);
		}
		int can = deg[i];
		cnt.erase(cnt.find(deg[i]));
		can += *cnt.rbegin();
		ans = max(ans, can);
		cnt.insert(deg[i]);
		for (int x : adjList[i]) {
			cnt.erase(cnt.find(deg[x] - 1));
			cnt.insert(deg[x]);
		}
	}
	cout << ans - 1 << endl;
}

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



Solution 2 (runtime: 640 ms):
#include<bits/stdc++.h>
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long int
#define dec greater<pair<int,int>>()
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }

void solve()
{
    int n;
    cin>>n;
    vector<int> in_degree(n + 1);
    map<pair<int,int>,int>mp;
    for(int i=0; i<n-1; i++)
    {
        int u,v;
        cin>>u>>v;
        in_degree[u]++;
        in_degree[v]++;
        mp[{u,v}]++;
        mp[{v,u}]++;
    }
    vector<pair<int,int>>vp;
    for(int i=1; i<=n; i++){
        vp.push_back({in_degree[i],i});
    }
    sort(all(vp),dec);
    //for(auto &[x,y] : vp)cout<<x<<' '<<y<<'\n';
    int res=0;
    for(int i=0; i<vp.size(); i++)
    {
        for(int j=i+1; j<vp.size(); j++)
        {
            if(!mp.count({vp[i].second,vp[j].second})){
                res = max(res, vp[i].first + vp[j].first - 1);
                break;
            }
        }
    }

    for(auto ii : mp)
    {
        int x=ii.first.first,y=ii.first.second;
        res=max(res,in_degree[x]+in_degree[y]-2);
    }
    cout<<res<<'\n';
}
 
signed main()
{
    fast;    
    int t=1;
    cin>>t;
    while(t--)
      solve();
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define rev(a) reverse(a.begin(),a.end())
#define s1(a) sort(a.begin(),a.end())
#define s2(a,n) sort(a,a+n)
#define cy cout << "YES" << endl;
#define cn cout << "NO" << endl;
#define g(x,y) __gcd(x,y)
#define minV(ans) *min_element(ans.begin(), ans.end())
#define maxV(ans) *max_element(ans.begin(), ans.end())
#define merge(v1,v2) v1.insert(v1.end(), v2.begin(), v2.end());
    
// vector<int> v(arr, arr + n); // convert array to vector
// sort(arr,arr+n); // sort array
//  auto n = find(v.begin(),v.end(),5); cout<<*n; // check if element is present or not
// lower_bound(begin(a), end(a), v) - begin(a)
    
void solve(){
    int n,l,r; cin>>n>>l>>r;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    vector<int> b,c;
    for(int i=0; i<r; i++){
        b.push_back(a[i]);
    }
    for(int i=l-1; i<n; i++){
        c.push_back(a[i]);
    }
    s1(b); s1(c);
    
    int num = r-l+1;
    int sum1=0,sum2=0;

    if(b.size()==0){ sum1=INT_MAX;}
    if(c.size()==0){ sum2=INT_MAX;}

    for(int i=0; i<num; i++){
        if(i>=b.size()) {sum1 = INT_MAX; break;}
        else {sum1+=b[i];}
    }
    for(int i=0; i<num; i++){
        if(i>=c.size()) {sum2 = INT_MAX; break;}
        else {sum2+=c[i];}
    }
      cout<<min(sum1,sum2)<<endl;
}
    
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--) solve();
return 0;
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
#define int long long
typedef pair<int,int> PII;
int n,m,a[N],num;
int ask(int l,int r){
    vector<int>v;
    for(int i=l;i<=r;i++){
        v.push_back(a[i]);
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<num;i++) ans+=v[i];
    return ans;
}
void solve(){
    int l,r;
    cin>>n>>l>>r;
    num=r-l+1;
    for(int i=1;i<=n;i++) cin>>a[i];
    int ans= ask(1,r);
    ans=min(ans, ask(l,n));
    cout<<ans<<'\n';

}
signed main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _=1;
    cin>>_;
    while(_--){
        solve();
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 265 ms):
#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;


}



Solution 2 (runtime: 1108 ms):
#include<bits/stdc++.h>

// #define OPEN_FILE 1
using namespace std;

int t = 1, n;
int a[1005];
vector<int> x,y;
void solve() {
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    vector<int> nums(n);
    iota(nums.begin(), nums.end(), 1);
    for(int i = n - 1; i >= 0; i--) {
        int k = 0;
        while (k < n && nums[k] != a[i]) {
            k++;
        }
        
        for(int j = k - 1; j >= 0; j--) {
            x.push_back(nums[k]);
            y.push_back(nums[j]);
        }
        for(int j = 0; j < k; j++) {
            x.push_back(nums[j]);
            y.push_back(nums[k]);
        }
        for(int j = k + 1; j <= i; j++) {
            nums[j - 1] = nums[j];
            x.push_back(nums[j]);
            y.push_back(a[i]);
        }
        nums[i] = a[i];
    }
    cout<<x.size()<<endl;
    for(int i = 0; i < x.size(); i++) {
        cout<<x[i]<<" "<<y[i]<<endl;
    }
    x.clear();
    y.clear();
}


int main() {
    #ifdef OPEN_FILE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    // cin>>t;
    while(t-- > 0) {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 342 ms):
#include <bits/stdc++.h>
using namespace std;
#define lint long long
#define NL printf("\n")
#define YES printf("YES\n")
#define NO printf("NO\n")


int main(){
	int t;
    cin>>t;
    // t=1;
    while(t--){
        lint n,m;
        cin>>n;
        int a[n];
        for(int i=0; i<n; i++) cin>>a[i];
        int f=0;
        if(a[0]>a[1]){
            NO;
            continue;
        }
        for(int i=0; i<n-2; i++){
            if(a[i+1]-a[i]>a[i+2]){
                f=1;
            }
            else a[i+1]=a[i+1]-min(a[i], a[i+1]);
        }
        if(f) NO;
        else YES;

        
        
        

	}
    
	
}

Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>

using namespace std;



void solve(){



    int n; cin >> n;



    vector< int > v;



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

        int x; cin >> x;

        v.push_back(x);

    }

    

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

        cout << "NO\n";

        return;

    }



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

        int mi = min(v[ i - 1 ], v[ i ]);

        v[ i - 1 ] -= mi;

        v[ i ] -= mi;

    }





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

        if(v[ i ] < v[ i - 1 ]){

            cout << "NO\n";

            return;

        }

    }



    cout << "YES\n";

    



}



int main(){



    ios_base::sync_with_stdio(0);

    cin.tie(0); cout.tie(0);



    int t; cin >> t;



    while(t--){

        solve();

    }



    return 0;



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

Solution 1 (runtime: 203 ms):
#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vector<int>a(n);
        map<int,int>mapping;
        for(int i=0;i<n;i++){
            cin>>a[i];
            mapping[a[i]]++;
        }
        vector<int>freq;
        for(auto i:mapping){
            freq.push_back(i.second);
        }
        
        sort(freq.begin(),freq.end());
        for(int i=0;i<n;i++){
            if(freq[i]<=k){
              k=k-freq[i];
              freq[i]=0;
            }else{
                freq[i]=freq[i]-k;
                k=0;
                break;
            }
        }
        int count=0;
        for(auto i:freq){
            if(i!=0){
                count++;
            }
        }
        if(count==0){
            count=count+1;
        }
       cout<<count<<endl;
    }
}


Solution 2 (runtime: 155 ms):
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include<climits>
#include<cmath>
using namespace std;

using ll = long long;
#define endl "\n"
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pbk push_back
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); (a)++)
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int,int>

const int mod = 1e9 + 7;
bool mycomp(pair<ll,ll> &a,pair<ll,ll> &b){
    if(a.ff == b.ff) return a.ss > b.ss;
    return a.ff < b.ff;
   // return a.ss < b.ss;
}

void solve(){
    int n,k;
    cin >> n >> k;
    vector<int> V(n);
    int maxf = 0;
    int maxele = -1;
    
    map<int,int> Freq;
    Freq[-1] = 0;
    for(int i=0; i<n; i++){
        cin >> V[i];
        Freq[V[i]]++;
        if(Freq[maxele] < Freq[V[i]]){
            maxele = V[i];
        }
    }
    Freq.erase(-1);
    int cnt = Freq.size();
    
    vector<pair<int,int>> freqVec;
    for (auto &p : Freq) {
        if (p.first != maxele) {
            freqVec.push_back(p);
        }
    }
    sort(freqVec.begin(), freqVec.end(), [](const pair<int,int> &a, const pair<int,int> &b){
        return a.second < b.second;
    });
    for(auto &p : freqVec){
        if(k >= p.ss){
            k -= p.ss;
            cnt--;
        }
        else break;
    }
    cout << cnt << endl;
}
int main() {
    fast_io;
    int t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 124 ms):
#include <bits/stdc++.h>



#define ll long long int

#define for1(x1) for(ll i = 0; i < x1; i++)

#define for2(x2) for(ll j = 0; j < x2; j++)

#define for3(vc_1) for(auto &it : vc_1) cin >> it;

#define so(x3) sort((x3).begin(), (x3).end())

#define rev(x3) reverse((x3).begin(), (x3).end())

#define nl endl

#define nb "\n"

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

#define all(container) (container).begin(), (container).end()

using namespace std;



istream& operator>> (istream &input, vector <ll> &vc_1)

{

    for3(vc_1);

    return input;

}



const ll mod = 1e9 + 7;

const int N = 2e5 + 5;  



vector<int> adj[N];     

bool vis[N];      





ll gcd(ll a, ll b)

{

    if(b == 0) return a;

    return gcd(b, a%b);

}



ll mult(ll a, ll b)

{

    return (a%mod * b%mod)%mod;

}



ll add(ll a, ll b)

{

    return (a%mod + b%mod)%mod;

}



ll subtract(ll a, ll b)

{

    return (a%mod - b%mod + 2*mod)%mod;

}







char di[] = {'D', 'L', 'U', 'R'};

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

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





void Ahmed_log()

{

    ll siz; cin >> siz; vector <ll> vc_1 (siz); cin >> vc_1;

    if (vc_1[0] > vc_1[1])

    {

        cout << "NO" << nl;

        return;

    }

    ll a1 , a2;

    for1(siz - 1)

    {

        a1 = vc_1[i] , a2 = vc_1[i + 1];

        if (a1 <= a2)

        {

            vc_1[i] = 0;

            vc_1[i + 1] -= a1;

        }

        else

        {

            cout << "NO" << nl;

            return;

        }

    }

    cout << "YES" << nl;

}



// Example: nums.erase(remove(nums.begin(), nums.end(), Player1), nums.end());



int main()

{

    fast_IO;

    ll test_case = 1;

    cin >> test_case;

    while(test_case--)

    {

        Ahmed_log();

    }

    return 0;

}

Solution 2 (runtime: 374 ms):
#include<bits/stdc++.h>

using namespace std;

int main()

{

int n,t;

cin >> t;

while(t-- > 0)

{

cin >> n;

vector<int> x(n);

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

{

cin >> x[i];

}

bool flag = 0;

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

{

if(i)

x[i] = x[i] - x[i - 1];

if(x[i] < 0 || x[i] > x[i + 1])

{

flag = 1;

break;

}

}

if(flag) cout << "NO\n";

else cout << "YES\n";



}

}