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

Solution 1 (runtime: 62 ms):
// To the Moon and never back ... 
#include <bits/stdc++.h>
#define Maryam ios_base::sync_with_stdio(false);cin.tie(0);
#define ll long long    
using namespace std;
int main()
{
    Maryam;

    ll t; cin >> t; 
    while (t--)
    {
        string s; cin >> s;   

        for (ll i = 0; i < s.size(); i++)
        {
            ll p = i; char Max = s[i]; 
            for (ll j = 9; j >= 0; j--)
            {
                if (i + j >= s.size()) continue ; 

                char c = s[i + j] - j ; 
                if (c >= Max )  
                {
                    p = i + j;
                    Max = c;
                }
            }

            if (p > i)
            {
                for (ll j = p; j > i; j--)
                    s[j] = s[j - 1]; 

                s[i] = Max; 
            }
            //cout << p << ' ' << s << '\n';
        }
        cout << s << '\n'; 
    }

    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef vector<int> VI;

typedef vector<VI> VVI;

typedef vector<long long> VL;

typedef vector<VL> VVL;

typedef long long LL;

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

#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define ALL(a)  (a).begin(),(a).end()

#define pb push_back



string f(string s){

  int n=s.size();

  rep(i,n){

    int m=0,am=0;

    rep(j,10){

      if(i+j<n&&m<s[i+j]-'0'-j){

        m=s[i+j]-'0'-j; am=j;

      }

    }

    for(int j=am-1;j>=0;j--){

      swap(s[i+j],s[i+j+1]);

    }

    s[i]-=am;

  }

  return s;

}



void solv(){

  string s;cin>>s;

  cout<<f(s)<<endl;

}



int main() {

  int t;cin>>t;

  rep(i,t){solv();}

}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;
void solve(){
    int n, now;
    long long rez=-1e18;
    cin >> n;
    now=n;
    vector<long long> a(n);
    for(int i=0; i<n; i++)
        cin >> a[i];
    for(int i=0; i<n; i++){
        long long s=accumulate(a.begin(), a.begin()+now, 0LL);
        if(i==0)
            rez=max(rez, s);
        else
            rez=max(rez, max(s, -s));
        for(int i=0; i<now-1; i++)
            a[i]=a[i+1]-a[i];
        now--;
    }
    cout << rez << '\n';
}
int main(){
    FAST
    int t;
    cin >> t;
    while(t--)
        solve();
}

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

using namespace std;

int n, t;

void solve() {
    scanf("%d", &n);
    long long a[n];

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        scanf("%lli", a + i);
        ans += a[i];
    }

    for (int i = 1; i < n; i++) {
        long long curr = 0;
        for (int j = n - 1; j >= i; j--) {
            a[j] -= a[j - 1];
            curr += a[j];
        }
        ans = max(ans, abs(curr));
    }

    printf("%lli\n", ans);
}

