ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
 
using namespace std;
using ll = long long;
using vec = vector<int>;
using vecll = vector<ll>;

const int N = 2e5+5;
const ll INF = 1e18+10;
const int Intmax = 2147483647;
const int Intmin = -2147483648;

void solve(){
	string n;
	cin>>n;
	int sum = 0;
	int num2=0,num3=0;
	for(auto& c:n){
		if(c=='2') num2++;
		if(c=='3') num3++;
		sum += c-'0';
	}
	// cout<<sum<<" ";
	for(int i=0;i<min(num2+1,10);i++){
		for(int j=0;j<min(num3+1,10);j++){
			int k = sum+2*i+6*j;
			if(k%9==0){
				cout<<"YES"<<endl;return;
			} 
		}
	}
	cout<<"NO"<<endl;

}

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



Solution 2 (runtime: 93 ms):
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#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 tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
#define f(n) for(int i = 0 ; i < n ; i++)
#define all(x)  x.begin(), x.end() 
#define vi vector<int>
#define pi pair<int , int>
#define fl(a , b) for(int i = a ; i < b ; i++)
#define uid(a , b) uniform_int_distribution(a , b)(rng)
#define sz(x) (int)(x).size()

 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; 

/*
    1) Think Greedy
    2) Focus On the Note section and test cases.
    3) Think Solution In reverse order
    4) Think Graph
    5) Think Something Else (Algorithms or Some Intution Based On the test cases)
    6) Optimum use of the pair (playing with the second index !!)
    7) Proper Use Of Stacks (N R Q)

*/

/*
    What ----> How 
*/


