ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NITRO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define workWithFiles freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)
#define mod 1000000007

#define int long long

using namespace std;


void solve() {
	int l, r;
	cin >> l >> r;
	bitset<32> a(l);
	bitset<32> b(r);
	bool finish = false;
	for (int i = 31; i >= 0; i--) {
		if (finish) {
			a[i] = 1;
			b[i] = 0;
		}
		if (a[i] != b[i]) {
			finish = true;
		}
	}
	int res1 = a.to_ullong();
	int res2 = b.to_ullong();
	cout << res1 << " " << res2 << " ";
	if (l < res1) cout << l << endl;
	else cout << r << endl;
}


int32_t main() {
	NITRO;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	clock_t s = clock();

	int t = 1;

	cin >> t;

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

	cerr << "Run Time : " << ((double)(clock() - s) / CLOCKS_PER_SEC);
}



Solution 2 (runtime: 92 ms):
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll; 
int main() {
    ll t; 
    cin >> t; 
    while (t--) {
        ll l, r; 
        cin >> l >> r;
        ll a, b, c; 
        ll still = 0; 
        for (ll i = 30; i >= 0; i--) {
            if ((l >> i) % 2 == (r >> i) % 2) {
                still += (1ll << i) * ((l >> i) & 1); 
                continue; 
            }
            b = (1ll << i); 
            a = b - 1; 
            c = 0; 
            if (a + still - 1 >= l)
                c = a - 1; 
            else
                c = b + 1; 
            break; 
        }
        cout << a + still << ' ' << b + still << ' ' << c + still << endl;
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 108 ms):
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,sse4a,avx,avx2,popcnt,tune=native")
#include<bits/stdc++.h>
using namespace std;



#define ll long long




int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
    
    int n;
    cin>>n;
    
    ll arr[n];
    ll brr[n];
    for(int i=0;i<n;i++) {
        cin>>arr[i];
        brr[i]=arr[i];
    }
    
    
    ll x=min(arr[0],arr[1]);
    arr[0]-=x;
    arr[1]-=x;
    for(int i=1;i<n-1;i++){
         x=min(arr[i],arr[i+1]);
        arr[i]-=x;
        arr[i+1]-=x;
    }
    
    x=min(brr[n-1],brr[n-2]);
   
    brr[n-1]-=x;
    brr[n-2]-=x;
    for(int i=n-2;i>=1;i--){
        x=min(brr[i],brr[i-1]);
        brr[i]-=x;
        brr[i-1]-=x;
    }
    bool f1=true,f2=true;
    // for(int i:arr) cout<<i<<" ";
    //     cout<<endl;
    // for(int i: brr) cout<<i<<" ";
    //     cout<<endl;
    
    
    for(int i=0;i<n-1;i++){
        if(arr[i]>arr[i+1]){
            f1=false; break;
        }
    }
     for(int i=0;i<n-1;i++){
        if(brr[i]>brr[i+1]){
            //cout<<i<<endl;
            f2=false; break;
        }
    }
    if(f1 || f2 ) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}    
    
return 0;
}





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

#define ll long long

#define pii pair<int,int>

#define vi vector<int>

#define pb push_back

#define fi first

#define se second

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

#define len(s) (int)s.size()

#define pq priority_queue

#define il inline

using namespace std;

void solve(){

int n;

cin>>n;

int a[n+1];

for(int i=1;i<=n;i++)cin>>a[i];

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

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

cout<<"NO\n";

return;

}

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

a[i]-=x;

a[i+1]-=x;

}

cout<<"YES\n";

}

