ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049C - MEX Cycle
Language: c++17 

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

using namespace std;

int main()

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    int t;

    cin >> t;

    while(t--)

    {

        int n,x,y;

        cin >> n >> x >> y;

        vector<int> a(n+1);

        if(n%2==0)

        {

            if((y-x)%2==0) a[x] = 2;

            else a[x] = 0;

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

            {

                int k = x+i;

                if(k>n) k%=n;

                a[k] = i&1;

            }

        }

        else

        {

            a[x] = 2;

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

            {

                int k = x+i;

                if(k>n) k%=n;

                a[k] = i&1;

            }

        }

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

        {

            cout << a[i] << ' ';

        }

        cout << '\n';

    }

    return 0;

}

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

using namespace std;

void solve() {



    int n, x, y;

    cin >> n >> x >> y;

    int ans[n], d, p;

    p = y - x;



    if((p + 1) % 2 == 0) {

        for(int i = 0; i <= p; i++) ans[i] = i % 2;

    } else {

        ans[0] = 0; ans[1] = 2; ans[2] = 1;

        for(int i = 3; i <= p; i++) ans[i] = (i + 1) % 2;

    }

    if((n - p + 1) % 2 == 0) {

        for(int i = 0; i < (n - p); i++) ans[n - i - 1] = (i + 1) % 2;

    } else {

        ans[n - 1] = 2; ans[n - 2] = 1;

        for(int i = 2; i < (n - p); i++) ans[n - i - 1] = i % 2;

    }



    for(int i = 0; i < n; i++) cout << ans[(i + n - x + 1) % n] << " ";

    cout << endl;



}



int main() {



    int t;

    cin >> t;

    while(t--) solve();



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

Solution 1 (runtime: 155 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll f(ll ida,ll idb,vector<vector<ll>>&dp, string &a,string &b,string &c)
{
   if(idb>=b.length())
   {
      ll ans=0;
      while(ida<a.size())
      {
         if(a[ida]!=c[idb+ida]) ans++;ida++;
      }
      return ans;
   }
   if(ida>=a.length())
   {
      ll ans=0;
      while(idb<b.size())
      {
         if(b[idb]!=c[ida+idb]) ans++;idb++;
      }
      return ans;
   }
   
   int pica=1e9;
   int picb=1e9;
   if(dp[ida][idb]!=-1)  return dp[ida][idb];
   if( a[ida]==c[ida+idb])
   {
      pica=f(ida+1,idb,dp,a,b,c);
   }
   else 
   pica=f(ida+1,idb,dp,a,b,c)+1;

   if( b[idb]==c[ida+idb])
   {
      picb=f(ida,idb+1,dp,a,b,c);
   }
   else
   picb=f(ida,idb+1,dp,a,b,c)+1;
   return  dp[ida][idb]=min(pica,picb);


}

int main()
{
   ll t; cin>>t;
   while(t--)
   {
      string a,b,c;
      cin>>a>>b>>c;
      vector<vector<ll>> dp(a.size(), vector<ll> (b.size(),-1));
     cout<< f(0,0,dp,a,b,c)<<endl;

   }  

   
}

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

// Memoization table (2D array)
int dp[1001][1001];

// Recursive helper function with memoization
int helpher(int i, int j, const string &a, const string &b, const string &c) {
    int k = i + j; // Position in c derived from positions in a and b
    if (k == c.size()) return 0; // Base case: processed all of c
    if (dp[i][j] != -1) return dp[i][j]; // Memoized result

    int ans = INT_MAX;

    // Match c[k] with a[i]
    if (i < a.size()) {
        if (a[i] == c[k]) {
            ans = min(ans, helpher(i + 1, j, a, b, c));
        } else {
            ans = min(ans, 1 + helpher(i + 1, j, a, b, c)); // Count mismatch
        }
    }

    // Match c[k] with b[j]
    if (j < b.size()) {
        if (b[j] == c[k]) {
            ans = min(ans, helpher(i, j + 1, a, b, c));
        } else {
            ans = min(ans, 1 + helpher(i, j + 1, a, b, c)); // Count mismatch
        }
    }

    return dp[i][j] = ans;
}

void solve() {
    string a, b, c;
    cin >> a >> b >> c;

    // Initialize memoization table
    memset(dp, -1, sizeof(dp));

    // Solve for minimum changes
    cout << helpher(0, 0, a, b, c) << endl;
}

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

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

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

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define ull unsigned ll

void Mohamady() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void Solve() {
	int n, l, r;
	cin >> n >> l >> r;
	vector<int> a(n), left, right;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < r; ++i) left.pb(a[i]);
	for (int i = l - 1; i < n; ++i) right.pb(a[i]);
	sort(all(left)), sort(all(right));
	ll s_left = 0, s_right = 0;
	for (int i = 0; i < left.size() && i < r - l + 1; ++i) s_left += left[i];
	for (int i = 0; i < right.size() && i < r - l + 1; ++i) s_right += right[i];
	cout << min(s_left, s_right) << "\n";
}
// 7.72568
int main() {
	Mohamady();
	int t = 1;
	cin >> t;
	while (t--) Solve();
}


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

#define endl '\n'

#define int long long

#define double long double

#define close ios :: sync_with_stdio(0),cin.tie(0),cout.tie(0)

using namespace std;



const int N = 100010;

int a[N];

int n,l,r;



void solve()

{

    priority_queue<int> heap1,heap2;

    cin >> n >> l >> r;

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



    int ans = 0;

    for(int i = l;i <= r;i ++) heap1.push(a[i]),heap2.push(a[i]),ans += a[i];



    int res1 = ans;

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

    {

        if(a[i] < heap1.top())

        {

            res1 -= heap1.top();

            heap1.pop();

            res1 += a[i];

            heap1.push(a[i]);

        }

    }

    

    int res2 = ans;

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

    {

        if(a[i] < heap2.top())

        {

            res2 -= heap2.top();

            heap2.pop();

            res2 += a[i];

            heap2.push(a[i]);

        }

    }



    cout << min(res1,res2) << endl;



}



signed main()

{

    close;

    int T = 1;

    cin >> T;

    while(T--)

    {

        solve();

    }

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 343 ms):
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
const int MAX_N = 2e5 + 9;

int t , n , a[MAX_N];


int main()
{
    cin >> t;
    while (t--)
    {
        cin >> n;
        for(int i = 1; i <= n; i++)
            cin >> a[i];

        bool check = true;
        for(int i = 2; i <= n; i++)
        {
            if(a[i - 1] <= a[i])
                a[i] -= a[i - 1];
            else
                check = false;
        }
        cout << (check == true ? "yes" : "no") << endl;
    }
    return 0;
}


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

#define endl "\n"

#define int long long

using namespace std;

const int N = 2e5 + 10;





int a[N];

void solve(){

    int n; cin >> n;

    int mx = 0;

    cin >> a[0];

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

        cin >> a[i];

        int num = min(a[i], a[i-1]);

        a[i] -= num; a[i-1] -= num;

        mx = max(mx, a[i]);

    }



    if(mx == a[0]){

        cout << "NO\n";

        return;

    }

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

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

            cout << "NO\n";

            return;

        }

    }

    cout << "YES\n";

}