signed main(){
    int test;
    cin >> test;
    while(test--){
        string s;
        cin >> s;
        int two = 0 , sum = 0 , three = 0;
        for(auto i : s){
            sum += (i - '0');
            two += (i == '2');
            three += (i == '3');
        }
        bool ok = false;
        for(int t = 0 ; t <= min(9ll , two) ; t++){
            for(int th = 0 ; th <= min(9ll , three) ; th++){
                if((sum + t * 2 + th * 6 )% 9 == 0){
                    ok = true;
                }
            }
        }
        if(ok){
            cout << "YES\n";
        }
        else{
            cout << "NO\n";
        }
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 374 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
    ll n;
    cin>>n;
    vector<ll>arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    if(is_sorted(arr.begin(),arr.end())){
        cout<<"YES"<<endl;
        return;
    }
    else{
        for(int i=0;i<n-1;i++){
            ll mi = min(arr[i],arr[i+1]);
            arr[i] -= mi;
            arr[i+1] -= mi;
        }
    }
    if(is_sorted(arr.begin(),arr.end())){
                cout<<"YES"<<endl;
                return;
            }
    cout<<"NO"<<endl;
    return;
}
int main(){
    int q;
    cin>>q;
    while(q--){
        solve();
    }
    return 0;
}

Solution 2 (runtime: 328 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll t;
    cin>>t;
    for (int i = 0; i < t; ++i) {
        ll n,f=1;
        cin>>n;
        vector<ll> ns(n);
        for (int j = 0; j < n; ++j) {
            cin>>ns[j];
        }
        ll l=-1,tmp,way=0;
        for (int j = 0; j < n; ++j) {
            tmp=ns[j];
            if(tmp<l){
                for (int k = way; k < j; ++k) {
                    ll a=min(ns[k],ns[k+1]);
                    ns[k]-=a;
                    ns[k+1]-=a;
                }
                way=j-1;
                if(ns[j]<ns[j-1]){
                    f=0;
                    break;
                }
            }
            l=ns[j];
        }
        if(f){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 452 ms):
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int> ma;
int n,m;
bool cal(int x)
{
if(ma[x]>0)
{
	ma[x]--;
	n--;
	return 1;
}
if(x==1)
	return 0;
return cal(x/2)&&cal(x/2+x%2);
}
void solve()
{

	cin>>n>>m;
	ma.clear();
	for(int i=1;i<=n;i++)
	{
		int temp;cin>>temp;
		ma[temp]++;
	}
	for(int i=1;i<=m;i++)
	{
		int temp;cin>>temp;
		if(cal(temp)==0)
		{
			cout<<"NO\n";
			for(int j=i+1;j<=m;j++)
				cin>>temp;
			return ;
		}
	}
	if(n==0)
	cout<<"YES\n";
else cout<<"NO\n";
	return;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin>>T;
	while(T--)
	solve();
}

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

constexpr int maxn = 2e5 + 5;
int n, m;
multiset<int> a, b;

void input()
{
    cin>>n>>m;
    a.clear(), b.clear();
    int x;
    for (int i = 1; i <= n; ++i)
    {
        cin>>x;
        a.insert(x);
    }
    for (int i = 1; i <= m; ++i)
    {
        cin>>x;
        b.insert(x);
    }
}

void solve()
{
    while (!a.empty() || !b.empty())
    {
        if (*a.begin() > *b.begin() || b.size() > a.size())
        {
            cout<<"NO\n";
            return;
        }
        else if (*a.begin() == *b.begin())
        {
            a.erase(a.begin());
            b.erase(b.begin());
        }
        else
        {
            int v = *b.begin();
            auto it = a.lower_bound(v);
            b.erase(b.begin());
            if (it != a.end() && *it == v)
            {
                a.erase(it);
                continue;
            }
            b.insert(v/2), b.insert(v - v/2);
        }
    }
    cout<<(a.empty() && b.empty() ? "YES\n" : "NO\n");
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen(_F".INP", "r"))
    {
        freopen(_F".INP", "r", stdin);
        freopen(_F".OUT", "w", stdout);
    }
    int t = 1; cin>>t;
    while (t--)
    {
        input();
        solve();
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

bool cmp(int a,int b){
	return a>b;
}

void solve(){
	int n,l,r;
	cin >> n >> l >> r;
	int a[n+1];
	vector<int> v1,v2,v3;
	int sum=0;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		if(i<=l-1) v1.push_back(a[i]);
		else if(i>=l&&i<=r) v2.push_back(a[i]),sum+=a[i];
		else v3.push_back(a[i]);
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end(),cmp);
	sort(v3.begin(),v3.end());
	
	int sum1=sum,sum2=sum;
	for(int i=0;i<min(v2.size(),v1.size());i++){
		if(v1[i]<v2[i]) sum1-=(v2[i]-v1[i]);
	}
	for(int i=0;i<min(v2.size(),v3.size());i++){
		if(v3[i]<v2[i]) sum2-=(v2[i]-v3[i]);
	}
	cout << min(sum1,sum2) << endl;
	
}

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

Solution 2 (runtime: 93 ms):
#include <iostream>
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
#define int long long


void solve(){
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> arr(n);
    for(int i = 0; i<n; i++){
        cin >> arr[i];
    }

    int sum1 = 0;
    for(int i = l-1; i<r; i++){
        sum1 = sum1 + arr[i];
    }

    vector<int> left;
    vector<int> right;

    for(int i = 0; i<r; i++){
        left.push_back(arr[i]);
    }

    for(int i = l-1; i<n; i++){
        right.push_back(arr[i]);
    }

    sort(left.begin(), left.end());
    sort(right.begin(), right.end());

    int ran = r - l + 1;
    int sum2 = 0, sum3 = 0;
    for(int i = 0; i<ran; i++){
        sum2 += left[i];
        sum3 += right[i];
    }

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

}




signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

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

void solve(int l,int r){
    int fir=0;
    
    for(int i=31;i>=0;i--){
        if(r & (1<<i)){
            fir+=1<<i;
            if(fir>l) break;
        }
    }
    
    int sec=fir-1;
    int thir=l;
    if(fir !=r) thir=r;
    else if(sec!=l) thir=l;
    else thir=fir-2;
    
    cout<<fir<<" "<<sec<<" "<<thir<<endl;
}
int main() {
	 int t;
	 cin>>t;
	 
	 while(t--){
	     int l,r;
	     cin>>l>>r;
	     
	      solve(l,r);
	 }
	 return 0;
}


Solution 2 (runtime: 62 ms):
/*
 Try Try Try ... Try forever
 ------------------------------------------------------------------------
 ░██╗░░░░░░░██╗░█████╗░██████╗░██╗░░██╗  ██╗░░██╗░█████╗░██████╗░██████╗░
 ░██║░░██╗░░██║██╔══██╗██╔══██╗██║░██╔╝  ██║░░██║██╔══██╗██╔══██╗██╔══██╗
 ░╚██╗████╗██╔╝██║░░██║██████╔╝█████═╝░  ███████║███████║██████╔╝██║░░██║
 ░░████╔═████║░██║░░██║██╔══██╗██╔═██╗░  ██╔══██║██╔══██║██╔══██╗██║░░██║
 ░░╚██╔╝░╚██╔╝░╚█████╔╝██║░░██║██║░╚██╗  ██║░░██║██║░░██║██║░░██║██████╔╝
 ░░░╚═╝░░░╚═╝░░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝  ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░
 ------------------------------------------------------------------------
 */
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define fast                    \
    ios::sync_with_stdio(NULL); \
    cin.tie(0);
using namespace std;
ll aa[1000009];
ll bb[1000009];
vector<ll> v;
map<ll, ll> mp;
set<ll> st;
pair<ll, ll> pp[1000009];
int xx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int yy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int main()
{
    fast int t = 1;
    cin >> t;
    while (t--)
    {
        int l, r;
        cin >> l >> r;
        int a = 0, b = 0;
        for (int i = 29; i >= 0; i--)
        {
            if ((l & (1 << i)) == (r & (1 << i)))
            {
                a |= (l & (1 << i));
                b |= (l & (1 << i));
                continue;
            }
            a |= ((1 << i) - 1);
            b |= (1 << i);
            break;
        }
        int c;
        if (a == l)
            c = b + 1;
        else
            c = l;
        cout << a << " " << b << " " << c << endl;
    }
}
Problem: 2049B - pspspsps
Language: c++17 

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

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define range(i, a, b, s) for (int i = a; (s > 0 && i < (b)) || (s < 0 && i > (b)); i += s)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

template <typename T>
void print_arr(vector<T> a) {
	trav(x, a) cout << to_string(x) << " ";
	cout << "\n";
}

int T;
int n;
vi a;
string s;

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

	cin >> T;
	while (T--) {
		cin >> n >> s;
		
		int s_cnt = 0;
		int p_cnt = 0;
		int pos = -1;
		rep(i, 0, n) {
			if (pos == -1 && s[i] != '.') pos = i;
			if (s[i] == 'p') p_cnt++;
			if (s[i] == 's') s_cnt++;
		}

		if (s_cnt == 0 || p_cnt == 0) {
			cout << "YES" << '\n';
			continue;
		}

		if (min(s_cnt, p_cnt) != 1) {
			cout << "NO" << '\n';
			continue;
		}

		if (s_cnt > p_cnt) {
			cout << (s[n-1] == 'p' ? "YES" : "NO") << '\n';
		} else if (p_cnt > s_cnt) {
			cout << (s[0] == 's' ? "YES" : "NO") << '\n';
		} else {
			cout << (s[0] == 's' || s[n-1] == 'p' ? "YES" : "NO") << '\n';
		}
	}

	return 0;
}


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

using namespace std;

typedef long long ll;



void solve() {

    int n;

    cin >> n;

    string s;

    cin >> s;

    int l1 = s.length();

    bool can = true;

    bool pf=false;

    bool sf=false;

	int s_found=-1;

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

		char x=s[i];

		if(x=='s'){

			sf=true;

			s_found=i;

			if(pf){

				can=false;

				break;

				}

			}

		if(x=='p'){

			pf=true;

			if(sf){

				if(s_found!=0 && i!=l1-1){can=false;break;}

				}

			}

		}

	if(can){

		cout<<"yes"<<endl;

		}

	else{

		cout<<"no"<<endl;

		}

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 343 ms):
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
int n;
const int maxn=2e5+5;
int a[maxn];
signed main(){
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        int ans=0,sum=0;
        for(int i=1;i<=n;i+=2)
            ans+=a[i];
        for(int i=2;i<=n;i+=2)
            sum+=a[i];
        if(n%2==0){
            if(ans%(n/2)!=0||sum%(n/2)!=0) cout<<"NO"<<endl;
            else{
                if(ans==sum) cout<<"YES"<<endl;
                else cout<<"NO"<<endl;
            }
        }else{
            if(ans%(n/2+1)!=0||sum%(n/2)!=0) cout<<"NO"<<endl;
            else{
                if(ans/(n/2+1)==sum/(n/2)) cout<<"YES"<<endl;
                else cout<<"NO"<<endl;
            }
        }
    } 
    return 0;
}

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