int main() {

ios::sync_with_stdio(0);

cin.tie(0);

cout.tie(0);

int T=1;

cin>>T;

while(T--){

solve();

}

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

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
// using namespace __gnu_pbds;
using namespace std;
 
#define all(vec) vec.begin(), vec.end()
#define fbo find_by_order
#define ook order_of_key
#define fi first
#define se second
#define long long long
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define rep2(i,a,b) for(int i = a; i >= b; i--)
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vector<int>> vvi;
const int INF = 1e9;
const long LINF = 4e18;
// const long P1 = 1+7*17*(1<<23), P2 = 1+7*(1<<26); // PRIME FOR FFT
// const long MOD = 1e9+7; // 998244353 
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// mt19937_64 rng(std::chrono::system_clock::now().time_since_epoch().count());
// long inv[1000003], fac[1000003], ifac[1000003];
// inv[1] = fac[0] = ifac[0] = 1;
// rep(i, 2, 1000000) inv[i]=MOD-(MOD/i)*inv[MOD%i]%MOD;
// rep(i, 1, 1000000) fac[i] = (i*fac[i-1])%MOD, ifac[i] = (inv[i]*ifac[i-1])%MOD;

// long C(int n, int k) { return (k > n)? 0 : ((fac[n]*ifac[n-k])%MOD)*ifac[k]%MOD; }


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int t; cin >> t;
	while(t--)
	{
		int n, l, r; cin >> n >> l >> r;
		vector<int> L, R, C;
		rep(i, 1, l-1)
		{
			int x; cin >> x;
			L.push_back(x);
		}
		rep(i, l, r)
		{
			int x; cin >> x;
			C.push_back(x);
		}
		rep(i, r+1, n)
		{
			int x; cin >> x;
			R.push_back(x);
		}
		sort(L.begin(), L.end());
		sort(R.begin(), R.end());
		sort(C.begin(), C.end());
		reverse(C.begin(), C.end());

		long res = LINF, sum = 0, dif = 0;
		for(int x : C) sum += x;
		res = sum;
		for(int i = 0; i < min(C.size(), L.size()); i++)
		{
			dif += -C[i]+L[i];
			res = min(res,sum+dif);
		}
		dif = 0;
		for(int i = 0; i < min(C.size(), R.size()); i++)
		{
			dif += -C[i]+R[i];
			res = min(res,sum+dif);
		}
		cout << res << "\n";
	}
	
}






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

using namespace std;

int main()

{

    int t;

    cin>>t;



    while(t--)

    {

        int n,l,r;

        cin >> n >> l >> r;



        vector<int> arr(n);

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

        {

            cin >> arr[i];

        }



        int num = r - l + 1;

        vector<int> a1, a2;

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

        {

            a1.push_back(arr[i]);

        }

        for (int i = n-1; i >= l-1; i--)

        {

            a2.push_back(arr[i]);

        }



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

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



        long long sum = accumulate(a1.begin(), a1.begin() + r - l + 1, 0LL);

        sum = min(sum, accumulate(a2.begin(), a2.begin() + r - l + 1, 0LL));



        cout << sum << endl;

    }



   return 0;

}
Problem: 2050D - Digital string maximization
Language: c++17 

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

int main(){
    int t;cin>>t;
    while(t--){
        string s;cin>>s;
        vector<int>arr(s.size());
        for(int i=0;i<arr.size();i++){
            arr[i]=s[i]-'0';
        }
        for(int i=0;i<s.size();i++){
            int j=i;
            while(j>=1 && arr[j]>0 && arr[j]>arr[j-1]+1 ){
                int val= arr[j];
                arr[j]=arr[j-1];
                arr[j-1]=val-1;
                if(j>1)j--;
                else break;
        }
    }
    string rs="";
    for(int d:arr){
        rs+=to_string(d);
      
    }
      cout<<rs<<endl;
 
    }
       return 0;
}

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

using namespace std;

void solve() {
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int best = s[i] - '0', pos = i;
        for (int j = i; j < min(i + 10, (int) s.size()); j++) {
            if (s[j] - '0' - (j - i) > best) {
                best = s[j] - '0' - (j - i);
                pos = j;
            }
        }
        while (pos > i) {
            swap(s[pos], s[pos - 1]);
            pos--;
        }
        s[i] = char(best + '0');
    }
    cout << s;
}