signed main(){

    ios::sync_with_stdio(0);

    cin.tie(nullptr);

    int t = 1; cin >> t;

    while(t--)solve();

    return 0;

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

Solution 1 (runtime: 202 ms):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int d[1000001];
int maks=1000001;
int main() 
{
  ll t;
  cin>>t;
  while(t--)
  {
    ll n,k;
    cin>>n>>k;                              
    ll a[n];
    vector<int>v;
    for(ll i=0;i<n;i++)             
    {                               
      cin>>a[i];
    }
    sort(a,a+n);
    ll say=1;
    for(ll i=0;i<n-1;i++)
    {
      if(a[i]==a[i+1])
      say++;
      else
      {
        v.push_back(say);
        say=1;
      }
  }
  v.push_back(say);
  sort(v.begin(),v.end());
  ll i=0,j=n-1;
  while(i<j and k!=0)
  {
    if( v[i]!=0)
    {
      v[i]=v[i]-1;
      k--;
    }
    if(v[i]==0)
    i++;
  }
  ll sa=0;
  for(ll g=0;g<v.size();g++)
  {
    if(v[g]>=1)
    sa++;
  }
  if(sa!=0)
  cout<<sa<<endl;
  else
  cout<<1<<endl;
}
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	while(n--)
	{
	    long long a,b;
	    cin>>a>>b;
	    vector<long long>ar(a);
	    for(long long i=0;i<a;i++){
	        cin>>ar[i];
	    }
	    
	    map<long long,long long>mp;
	    for(long long i=0;i<a;i++){
	        mp[ar[i]]++;
	    }
	     vector<long long>ans;
	    for(auto it:mp){
	        ans.push_back(it.second);
	    }
	    sort(ans.begin(),ans.end());
	    
	    long long x=ans.size();
	    long long ct=0;
	    while(b>0 && ct< x-1){
	        if(ans[ct]<=b){
	          b-=ans[ct];
	          ct++;
	        }
	        else{
	            break;
	        }
	    }
	    cout<<x-ct<<endl;
	    
	    
	    
	}

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

Solution 1 (runtime: 1343 ms):
#include<iostream>
#include<map>
#include<queue>
using namespace std;
typedef pair<int,int>PII;
queue<PII>q;
map<int,int>m;
int main(){
	int n,sum=0;
	cin>>n;
	int a[10001];
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=n;i>=1;i--){
		m[a[i]]=1;
		if(i==1)break;
		if(i>=2){
			for(int j=a[i]-1;j>=1;j--){
				if(m[j]==0){
					q.push({a[i],j});
					sum++;
				}
			}
			for(int j=1;j<=a[i]-1;j++){
				if(m[j]==0){
					q.push({j,a[i]});
					sum++;
				}
			}
			for(int j=a[i]+1;j<=n;j++){
				if(m[j]==0){
					q.push({j,a[i]});
					sum++;
				}
			}
		}
	}
	cout<<sum<<endl;
	while(!q.empty()){
		PII t=q.front();
		q.pop();
		cout<<t.first<<' '<<t.second<<endl;
	}
	return 0;
}

Solution 2 (runtime: 1280 ms):
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int>arr(n+1,0);
	vector<int>brr(n);
	int cnt=0;
	for(int i=0;i<n;i++){
		cin>>brr[i];
		arr[brr[i]]=1;
		for(int j=1;j<brr[i];j++){
			if(arr[j]==0){
				cnt++;
			}
		}
		for(int j=brr[i];j<=n;j++){
			if(arr[j]==0){
				cnt++;
			}
		}
		for(int j=brr[i];j<=n;j++){
			if(arr[j]==0){
				cnt++;
			}
		}

}

	for(int i=0;i<=n;i++){
		arr[i]=0;
	}

	cout<<cnt<<endl;

	for(int i=0;i<n;i++){
		cin>>brr[i];
		arr[brr[i]]=1;

		for(int j=brr[i];j<=n;j++){
			if(arr[j]==0){
				cout<<j<<" "<<brr[i]<<endl;
			}
		}
		for(int j=n;j>=brr[i];j--){
			if(arr[j]==0){
				cout<<brr[i]<<" "<<j<<endl;
			}
		}
		for(int j=brr[i]-1;j>0;j--){
			if(arr[j]==0){
				cout<<brr[i]<<" "<<j<<endl;
			}
		}
	}

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

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mp make_pair
#define push_b push_back
#define push_f push_front
#define pop_f pop_front
#define pop_b pop_back
#define sec second
#define fir first

const int inf = 1e9 + 7;

pair<vector<int>, int> minus_(vector<int>& a) {
    vector<int> ans;
    int sum = 0;

    for (int i = 1; i < a.size(); i++) {
        ans.push_b(a[i] - a[i - 1]);
        sum += ans.back();
    }

    return {ans, sum};

}

signed main() {

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

    int t; cin >> t;

    while (t--) {

        int n; cin >> n;
        vector<int> a(n);

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

        if (n == 1) {
            cout << a[0] << endl;
            continue;
        }

        int max_sum = -inf;

        while (a.size() > 1) {
            max_sum = max(max_sum, sum);
            auto new_ = minus_(a);
            a = new_.fir;
            sum = new_.sec;
            max_sum = max(max_sum, abs(sum));
        }

        cout << max_sum << endl;

    }



}


Solution 2 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>PII;
const int N=55;
ll a[N];
ll cnt[N];


void solve(){
    int n;
    cin>>n;
    ll ans=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ans+=(ll)a[i];
    }
    if(n==1){cout<<a[0]<<endl;return;}
    for(int i=0;i<n-1;i++){
        ans=max(max(ans,a[n-i-1]-a[0]),a[0]-a[n-i-1]);
        for(int j=0;j<n-i-1;j++){
            a[j]=(ll)(a[j+1]-a[j]);
        }
    }
    cout<<ans<<endl;

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

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

using namespace std;

const int N = 100010;

int t;
int a[N];

int main()
{
    cin >> t;

    while( t -- )
    {
        int n , l , r ;
        cin >> n >> l >> r;

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

        //左
        long long r1 = 0;
        int al[N] = {};

        for(int i = 1 ;i  <= r ; i ++ ) al[i] = a[i];
        sort(al + 1 , al + r + 1);
        for(int i = 1;i <= r - l + 1 ;i ++ ) r1 += al[i];
    
        //右
        long long r2 = 0;
        int cnt = 0;
        int ar[N] = {};

        for(int i = l ;i  <= n ; i ++ ) ar[ ++cnt ] = a[i];
        sort(ar + 1, ar + n - l + 2);
        for(int i = 1 ;i <= r - l + 1 ; i ++ ) r2 += ar[i];

        cout << min(r1 , r2) << 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,l,r;

      cin>>n>>l>>r;

      int arr[n],brr[l],crr[n-r+1],main1[r-l+1],main2[r-l+1];

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

        cin>>arr[i];

      }

      int index1=0,index2=0,index3=0;

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

       if(i<l-1){

        brr[index1++]=arr[i];

       }

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

        main1[index2]=arr[i];

        main2[index2++]=arr[i];

       }

       else{

        crr[index3++]=arr[i];

       }

      }

      sort(brr,brr+index1);

      sort(main1,main1+index2);

      sort(main2,main2+index2);

      sort(crr,crr+index3);

     int i=0,j=index2-1;

       while(i<index1&&j>=0){

          if(brr[i]<=main1[j]){

            swap(brr[i],main1[j]);

            i++;

            j--;

          }

          else{

            break;

          }

       }

      i=0;

      j=index2-1;

       while(i<index3&&j>=0){

          if(crr[i]<=main2[j]){

            swap(crr[i],main2[j]);

            i++;

            j--;

          }

          else{

            break;

          }

       }

       long long sum1=0,sum2=0;

       for(int k=0;k<index2;k++){

        sum1+=main1[k];

       }

       for(int k=0;k<index2;k++){

        sum2+=main2[k];

       }

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

    }

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