int main() {
    scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

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

ll update(ll a[], ll n) {
    n -= 1;
    for (ll i = 0; i < n; i++) {
        a[i] = a[i+1] - a[i];
    }
    return n;
}

int main() {
    int t;
    cin >> t;
    while (t != 0) {
        int n;
        cin >> n;

        ll a[n];
        ll sum = 0; 
        for(ll i = 0; i < n; i++) {
            cin >> a[i];
            sum += a[i];
        }

        if (n == 1) {
            cout << sum << endl;
        }

        else {
            while (n > 1) {
                ll temp = abs(a[n-1] - a[0]);
                if (temp > sum) {sum = temp;}
                n = update(a, n);
            }

            if (a[0] > sum) {sum = a[0];}
            cout << sum << endl;
        }
        t--;
    }
    return 0;
}

Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
#define NMAX 55
#define pb push_back

using namespace std;

long long v[NMAX];

int main() {
    int tt;
    cin >> tt;
    while (tt--) {
        int n;
        long long maxx = LONG_LONG_MIN;
        cin >> n;
        long long s = 0;
        for (int i = 1; i <= n; i++) {
            cin >> v[i];
            s += v[i];
        }
        maxx = max(maxx, s);
        int p = n;
        while(p > 1) {
            long long s1 = 0, s2 = 0;
            for (int i = 1; i < p; i++) {
                v[i] = v[i + 1] - v[i];
                s1 += v[i];
                s2 += -(v[i]);
            }
            p--;
            maxx = max(maxx, max(s1, s2));
        }
        if (n > 1)
            cout << maxx << '\n';
        else cout << v[1] << '\n';
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

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

int main() {
    int t;
    cin>>t;
    while(t--){
        long long l,r;
        cin>>l>>r;
        long long ans=0;
        long long a,b,c;
        for(int i=30;i>=0;i--){
            long long b1=0;
            long long b2=0;

            if(l & (1LL<<i)){
                b1=1;
            }
            if(r & (1LL<<i)){
                b2=1;
            }

            if(b1==b2){
                ans+=b1*(1LL<<i);
            }
            else{
                a=ans+(1LL<<i);
                b=a-1;
                break;
            }
        }
        for(long long i=l;i<=r;i++){
            if(i!=a && i!=b){
                c=i;
                break;
            }
        }
        cout<<a<<" "<<b<<" "<<c<<endl;
    }
}

Solution 2 (runtime: 77 ms):
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#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;
   
typedef long long ll;
#define int long long
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#ifndef ONLINE_JUDGE
#include "ciphertxt.cpp"
#else
#define dff(...)
#define dfa(...)
#endif

vector<int> bin(int x){
    vector<int> arr;
    while(x){arr.push_back(x%2);x/=2;}
    while(arr.size()!=30){arr.push_back(0);}
    return arr;
}

void solve(){
    int l,r;cin>>l>>r;
    int i,j;    
    // int a,b,c;cin>>a>>b>>c;
    // cout<<(a ^ b) + (b ^ c) + (c ^ a)<<" ";cout<<endl;
    // bin(a);bin(b);bin(c);cout<<endl;
    auto la=bin(l);auto ra=bin(r);
    
    for(i=29;i>=0;i--){if(la[i]!=ra[i]){break;}}
    int a=0;
    int b=0;
    int id=i;int t=1;
    dff(la,ra);

    for(i=0;i<id;i++){a+=t;t*=2;}
    t*=2;
    for(i=id+1;i<30;i++){if(la[i]){a+=t;}t*=2;}

    t=1;
    for(i=0;i<id;i++){t*=2;}
    b+=t;
    t*=2;
    for(i=id+1;i<30;i++){if(ra[i]){b+=t;}t*=2;}
    int c=(a+b)/2;
    if(c==a || c==b){if(l<=(min(a,b)-1)){c=min(a,b)-1;}else if(r>=max(a,b)+1){c=max(a,b)+1;}}
    cout<<a<<" "<<b<<" "<<c<<endl;
   // cout<<(a ^ b)+(b ^ c) + (c ^ a) <<endl;
    }
    
 
signed main(){
    
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    
    #ifndef ONLINE_JUDGE
    freopen("rr.txt", "w", stderr);
    #endif

    int t;cin>>t;while(t--){
        solve();
        }
    return 0;
    }
Problem: 2062C - Cirno and Operations
Language: c++17 

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        vector<ll> a(n);
        for (ll i = 0; i < n; i++)
            cin >> a[i];
        ll ans = accumulate(a.begin(), a.end(), 0LL);
        while (a.size() > 1)
        {
            vector<ll> b(a.size() - 1);
            for (ll i = 0; i < a.size() - 1; i++)
                b[i] = a[i + 1] - a[i];
            a = b;
            ll sum = 0;
            for (ll x : a)
                sum += x;
            ans = max(ans, abs(sum));
        }
        cout << ans << '\n';
    }
    return 0;
}

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

void solve() {
    ll n, t;
    cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    ll len = n;
    ll sum = 0;
    if(n == 1){
      cout << a[0] << endl;
      return;
    }
    vector<ll> v;
    ll maxi = accumulate(a.begin(), a.end(), 0LL);
    while(len > 1){
      sum = 0;
      for(int i=0; i<len-1; i++){
        // sum += a[i];
        v.push_back(a[i+1] - a[i]);
      }
      
      for(ll i = 0; i < len - 1; i++){
        a[i] = v[i];
      }
      
      maxi = max(maxi, abs(accumulate(v.begin(), v.end(), 0LL)));
      v.clear();
      len--;
    }
    cout << maxi << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

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

    while (t--) {
        string n;
        cin>>n;
        string n1 = n;
        string n2 = n;
        int sum_1 = 0, count_2 = 0, count_3 = 0;
        for (char ch : n) {   
            sum_1 += int(ch - '0');
            if (ch == '2')    count_2++;
            if (ch == '3')    count_3++;
        }

        int flag = 0;

        for (int i = 0; i <= count_2; ++i) {
            for (int j = 0; j <= count_3; ++j) {
                int temp_sum = (j * (3) * (2)) + (i * (2) * (1));   
                //digit_count * digit * (digit - 1) = subtartcting digit and adding digit^2 for that count
                //digit can be 2, 3 only since digit^2 < 10; 0 and 1 wont change sum upon squaring.
                //basically squaring and updating sum (updates sum_1 = sum_1 + temp_sum) for each 
                //combination (i, j) to check if updated sum is ever divisible by 9.

                if ((sum_1 + temp_sum) % 9 == 0) {
                    flag = 1;
                    break;
                }
            }
            if (flag)    break;
        }

        if (flag)    cout<<"YES"<<endl;
        else    cout<<"NO"<<endl;
    }

    return 0;
}

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

using namespace std;

#define int long long

 

signed main() {

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int n = s.size();

        int sum = 0;

        int two,three;

        two = three = 0;

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

            sum+=s[i]-'0';

            if(s[i]-'0' == 2) two++;

            if(s[i]-'0' == 3) three++;

        }

        int flag=0;

        int a =10;

        two = min(a,two);

        three = min(a,three);

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

            for(int j=0;j<=three;j++){

                if((sum+i*2+j*6)%9==0){

                    flag++;

                    break;

                }

            }

        }

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

        else{

            cout<<"NO\n";

        }      

        }

        

    

    return 0;

}
Problem: 2063B - Subsequence Update
Language: c++17 

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