int main() {
    int TESTS = 1; cin >> TESTS;
    while (TESTS --> 0) {
        solve();
        cout << '\n';
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 78 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 1e9;

int solve(int i, int j, string &a, string &b, string &c, vector<vector<int>> &dp) {
 
    if (dp[i][j] != -1) return dp[i][j];
    int n = a.size(), m = b.size();
    if (i == n && j == m) return dp[i][j] = 0;
    if (i == n) { 
        int cnt = 0;
        for (int k = j; k < m; k++) {
            if (b[k] != c[i + k]) cnt++;
        }
        return dp[i][j] = cnt;
    }
    if (j == m) {
        int cnt = 0;
        for (int k = i; k < n; k++) {
            if (a[k] != c[k + j]) cnt++;
        }
        return dp[i][j] = cnt;
    }
    int mismatchA = (a[i] != c[i + j]); 
    int mismatchB = (b[j] != c[i + j]); 

    int useA = solve(i + 1, j, a, b, c, dp) + mismatchA;
    int useB = solve(i, j + 1, a, b, c, dp) + mismatchB;
    return dp[i][j] = min(useA, useB);
}

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

    ll t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        int n = a.size();
        int m = b.size();
        vector<vector<int>> dp(n + 1, vector<int>(m + 1, -1));
        int result = solve(0, 0, a, b, c, dp);
        cout << result << '\n';
    }

    return 0;
}


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

#include <vector>

#include <string>

#include <algorithm>

using namespace std;



int minChangesToAlternatingPattern(const string& a, const string& b, const string& c) {

    int n = a.size();

    int m = b.size();

    int len = c.size();

    

    // dp[i][0] = minimum changes to match pattern up to i using a

    // dp[i][1] = minimum changes to match pattern up to i using b

    vector<vector<int>> dp(len + 1, vector<int>(2, 1e9));

    dp[0][0] = 0;

    dp[0][1] = 0;

    

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

        // If the current character in c matches the current character in a

        if (i <= n && c[i - 1] == a[i - 1]) {

            dp[i][0] = min(dp[i][0], dp[i - 1][1] + (i % 2 == 1));

        }

        // If the current character in c matches the current character in b

        if (i <= m && c[i - 1] == b[i - 1]) {

            dp[i][1] = min(dp[i][1], dp[i - 1][0] + (i % 2 == 0));

        }

        // If the current character in c does not match either a or b

        if (i <= n && c[i - 1] != a[i - 1]) {

            dp[i][0] = min(dp[i][0], dp[i - 1][1] + 1);

        }

        if (i <= m && c[i - 1] != b[i - 1]) {

            dp[i][1] = min(dp[i][1], dp[i - 1][0] + 1);

        }

    }

    

    // The answer is the minimum of the two possibilities for the last character

    return min(dp[len][0], dp[len][1]);

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        string a, b, c;

        cin >> a >> b >> c;

        cout << minChangesToAlternatingPattern(a, b, c) << "\n";

    }

    return 0;

}





// WScoTkLiD3htN7Q8XYV
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 280 ms):
#include "bits/stdc++.h"
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define int long long

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const char nl = '\n';
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

void solve() {
	int n, m; cin >> n >> m;
	vector<int> a(n); for (auto &x : a) cin >> x;
	vector<int> b(m); for (auto &x : b) cin >> x;

	int sumA = accumulate(all(a), 0LL);
	int sumB = accumulate(all(b), 0LL);

	if (sumA != sumB) {
		cout << "No" << nl;
		return;
	}

	multiset<int> st;
	for (int i = 0; i < n; i++)
		st.insert(a[i]);

	priority_queue<int, vector<int>, greater<int>> q;
	for (int i = 0; i < m; i++)
		q.push(b[i]);

	while (!q.empty()) {
		int x = q.top(); q.pop();

		if (st.count(x) == 0) {
			if (x <= 1) {
				cout << "No" << nl;
				return;
			}

			if (x % 2 == 0) {
				q.push(x / 2);
				q.push(x / 2);
			} else {
				q.push(x / 2);
				q.push(x / 2 + 1);
			}
		} else {
			st.erase(st.find(x));
		}
	}

	cout << "Yes" << nl;
}