Solution 1 (runtime: 93 ms):
// source problem : 
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
#define lb lower_bound
#define ub upper_bound
#define MASK(i) (1LL << (i))
const int inf = 1e18;
void ckmax(int& f, int s)
{
    f = (f > s ? f : s);
}
void ckmin(int& f, int s)
{
    f = (f < s ? f : s);
}
void solve()
{
    int n, l, r;
    cin >> n >> l >> r;
    l--, r--;
    vector<int> a(n);
    for (int &i : a) cin >> i;
    vector<int> f, s, t;
    for (int i = 0; i < n; i++)
    {
        if (i < l) f.push_back(a[i]);
        else if (i > r) t.push_back(a[i]);
        else s.push_back(a[i]);
    } 
    sort(all(f));
    sort(s.rbegin(), s.rend());
    sort(all(t));
    int sum = accumulate(all(s), 0LL);
    for (int i = 1; i < f.size(); i++) f[i] += f[i - 1];
    for (int i = 1; i < s.size(); i++) s[i] += s[i - 1];
    for (int i = 1; i < t.size(); i++) t[i] += t[i - 1];
    int ans = sum;
    for (int i = 0; i < min(f.size(), s.size()); i++)
    {
        ckmin(ans, sum - s[i] + f[i]);
    }
    for (int i = 0; i < min(t.size(), s.size()); i++)
    {
        ckmin(ans, sum - s[i] + t[i]);
    }
    cout << ans << '\n';
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}

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