#define endl '\n'
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;

	while(t-- >0){
	

		ll s,l,r;
		cin>>s>>l>>r;
		vector<ll> vec(s);
		for(auto &x: vec){cin>>x;}	
		vector<ll> pref = vec;
		ll prefix=0;
		sort(pref.begin(),pref.begin()+r);

		reverse(pref.begin(),pref.begin()+r);
		for(int i = l-1;i<r;i++){
			prefix+=pref[i];
		}
		vector<ll> suffix = vec;
		ll suff=0;
		sort(suffix.begin()+l-1,suffix.end());

		for(int i = l-1;i<r;i++){
			suff+=suffix[i];
		}
		cout<<min(prefix,suff)<<endl;

	}


	return 0;
}


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

using namespace std;



#define ll long long int

#define ull unsigned long long int

#define ld long double

#define vi vector<int>

#define vll vector<ll>

#define pii pair<int, int>

#define pll pair<ll, ll>

#define mp make_pair

#define pb push_back

#define F first

#define S second

#define ALL(v) v.begin(), v.end()

#define SORT(v) sort(ALL(v))

#define REVERSE(v) reverse(ALL(v))

#define FOR(i, a, b) for (int i = a; i < b; ++i)

#define FORD(i, a, b) for (int i >= b; --i)

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



const ll MOD = 1e9 + 7;

const ll INF = 1e18;

const ld EPS = 1e-9;



ll gcd(ll a, ll b) {

    while (b != 0) {

        ll temp = b;

        b = a % b;

        a = temp;

    }

    return a;

}



ll lcm(ll a, ll b) {

    return (a / gcd(a, b)) * b;

}



ll mod_exp(ll base, ll exp, ll mod) {

    ll result = 1;

    while (exp > 0) {

        if (exp % 2 == 1) {

            result = (result * base) % mod;

        }

        base = (base * base) % mod;

        exp /= 2;

    }

    return result;

}



bool is_prime(ll n) {

    if (n <= 1) return false;

    if (n <= 3) return true;

    if (n % 2 == 0 || n % 3 == 0) return false;

    for (ll i = 5; i * i <= n; i += 6) {

        if (n % i == 0 || n % (i + 2) == 0) return false;

    }

    return true;

}



void solve() {

    // Your solution code here

    ll n,l,r;

    cin>>n>>l>>r;

    vll pre,seg,next;

    ll a;

    FOR(i,0,n){

        cin>>a;

        if(i<l-1){

          pre.push_back(a);

        }else if(i>=l-1 && i<r){

          seg.push_back(a);

        }else{

            next.push_back(a);

        }

    }



    SORT(pre);

    SORT(seg);

    REVERSE(seg);

    SORT(next);



    ll i = 0;

    ll j = 0;

   

    

    ll sum = 0;

    FOR(i,0,seg.size()) sum+=seg[i];

    ll sum1 = sum;

    ll sum2 = sum;

    while(i<pre.size() && j<seg.size()){

        if(seg[j]<=pre[i]) break;

        sum1+=pre[i];

        sum1-=seg[j];

        i++;

        j++;

    }

    i = 0;

    j = 0;



    while(i<next.size() && j<seg.size()){

        if(seg[i]<=next[j]) break;

       sum2+=next[i];

       sum2-=seg[j];

       i++;

       j++;

    }



   

    cout<<min(sum1,sum2)<<endl;

}