int main(){
    int t;
    std::cin>>t;
    while(t--){
        int n;
        std::cin>>n;
        int arr[n];
        for(int j=0;j<n;j++){
            std::cin>>arr[j];
        } 
        long long odd=0;
        long long even=0;
        for(int i=0;i<n;i++){
            if(i%2==0) even+=arr[i];
            else odd+=arr[i];
        }
        long oddPlace=n/2;
        long evenPlace=(n+1)/2;

        if(odd%oddPlace==0 && even%evenPlace==0 && odd/oddPlace==even/evenPlace) std::cout<<"Yes"<<std::endl;

        else std::cout<<"No"<<std::endl;
    }
        
    return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

using namespace std;

#ifdef LOCAL

#include "debug.h"

#else

#define debug(...) 42;

#define endl '\n'

#endif



#define int long long



int solve(int _) {

    int l, r, n;

    cin >> n >> l >> r;



    vector<int>a(n);

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

        cin >> a[i];

    }



    vector<int>b(a.begin(), a.begin() + r);

    vector<int>c(a.begin() + l - 1, a.end());

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

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



    // debug(l, r, a, b, c)

    return min(accumulate(b.begin(), b.begin() + (r - l + 1), 0ll), accumulate(c.begin(), c.begin() + (r - l + 1), 0ll));

}