int32_t main() {
	ios::sync_with_stdio(0), cin.tie(0);

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

	return 0;
}


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

using namespace std;

using ll =long long;

using pii=pair<int,int>;

#define yes cout<<"YES"<<endl;

#define no cout<<"NO"<<endl;

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

using namespace std;





void solve(){

    ll n,m;

    cin>>n>>m;

    vector<ll>a(n),b(m);

    for(auto &it:a)cin>>it;

    for(auto &it:b)cin>>it;

    map<ll,ll>freq_a,freq_b;

    set<ll,greater<ll>>set_a,set_b;

    for(auto value:a){

        freq_a[value]++;

        set_a.insert(value);

    }

    for(auto value:b){

        freq_b[value]++;

        set_b.insert(value);

    }

    while(true){

        if(set_a.empty() and set_b.empty()){

            yes

            return;

        }

        if(set_a.empty() or set_b.empty()){

            no

            return;

        }

        ll max_b=*set_b.begin();

        ll max_a=*set_a.begin();

        if(max_a>max_b){

            no

            return;

        }

        if(freq_a[max_b]){

            ll min_count=min(freq_a[max_b],freq_b[max_b]);

            freq_a[max_b]-=min_count;

            freq_b[max_b]-=min_count;

            

            if (freq_a[max_b] == 0) set_a.erase(max_b);

            if (freq_b[max_b] == 0) set_b.erase(max_b);

        }

        else{

            ll part1=max_b/2;

            ll part2=(max_b+1)/2;

            ll count=freq_b[max_b];

            freq_b[max_b]=0;

            set_b.erase(max_b);



            freq_b[part1]+=count;

            freq_b[part2]+=count;

            set_b.insert(part1);

            set_b.insert(part2);

        }

    }

}

int main(){

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

    int t=1;

    cin>>t;

    while(t--){

        solve();

    }

    return 0; 

}
Problem: 2050E - Three Strings
Language: c++17 

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


void sol(){
	string a, b, c;
	cin >> a >> b >> c;
	int n = a.size();
	int m = b.size();
	int dp[n + 1][m + 1];
	//fill(&dp[0][0], &dp[n + 1][m + 1], 1e9 );
	dp[0][0] = 0;
	for (int i = 0; i <= n; i++){
		for (int j = 0; j <= m; j++){
			if(i == 0 && j == 0) continue;
			dp[i][j] = 1e9;
			if(i - 1 >= 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + (a[i - 1] != c[i + j - 1]));
			if(j - 1 >= 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));
			//cout << i << " " << j << ": " << dp[i][j] << "\n ";
		}
	}
	cout << dp[n][m] << "\n";
}