int main() {

    FAST_IO;



    int t;

    cin >> t;

    while (t--) {

        solve();

    }



    return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 78 ms):
#include <bits/stdc++.h>
int main() {
    int t;
    std::cin >> t;
    while (t--) {
        int l, r;
        std::cin >> l >> r;
        bool ok = false;
        for (int i = 30; i >= 0; --i) {
            if (r >= (1 << i)) {
                if ((1 << i) >= l + 1) {
                    std::cout << (1 << i) << ' ' << (1 << i) - 1 << ' ' << (l == (1 << i) - 1 ? r : l) << '\n';
                    ok = true;
                    break;
                }
            }
        }
        if (!ok) {
            int z = 0;
            while (!ok) {
                for (int i = 30; i >= 0; --i) {
                    if (r >= (1 << i)) {
                        if ((1 << i) >= l + 1) {
                            std::cout << z + (1 << i) << ' ' << z + (1 << i) - 1 << ' ' << z + (l == (1 << i) - 1 ? r : l) << '\n';
                            ok = true;
                            break;
                        } else {
                            r -= (1 << i);
                            l -= (1 << i);
                            z += (1 << i);
                        }
                    }
                }
            }
        }
    }
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
#define sz(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
#define Sum(a) accumulate((a).begin(), (a).end(), 0LL)
#define Min(a) *min_element(all(a))
#define Max(a) *max_element(all(a))
#define UB(a, x) upper_bound(all(a), x)
#define LB(a, x) lower_bound(all(a), x)
#define fr(i, x, n) for (i = x; i < n; i++)

const int MOD = 1e9 + 7;
int dir[] = {-1, 0, 1, 0, -1};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        ll l, r;
        cin >> l >> r;
        ll a = 0, b = 0, c = 0;
        ll cnt = 30;
        ll n = r;

        while (cnt--)
        {
            if (((1 << cnt) & l) == ((1 << cnt) & r))
            {
                a |= ((1 << cnt) & l);
                b |= ((1 << cnt) & l);
            }
            else
            {
                a |= (1 << cnt);
                b |= ((1 << cnt) - 1);
                break;
            }
        }
        for (ll i = l; i <= r; i++)
        {
            if (i != a && i != b)
            {
                c = i;
                break;
            }
        }
        cout << a << " " << b << " " << c << endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
int T,n,m,dp[1005][1005];
char a[1005],b[1005],c[2005];
#undef int
int main(){
	cin>>T;
	while(T--){
	scanf("%s",a+1),n=strlen(a+1);
	scanf("%s",b+1),m=strlen(b+1);
	scanf("%s",c+1);
	for(int i=1;i<=n;i++)dp[i][0]=dp[i-1][0]+(a[i]!=c[i]);
	for(int i=1;i<=m;i++)dp[0][i]=dp[0][i-1]+(b[i]!=c[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			dp[i][j]=min(dp[i-1][j]+(a[i]!=c[i+j]),
			             dp[i][j-1]+(b[j]!=c[i+j]));
	cout<<dp[n][m]<<endl;
	};
	return 0;
}


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

static const int inf = 1e9;

void solve() {
    std::string a, b, res;
    std::cin >> a >> b >> res;
    int n = (int) a.size(), m = (int) b.size();
    int dp[n + 1][m + 1];
    std::fill(&dp[0][0], &dp[0][0] + (n + 1) * (m + 1), inf);
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        dp[i + 1][0] = dp[i][0] + (a[i] != res[i]);
    }
    for (int j = 0; j < m; j++) {
        dp[0][j + 1] = dp[0][j] + (b[j] != res[j]);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = std::min(dp[i - 1][j] + (a[i - 1] != res[i + j - 1]),
                                dp[i][j - 1] + (b[j - 1] != res[i + j - 1]));
        }
    }
    std::cout << dp[n][m] << std::endl;
}

int main() {
    int tests;
    std::cin >> tests;
    while (tests--) {
        solve();
    }
}
Problem: 2050E - Three Strings
Language: c++17 

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

int solve(string &a, string &b, string &c){
    int n = a.size(), m = b.size();
    vector<vector<int>> dp(n+1,vector<int>(m+1,INT_MAX));
    // Base case initialization
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        dp[i][0] = dp[i - 1][0] + (a[i - 1] != c[i - 1]);
    }
    for (int j = 1; j <= m; j++) {
        dp[0][j] = dp[0][j - 1] + (b[j - 1] != c[j - 1]);
    }

    // Fill the DP table
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int ta = (a[i - 1] != c[i + j - 1]);  // Cost if we take a[i-1]
            int tb = (b[j - 1] != c[i + j - 1]);  // Cost if we take b[j-1]
            dp[i][j] = min(dp[i - 1][j] + ta, dp[i][j - 1] + tb);
        }
    }

    return dp[n][m];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        cout<<solve(a,b,c)<<"\n";
    }

    return 0;
}