signed main()

{

    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int _ = 1;

    cin >> _;

    while (_--) {

        cout << solve(_) << endl;

    }

}



Solution 2 (runtime: 187 ms):
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

// Function to solve the problem
long long solve(int n, vector<int> sequence, int l, int r) {
    vector<int> copy = sequence;
    
    // Sorting first 'r' elements in descending order
    sort(copy.begin(), copy.begin() + r, greater<int>());
    
    // Sorting from 'l' to 'n' in ascending order
    sort(sequence.begin() + (l - 1), sequence.end());
    
    long long left = 0, right = 0; // Use long long to store large sums
    
    for (int i = l - 1; i < r; i++) {
        left += copy[i];
        right += sequence[i];
    }
    
    return min(left, right);
}

int main() {
    int t;
    cin >> t;
    
    while (t-- > 0) {
        int n, l, r;
        cin >> n >> l >> r;
        vector<int> sequence(n);
        
        for (int i = 0; i < n; i++) {
            cin >> sequence[i];
        }
        
        cout << solve(n, sequence, l, r) << endl;
    }

    return 0;
}

//#include <iostream>
//#include <vector>
//#include <algorithm>
//
//using namespace std;
//int solve(int n, vector<int>& sequence, int l, int r) {
//    vector<int> left_part(sequence.begin(), sequence.begin() + r);
//    vector<int> right_part(sequence.begin() + (l - 1), sequence.end());
//    sort(left_part.begin(), left_part.end(), greater<int>());
//    sort(right_part.begin(), right_part.end()); // Ascending
//
//    int left_sum = 0, right_sum = 0;
//    for (int i = l - 1; i < r; i++) {
//        left_sum += left_part[i];
//        right_sum += right_part[i - (l - 1)];
//    }
//
//    return min(left_sum, right_sum);
//}
//
//int main() {
//    int t;
//    cin >> t;
//    
//    while (t-- > 0) {
//        int n, l, r;
//        cin >> n >> l >> r;
//        vector<int> sequence(n);
//        
//        for (int i = 0; i < n; i++) {
//            cin >> sequence[i];
//        }
//        
//        cout << solve(n, sequence, l, r) << endl;
//    }
//
//    return 0;
//}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 202 ms):
/******************************************************************************

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

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

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        vector<int>v(n);
        for(int i = 0;i<n;i++){
            cin >> v[i];
        }
        
        long long leftSum = 0;
        long long rightSum = 0;
        vector<int>left;
        vector<int>right;
        
        for(int i = 0;i<r;i++){
            left.push_back(v[i]);
        }
        for(int i = l-1;i<n;i++){
            right.push_back(v[i]);
        }
    
        
        sort(left.begin(),left.end());
        sort(right.begin(),right.end());
        
        for(int i = 0;i<r-l+1;i++){
            leftSum += left[i];
            rightSum += right[i];
        }
        
        cout<<min(leftSum,rightSum)<<endl;
        
    }

    return 0;
}

Solution 2 (runtime: 93 ms):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void solve(vector<ll> a, int l, int r) {
    vector<ll> b(a);
    sort(a.begin(), a.begin() + r+1, greater<>());
    sort(b.begin()+l, b.end());
    cout << min(
        accumulate(a.begin()+l, a.begin()+r+1, 0LL),
        accumulate(b.begin()+l, b.begin()+r+1, 0LL)
    )<< endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t; cin >> t;
    while(t--) {
        int n, l, r; cin >> n >> l >> r;
        vector<ll> a(n, 0);
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        solve(a, l-1, r-1);
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 202 ms):
#include "bits/stdc++.h"

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        long long int n,l,r;

        cin>>n>>l>>r;

        vector<long long int>v;

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

            long long int x;

            cin>>x;

            v.push_back(x);

        }

        sort(v.begin(),v.begin()+l-1);

        sort(v.begin()+l-1,v.begin()+r);

        sort(v.begin()+r,v.end());

        long long int i=0,j=r-1;

        long long int ans=INT_MIN;

        long long int temp=0;

        while(i<=l-1&&j>=l-1){

            if(i==l-1){

                temp+=v[j];

                j--;

            }

            else if(v[i]>=v[j]){

                temp+=v[j];

                j--;

            }

            else{

                temp+=v[i];

                j--;

                i++;

            }

        }

        ans=temp;

        temp=0;

        i=r-1;

        j=r;

        // cout<<"temp1 "<<ans<<endl;

        while(i>=l-1&&j<=v.size()){

            if(j==v.size()){

                temp+=v[i];

                i--;

            }

            else if(v[i]>v[j]){

                temp+=v[j];

                j++;

                i--;

            }

            else{

                temp+=v[i];

                i--;

            }

        }

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

        //     cout<<v[i]<<" ";

        // }

        // cout<<endl;

        ans=min(ans,temp);

        cout<<ans<<endl;

    }

}

Solution 2 (runtime: 202 ms):
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define INF 0x7fffffffffffffff
using namespace std;

int L[100005],R[100005],mid[100005];

void solve()
{
    int n,l,r,x;
    cin>>n>>l>>r;
    for (int i=1;i<=n;i++)
    {
        cin>>x;
        if (i<l)
            L[i]=x;
        else if (i>r)
            R[i-r]=x;
        else
            mid[i-l+1]=x;
    }
    sort(L+1,L+l);
    sort(R+1,R+n-r+1);
    sort(mid+1,mid+r-l+2);
    int sum=0,cnt=r-l+1,sum2=0,p=1,q=1;
    for (int i=1;i<=cnt;i++)
    {
        if (L[p]<mid[q]&&p<l)
        {
            sum+=L[p];
            p++;
        }
        else
        {
            sum+=mid[q];
            q++;
        }
    }
    p=1;
    q=1;
    for (int i=1;i<=cnt;i++)
    {
        if (R[p]<mid[q]&&p<n-r+1)
        {
            sum2+=R[p];
            p++;
        }
        else
        {
            sum2+=mid[q];
            q++;
        }
    }
    cout<<min(sum,sum2)<<endl;
}

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

    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;cin>>t;
    while (t--)
    {
        string n;cin>>n;
        int n_2=0,n_3=0;
        // string s=to_string(n);
        // cout<<s<<endl;
        int sum=0;
        // int x=stoi(s[1]);
        // cout<<s.size();
        for(int i=0;i<n.size();i++){
            sum+=n[i]-'0';
            if(n[i]=='2') n_2++;
            if(n[i]=='3') n_3++;
        }
        // cout<<n_2<<" "<<n_3<<endl;
        if(n_2 == 0 && n_3 == 0){
            if(sum%9==0) cout<<"Yes"<<endl; 
            else cout<<"No"<<endl;
        }
        else{
            int flag=0; 
            for(int i=0;i<=min(n_3,2);i++){
                for(int j=0;j<=min(n_2,8);j++){
                    if((sum+ 6*i + 2*j)%9 == 0){
                        flag=1;
                    }
                }
            }
            if(flag==1) cout<<"Yes"<<endl;
            if(flag==0) cout<<"No"<<endl;
        }
    }
    
}

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

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

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

 int rem=0;
int cnt2=0;
int cnt3=0;
 for(int i=0;i<s.length();i++)
 {

         rem=(rem+(s[i]-'0'))%9;

         if(s[i]=='2')
         cnt2++;

        if(s[i]=='3')
         cnt3++;
 }
 int flag=0;
// cout<<rem;
 for(int i=0;i<=min(cnt2,8);i++)
 {
     for(int j=0;j<=min(3,cnt3);j++)
     {
      //   cout<<i<<j<<"\n";
         if((rem+(i*2)%9+(j*6)%9)%9==0)
         {
             cout<<"YES\n";
             flag=1;
             break;
         }

     }
      if(flag)
         break;
 }
 if(!flag)
 cout<<"NO\n";
 }
}