signed main() {
	//freopen("in.txt", "r", stdin);

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


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

#define ll long long
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define vi vector<int>
#define vll vector<long long>

#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define all(v) v.begin(), v.end()

#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for (int i = a; i >= b; --i)
#define fori(n) for (int i = 0; i < n; ++i)

#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define Yes { cout << "YES\n"; return; }
#define No { cout << "NO\n"; return; }

template<typename T> void print_value(const vector<T>& vec) { for (const auto& element : vec) cout << element << " "; }
template<typename T> void print_value(const T& value) { cout << value << " "; }
template<typename T, typename... Args> void print_value(const T& value, const Args&... args) { print_value(value); print_value(args...); }
template<typename T, typename... Args> void print(const T& value, const Args&... args) { print_value(value, args...); cout << endl; }

const int MOD = 1e9 + 7, INF = INT_MAX;

//------------------------Code Starts-------------------------

int rec(string& a, string& b, string& c, int i, int j, vector<vector<int>>& dp) {
    if (i + j == c.size()) return 0;
    if (dp[i][j] != -1) return dp[i][j];

    int sc1 = INF, sc2 = INF;

    if (i < a.size() && c[i + j] == a[i]) {
        sc1 = rec(a, b, c, i + 1, j, dp);
    } else if (i < a.size()) {
        sc1 = 1 + rec(a, b, c, i + 1, j, dp);
    }

    if (j < b.size() && c[i + j] == b[j]) {
        sc2 = rec(a, b, c, i, j + 1, dp);
    } else if (j < b.size()) {
        sc2 = 1 + rec(a, b, c, i, j + 1, dp);
    }

    return dp[i][j] = min(sc1, sc2);
}

void solve() {
    string a, b, c;
    cin >> a >> b >> c;
    vector<vector<int>> dp(a.size() + 1, vector<int>(b.size() + 1, -1));
    print(rec(a, b, c, 0, 0, dp));
}

//------------------------Code Ends---------------------------

int main() {
    fastio;
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

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

int main() {
    ll t;
    cin >> t;
    while (t--) {
        ll n, k, c = 0, res = 0;
        cin >> n >> k;
        vector<ll> a(n);
        map<ll, ll> mp;

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

        vector<ll> v;
        for (auto i : mp) {
            v.push_back(i.second);
        }

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

        for (ll i = 0; i < v.size(); i++) {
            k -= v[i];
            if (k >= 0)
                res++;
            else
                break;
        }

        //cout << "c=" << c << " res=" << res << endl;
        if(c-res==0)cout<<"1"<<endl;
        else cout << c - res << endl;
    }
    return 0;
}


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

int main() {
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        
        vector<int>v(n);
        map<int,int>mp;
        
        for(int i=0;i<n;i++){
            cin>>v[i];
        }
        sort(v.begin(),v.end());
        
        int cnt=0;
        int total=0;
        
        for(int i=0;i<n;i++){
            if(i != n-1){
                if(v[i]==v[i+1]){
                    cnt++;
                }else{
                    total++;
                    mp[++cnt]++;
                    cnt=0;
                }
            }
            else{
                total++;
                mp[++cnt]++;
            }
        }
        for(auto it: mp){
            int rep = it.first;
            int nums = it.second;
            
            if(k>=rep*nums){
                k-=(rep*nums);
                total-=nums;
            }else{
                total-=(k/rep);
                break;
            }
        }
        if(total<=1)
            cout<<1<<endl;
        else cout<<total<<endl;
        
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

using namespace std;

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

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

        int n2 = 0, n3 = 0, sum = 0;

        for (auto i : s)
        {
            if (i == '2')
                n2++;

            if (i == '3')
                n3++;

            sum += (int)i - 48;
        }

        int rem = sum % 9;

        bool ans = false;
        for (int i = 0; i <= min(n2, 8ll); i++)
            for (int j = 0; j <= min(n3, 8ll); j++)
                if ((rem + i * 2 + j * 6) % 9 == 0)
                {
                    ans = true;
                    break;
                }

        if (ans)
            cout << "YES\n";
        else
            cout << "NO\n";
    }
}

Solution 2 (runtime: 61 ms):


// KISS <3

 

#include <bits/stdc++.h>

#include<stdio.h>

using namespace std;

 

// #include <ext/pb_ds/assoc_container.hpp>

// #include <ext/pb_ds/tree_policy.hpp>

 

// typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;

 

typedef long long ll;



const int N = 200010;

const int M = 1e9 + 7;

const int MOD = 998244353;

// const int INF = 1000000007;

 

struct arr {

	ll val;

	ll idx;

};

 

long long int power(int base, int exp) {

	if (exp == 0)

		return 1;

	else if (exp == 1)

		return base;

	else{

		long long int calc;

		if (exp % 2 == 0){

			calc = power(base, exp/2);

			calc *= calc;

		} else {

			calc = base*power(base, exp-1);

		}

		return calc;

	}

}



bool chk(const string n){

	ll sum = 0;

	for(auto c:n) {

		sum += (c-'0');

		sum %= 9;

	}

	

	ll two = count(n.begin(),n.end(),'2');

	ll three = count(n.begin(),n.end(),'3');

	

	for(int i=0;i<min(10LL,two+1);i++){

		for(int j=0;j<min(10LL,three+1);j++){

			if((sum + i*2 + j*6)%9 == 0) return true;

		}

	}



	return false;

}



int main () {

 

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	

	#ifndef ONLINE_JUDGE

	freopen("input.txt","r", stdin);

	freopen("output.txt","w", stdout);

	#endif

	

	

	ll tc;cin>>tc;

	while(tc--){

		

		string n;cin>>n;

		

		if(chk(n)) cout<<"YES"<<endl;

		else cout<<"NO"<<endl;



	}



	

}
Problem: 2050D - Digital string maximization
Language: c++17 

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

using namespace std;

int main(){

int t;

cin>>t;

while(t--){

string s;

cin>>s;

int n=s.length();

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

int index=-1;

int maxdiff=0;

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

int diff=(s[j]-(j-i)-s[i]);

if(maxdiff<diff){

maxdiff=diff;

index=j;

}

}

if(index!=-1){

char c=s[index]-(index-i);

char p=s[i];

for(int j=i+1;j<=index;j++){

swap(p,s[j]);

}

s[i]=c;

}

}

cout<<s<<endl;

}

}

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