using namespace std;





void stdInput(){

	#ifndef ONLINE_JUDGE

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

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



	#endif

}



void solve(vector<int>& v1,int n,int l,int r)

{

	

	vector<int> a1,b1;

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

		a1.push_back(v1[i]);

	}

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

		b1.push_back(v1[i]);



	}

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

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

	long long sum1 = 0,sum2 = 0;

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

		sum1 += a1[i];

	}

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

		sum2 += b1[i];

	}

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

}

int main()

{

	stdInput();

	int T;

	cin >> T;

	while(T--)

	{

		int n,l,r;

		cin >> n >> l >> r;

		vector<int> v1(n);

		for(int &i : v1){

			cin >> i;

		}

		solve(v1,n,l-1,r-1);

	}

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

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

#define out(x) #x << " = " << x << " "
#ifndef LOCAL
#define endl "\n"
#define cerr \
	if (false) cerr
#define stdio(true) stdio(false)
#endif

const int MAX_N = 1e5 + 10;
const int INF = 1e9 + 10;

void solve() {
	string x;
	cin >> x;

	for (int i = 1; i < x.size(); i++) {
		int prv = 0;
		while (i - prv - 1 >= 0 && x[i - prv] != '0' && x[i - prv] - 1 > x[i - prv - 1]) {
			x[i - prv] -= 1;
			swap(x[i - prv], x[i - prv - 1]);
			prv++;
		}
	}

	cout << x << endl;
}

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

	int t;
	cin >> t;

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

	return 0;
}

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