Solution 2 (runtime: 61 ms):
#include<bits/stdc++.h>
using namespace std;
const int N=1010;
int T,dp[N][N];
char a[N],b[N],c[2*N];
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%s%s%s",a+1,b+1,c+1);
		int n=strlen(a+1),m=strlen(b+1);
		for(int i=0;i<=n;i++)
			for(int j=0;j<=m;j++){
				if(i==0 && j==0){
					dp[0][0]=0;
					continue;
				}
				dp[i][j]=2e9;
				if(i!=0) dp[i][j]=min(dp[i][j],dp[i-1][j]+(a[i]!=c[i+j]));
				if(j!=0) dp[i][j]=min(dp[i][j],dp[i][j-1]+(b[j]!=c[i+j]));
			}
		printf("%d\n",dp[n][m]);
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 124 ms):
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int>mp;
vector<int>num;
int n,m,idt,x;
void solve(){
	mp.clear();
	num.clear();
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x);
		mp[x]++;
	}
	for(auto _:mp){
		num.push_back(_.second);
	}
	sort(num.begin(),num.end());
	bool flag=false;
	int s=num.size();
	for(int i=0;i<s;i++){
		if(m>=num[i]){
			m-=num[i];
		}
		else{
			printf("%lld\n",s-i);
			flag=true;
			return;
		}
	}
	printf("1\n");
}
signed main(){
#ifdef USE_FILE_IO
	freopen("code.in","r",stdin);
	freopen("code.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

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

#define int long long
#define debug(x) cout<<#x<<"="<<x<<'\n'


void f()
{
    int n, k;
    cin>>n>>k;
    vector<int> a(n+1);
    map<int,int> mp;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    set<pair<int,int>> st;
    for(auto it: mp) st.insert({it.second,it.first});
    int ans=st.size();
    for(auto it: st)
    {
        if(k>=it.first)
        {
            k-=it.first;
            ans--;
        }
    }
    cout<<max(1ll,ans)<<"\n";
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tt=1;
    cin>>tt;
    while(tt--) f();
    return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <stdio.h>

int main()
{
    int t;
    scanf("%d", &t);

    while(t--)
    {
        char s[200001];
        scanf("%s", s);

        for(int i = 0; s[i] != '\0'; )
        {
            if(s[i + 1] - s[i] > 1)
            {
                s[i + 1]--;
                s[i] ^= s[i + 1];
                s[i + 1] ^= s[i];
                s[i] ^= s[i + 1];
                if(i)
                    i--;
                else
                    i++;
                continue;
            }
            i++;
        }
        puts(s);
    }

    return 0;
}

Solution 2 (runtime: 61 ms):
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define fori(n) for(ll i=0;i<n;i++)
#define forj(n) for(ll j=0;j<n;j++)
#define pb push_back
#define sorts(a) sort((a).begin(),(a).end())
ll solve(){
    string s;
    cin>>s;
    ll n=s.size();
    fori(n-1){
      ll m=s[i];
      ll ind=i;
      for(ll j=i+1;j<n && j-i<=9;j++){
        if(s[j]-(j-i)>m){
          m=s[j]-(j-i);
          ind=j;
        }
      }
      if(ind>i){
        char x=s[ind]-(ind-i);
        for(ll j=ind;j>=i+1;j--){
          s[j]=s[j-1];
        }
        s[i]=x;
      }
    }
    cout<<s<<endl;
    
    return 0;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll t=1;
    cin>>t;
    while(t--){
        solve();
    }
}