using namespace std;

int main()

{

	int t;

	cin>>t;

	while(t--)

	{

		string str;

		cin >> str;

		int n=str.size();

		vector<int>di(n+5);

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

		{

			di[i]=str[i]-'0';

		}

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

		{

			while(di[i]>di[i-1]+1&&di[i]>0)

			{

				//cout << i << " " << di[i] << " " << di[i-1] << endl;

				di[i]--;

				swap(di[i],di[i-1]);

				if(i>1)

				{

					i--;

				}

				else

				{

					break;

				}

			}

		}

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

		{

			cout << di[i];

		}

		cout << endl;

	}

	

}
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(){

int t;
cin >> t;

while(t--){

    int n;
    cin >> n;

    vector<ll>a(n);

    for(int i=0;i<n;i++) cin >> a[i];

    int c = n;

    ll ans = -1e18;

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

    for(int j=0;j<c;j++) sum = (sum + a[j]);

    if( i== 0) ans = max(ans, sum);
    else ans = max(ans, max(sum, (-sum)));

    for(int j=0;j<c;j++) a[j] = a[j+1] - a[j];

    c--;

    }

    cout << ans << endl;
}


}


Solution 2 (runtime: 46 ms):
/** author: harshit
  Slytherin
 This is the property of half blood prince
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n" 
void solve()
{ 
   int n;
   cin>>n;
   vector<int> a(n);
   for(auto &i:a) cin>>i;
   int ans=accumulate(a.begin(),a.end(),0);
   while(n>1){
    vector<int> x(n-1),y(n-1);
    for(int i=0;i<n-1;++i) x[i]=a[i+1]-a[i];
    for(int i=0,j=n-1;i<n-1,j>0;++i,--j) y[i]=a[j-1]-a[j];
    int sx=accumulate(x.begin(),x.end(),0LL);
    int sy=accumulate(y.begin(),y.end(),0LL);
    if(sx>sy) for(int i=0;i<n-1;++i) a[i]=x[i];
    else for(int i=0;i<n-1;++i) a[i]=y[i];
    ans=max({ans,sx,sy});
    n=x.size();
   }
   cout<<ans<<endl;
   
  return ;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
  int t;
  cin>>t; 
  while(t--)
  {
  solve();
  }
}