#define ep emplace_back

#define mp make_pair

using namespace std;

using i64=long long;



void solve() {

string s;

cin >> s;

int n = s.length();

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

int pos = -1;

int mx = -1;

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

int d = s[i+j]-'0'-j;

if(d > s[i]-'0' && d > mx) {

pos = i+j;

mx = d;

}

}

if(pos == -1) continue;

// cout << i << ',' << s[i] << ' ' << pos << ',' << s[pos] << '\n';

auto c = s[pos];

rotate(s.begin() + i, s.begin() + pos, s.begin() + pos + 1);

s[i] = char(c - pos + i);

}

cout << s << '\n';

}



int 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 <iostream>
#include <string>

void solve() 
{
	std::string n;
	std::cin >> n;

	int sum = 0;
	int twos = 0, threes = 0;
	for (int i = 0; i < n.size(); i++) {
		sum += n[i] - '0';	
		if (n[i] == '2') ++twos;
		if (n[i] == '3') ++threes;
	}

	for (int i = 0; i <= (twos < 8 ? twos : 8); i++) {
		for (int j = 0; j <= (threes < 8 ? threes : 8); j++) {
			if ((sum + i * 2 + j * 6) % 9 == 0) {
				std::cout << "YES\n";
				return;
			}
		}
	}
	std::cout << "NO\n";
}

int main() 
{
	std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);

	int t = 1; 
	std::cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//cin.ignore(numeric_limits<streamsize>::max(), '\n');
	int t;
	cin >> t;
	vector<bool> results(t,false);
	int Rindex = 0;
	cin.get();
	while (t--) {
		int twos = 0, threes = 0;
		int sum =0;
		char temp = cin.get();
		while (temp != '\n') {
			temp -= 48;
			sum += temp;
			if (twos < 8 && temp == 2) {
				twos++;
			}
			else if (threes < 2 && temp == 3) {
				threes++;
			}
			temp = cin.get();
		}
		sum %= 9;
		switch (sum) {
		case 0:
			results[Rindex] = true;
			break;
		case 1:
		{
			if ((threes >= 1 && twos >= 1) || (twos >= 4))
				results[Rindex] = true;
			break;
		}
		case 2: {
			if (twos >= 8 || (twos >=5 && threes >= 1) || (twos >= 2 && threes >= 2))
				results[Rindex] = true;
			break;
		}
		case 3: {
			if (twos >= 3 || threes >= 1)
				results[Rindex] = true;
			break;
		}
		case 4: {
			if (twos >= 7 || (twos >= 4 && threes >=1) || (threes >= 2 && twos >= 1))
				results[Rindex] = true;
			break;
		}
		case 5: {
			if (twos >= 2) {
				results[Rindex] = true;
			}
			break;
		}
		case 6: {
			if (twos >= 6 || threes >= 2 || (twos >= 3 && threes >=1)) {
				results[Rindex] = true;
			}
			break;
		}
		case 7: {
			if (twos >= 1)
				results[Rindex] = true;
			break;
		}
		case 8: {
			if (twos >= 5 || (twos >=2 && threes >=1)) {
				results[Rindex] = true;
			}
			break;
		}
		default:
			break;
		}
		Rindex++;
	}
	for (bool r : results) {
		if (r)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
// I am Going to become the King of the pirates
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long int
#define ff first
#define ss second
#define pb push_back
const ll mod = 1e9 + 7;
using namespace std ;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void solve() {
    int n;
    cin >> n;
    vector<int64_t> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = accumulate(a.begin(), a.end(), int64_t(0));
    while (a.size() > 1) {
        vector<int64_t> b(a.size() - 1);
        for (int i = 0; i < a.size() - 1; i++) {
            b[i] = a[i + 1] - a[i];
        }
        swap(a, b);
        ans = max(ans, abs(accumulate(a.begin(), a.end(), int64_t(0))));
    }
    cout << ans << '\n';
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

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

}

Solution 2 (runtime: 46 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<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans = INT_MIN;
	for (int len = n; len >= 1; len--) {
		vector<ll> b;
		ll sum = 0;
		for (int i = 0; i < len; i++) {
			sum += a[i];
			if (i > 0) {
				b.push_back(a[i] - a[i - 1]);
			}
		}
		if (len != n) {
			sum = abs(sum);
		}
		ans = max(ans, sum);
		a = b;
	}
	cout << ans << endl;
}

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