ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define mod 1000000007
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
bool comp(int a,int b){
  return a>b;
}
ll fact(ll n){
  ll x=n; ll prod=1;
  if(n==0) return 1;
  else{
  while(x){
    prod*=x;
    x--;
  }
  return prod;
  }
}
ll C(ll n, ll r){
  return fact(n)/(fact(r)*fact(n-r));
}

int main(){
    fast_io;
    int test=1;
    cin >> test;
    while(test--){
     int n;
     cin>>n;
     vector <ll> v(n);
     for(auto &x:v) cin>>x;
     ll sum=accumulate(v.begin(),v.end(),0ll);
     for(int i=1;i<n;i++){
      vector<ll> v1(n-i);
      for(int j=0;j<n-i;j++) v1[j]=v[j+1]-v[j];
      sum=max(sum,abs(accumulate(v1.begin(),v1.end(),0ll)));
      v=v1;
     }
     cout<<sum<<endl;
    }
    return 0;

}

Solution 2 (runtime: 46 ms):
#include<iostream>
#include<cmath>
using namespace std;
long long int t,n,a[52];
int main()
{
	scanf("%lld",&t);
	while(t--)
	{
		long long int aa=0;
		scanf("%lld",&n);
		for(long long int q=1;q<=n;q++)
			scanf("%lld",&a[q]),aa+=a[q];
		a[n+1]=0;
		if(n!=1)
		{
			while(n--)
			{
				for(long long int q=1;q<=n;q++)
					a[q]=a[q+1]-a[q];
				long long int sum=0;
				for(long long int q=1;q<=n;q++)
					sum+=a[q];
				aa=max(aa,max(sum,-sum));
			}
		}
		printf("%lld\n",aa);
	}
	
	return 0;
}
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 342 ms):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        long long a[n];
        long long sum=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum+=a[i];
        }
    long long k=sum/n;
    for(int i=0;i<=n-3;i++){
    int diff=a[i]-k;
    a[i]=k;
    a[i+2]+=diff;
    }
    if(a[n-1]==k && a[n-2]==k) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;    }
    return 0;
}

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

using  namespace std;

int main() {

    int t;cin >> t;

    while (t--) {

        long long n;cin >> n;

        vector<int>v(n);

        vector<int>v2(n);

        long long count = 0;

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

        for (int i = 0;i < v.size();i++)v2[i] = v[i];

        if (count % n){cout << "NO" << endl;continue;}

        long long sum = count / n;

        for (int i = 1;i < v.size() - 1;i++) {

            long long j1,j2;

            if (v[i - 1] < sum && v[i + 1] > sum) {

                j1 = sum - v[i - 1];

                v[i - 1] += j1;

                v[i + 1] -= j1;

            }else if (v[i - 1] > sum && v[i + 1] < sum){

                j1 = v[i - 1] - sum;

                v[i - 1] -= j1;

                v[i + 1] += j1;

            }

            else {

                j1 = v[i - 1] - sum;

                v[i - 1] -= j1;

                v[i + 1] += j1;

            }

        }

        bool f = true;

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

            if (v[i] != sum){f = false;break;}

        }

        for (int i = 1;i < v.size() - 1;i++) {

            int j1,j2;

            if (v[i - 1] < sum && v[i + 1] > sum) {

                j1 = sum - v[i - 1];

                v[i - 1] += j1;

                v[i + 1] -= j1;

            }else if (v[i - 1] > sum && v[i + 1] < sum){

                j1 = v[i - 1] - sum;

                v[i - 1] -= j1;

                v[i + 1] += j1;

            }

            else {

                j1 = sum - v[i - 1];

                v[i - 1] += j1;

                v[i + 1] -= j1;

            }

        }

        bool t = true;

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

            if (v2[i] != sum){t = false;break;}

        }

        if (f || t)cout << "YES" << endl;else cout << "NO" << endl;

        v.clear();v2.clear();

    }

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

Solution 1 (runtime: 108 ms):
#include<bits/stdc++.h>
#define int long long
using namespace std;
void solve(){
    int n,l,r;
    cin >> n >> l >> r;
    int a[n+1];
    l--;
    r--;
    vector<int>v1,v2;
    for(int i = 0; i < n ;i++){
        cin >> a[i];
    }
    for(int i = 0; i < n;i++){
        if(i <= r)  v1.push_back(a[i]);
        if(i >= l)  v2.push_back(a[i]);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    int cem1 = 0, cem2 = 0;
    for(int i = 0; i < r - l + 1; i++){
        cem1+= v1[i];
        cem2+= v2[i];
    }
    cout << min(cem1, cem2) << endl;
}
signed main (){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t=1;
    cin>>t;
    while (t--){
        solve();
    }
}


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

using namespace std;

typedef long long ll;

#define int long long

typedef pair<int, int> P;

const int N = 1e6 + 7, mod = 998244353, inf = 1e15;

int a[N], b[N];

inline void run(){

    int n, l, r;

    cin >> n >> l >> r;

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

        cin >> a[i];

        b[i] = a[i];

    }

    int res = 0, ans = 0;

    int m = r - l + 1;

    sort(a + 1, a + r + 1);

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

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

    // }

    // cout << '\n';

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

        res += a[i];

    }

    sort(b + l, b + n + 1);

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

    //     cout << b[i] << ' ';

    // }

    // cout << '\n';

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

        ans += b[i];

    }

   // cout << res << ' ' << ans << '\n';

    cout << min(res, ans) << '\n';

}

signed main(){

    std::ios_base::sync_with_stdio(false);

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

    int T;

    for(cin >> T; T > 0; T --)

    run(); return 0;

}
Problem: 2050C - Uninteresting Number
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;
        int sum=0;
        int cnt2=0;
        int cnt3=0;
        for(int i=0; i<s.size(); i++){
            sum+=s[i]-'0';
            if(s[i]=='2')
                cnt2++;
            if(s[i]=='3')
                cnt3++;
        }
        bool flag=false;
        for(int i=0; i<=cnt2; i++){
            for(int j=0; j<=cnt3; j++){
                int newNum=sum+2*i+6*j;
                if(newNum%9==0){
                    flag=true;
                    break;
                }
            }
            if(flag)
                break;
        }
        if(flag)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
#define it(a) a.begin(),a.end()
#define FOR(i,x,n) for(int i=x;i<n;i++) 
#define eb emplace_back
#define print(V) {for(auto v:V) cout << v << " " ; cout<< endl;}
#define sz(v) ((int)v.size())
#define yes "YES "
#define no "NO "
int gcd(int a,int b)
{
    if(b==0) return a;
    if(b>a) swap(a,b);
    return gcd(b,a%b);
}
void solution()
{  
   string s;
   cin >> s;
   int sum=0,tw=0,th=0;
   for(char c:s) {sum+=(c-'0'); if(c=='2') tw+=1; if(c=='3') th+=1;}
   
   if(sum%9==0)
   {
       cout << yes << endl; return;
   }
   if(sum%9==7 && tw>=1)
   {
       cout << yes << endl; return;
   }
   if(sum%9==3 && (th>=1 || tw>=3))
   {
       cout << yes << endl; return;
   }
   if(sum%9==1 && ((th>=1 && tw>=1)|| tw>=4))
   {
       cout << yes << endl; return;
   }
   if(sum%9==2 && (tw>=2 && th>=2 || (th>=1 && tw>=5) || tw>=8))
   {
       cout << yes << endl; return;
   }
   if(sum%9==4 && ((th>=2 && tw>=1)||(th>=1 && tw>=4) || tw>=7))
   {
       cout << yes << endl; return;
   }
   if(sum%9==5 && tw>=2)
   {
       cout << yes << endl; return;
   }
   if(sum%9==6 && (th>=2 || (tw>=3 && th>=1) || tw>=6))
   {
       cout << yes << endl; return;
   }
   if(sum%9==8 && ((th>=1 && tw>=2)|| tw>=5))
   {
       cout << yes << endl; return;
   }
   else cout << no << endl;
   
}
int main()
{  
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        solution();
    }
    cerr << "Total Time to run: " << 1000*(double)clock()/(double)CLOCKS_PER_SEC << "ms";
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 203 ms):
#include <set>

#include <map>

#include <cmath>

#include <queue>

#include <stack>

#include <vector>

#include <string>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <iostream>

#include <algorithm>



#define arrout(a,n) rep(i,1,n)std::cout<<a[i]

#define arrin(a,n) rep(i,1,n)std::cin>>a[i]

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

#define dep(i,x,n) for(int i=x;i>=n;i--)

#define mem(a,x) memset(a,x,sizeof a)

#define mp(a,b) make_pair(a,b)

#define arep(it,s) for(auto it=s.begin();it!=s.end();it++)

#define st first

#define ed second

#define eout(a) cout<<a<<endl;

#define INF 2e9;

#define int long long



using namespace std;

int l,r,mid;

int n,m,k,f,tot,ans,T,num;

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

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



int a[300005];

int b[300005];

int c[300005];

int v[1005][1005];

int fa[100005];



int num1,num2,num3;



void solve()

{

	num1=num2=num3=0;

	cin>>n>>l>>r;

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

	{

		cin>>a[i];

		b[i]=a[i];

	}

	sort(a+1,a+r+1);

	sort(b+l,b+n+1);

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

	{

		num1+=a[i];

	}

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

	{

		num3++;

		num2+=b[i];

		if(num3==r-l+1) break;

	}

	ans=min(num1,num2);

	eout(ans);

}



signed main() {

	cin>>T;

	while(T--)

	{

		solve();

	}

	return 0;

}

Solution 2 (runtime: 203 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 a[n];
        for(int i = 0; i < n; i++) cin >> a[i];
        
        vector<int> left;
        for(int i = l-1; i < n; i++) left.push_back(a[i]);

        sort(left.begin(), left.end());
        long long ans = 1e17, ss = 0ll;
        for(int i = 0; i < r-l+1; i++) {
            ss = ss + (long long)left[i];
        }
        ans = min(ans, ss);

        vector<int> right;
        for(int i = 0; i < r; i++) right.push_back(a[i]);
        sort(right.begin(), right.end());

        ss = 0;
        for(int i = 0; i < r-l+1; i++) {
            ss = ss + (long long)right[i];
        }

        ans = min(ans, ss);
        cout << ans << endl; 
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

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

using namespace std;

const int N = int(1e5);

int arr[N];
int n, k;

void solve()
{
    map<int, int> freq;
    for (int i = 0; i < n; i++)
        freq[arr[i]]++;

    int size = freq.size();
    vector<int> A;
    A.reserve(size);
    for (const auto &[k, v] : freq)
    {
        A.push_back(v);
    }

   
    sort(A.begin(), A.end());
    for (int i = 0; i < size - 1; i++)
    {
        if (k >= A[i])
        {
            A[size - 1] += A[i];
             k -= A[i];
            A[i] = 0;
           
        }
        else
        {
            break;
        }
    }

    int ans = 0;
    for (int i : A)
    {
        // cout << i << " ";
        if (i != 0)
            ++ans;
    }
    

    cout << ans << '\n';
}

int main()
{
   
    int tt;
    cin >> tt;
    while (tt--)
    {
        cin >> n >> k;
        for (int i = 0; i < n; i++)
            cin >> arr[i];
        solve();
    }

    return 0;
}

Solution 2 (runtime: 109 ms):
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);
    int t;  cin >> t;   while(t--)
    {
        int n, k;   cin >> n >> k;
        map<int,int>m;
        for (int i=0; i<n; i++) {
            int x;  cin >> x;
            m[x]++;
        }

        vector<int>a;
        for (auto i: m) {
            a.push_back(i.second);
        }
        sort(a.begin(), a.end());

        int s=a.size();

        stack<int>st;
        for (int i=s-1; i>=0; i--) st.push(a[i]);

        while(!st.empty() && k>0) {
            if (st.top()<=k) {
                k-=st.top();
                st.pop();
            }
            else break;
        }
        int ans=st.size();
        if (ans>0) cout << ans << endl;
        else cout << 1 << endl;

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

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


int pr(int x,vector<int> &pt){
  int a;
  a=pt[x];
  if(a==-1){
    return -1;
  }
  while(a!=x){
    pt[x]=a;
    x=a;
    a=pt[x];
  }
  return 0;
}
int checku(string x,string y){
  // cout<<x<<"dfhj"<<y<<endl;
  int maxl = max(x.length(), y.length());
  if(x.length()!=maxl){
    string l(maxl-x.length(),'0');
    x=l+x;
  }
  else{
    string l(maxl-y.length(),'0');
    y=l+y;
  }
   for (int i = 0; i < maxl; i++) {
        if (x[i] > y[i]) {
            return 0; // `a` is greater
        } else if (x[i] < y[i]) {
            return 1; // `b` is greater
        }
        else{
          continue ;
        }
    }
  return 0;
}
string cheo(string x,string y){
  // cout<<x<<" "<<y<<" ";
    int maxl = max(x.length(), y.length());
  if(x.length()!=maxl){
    string l(maxl-x.length(),'0');
    x=l+x;
  }
  else{
    string l(maxl-y.length(),'0');
    y=l+y;
  }
  string l="";
  for(int i=0;i<maxl;i++){
    if(x[i]==y[i]){
      l=l+"0";
    }
    else{
      l=l+"1";
    }
  }
  // cout<<l<<endl;
  return l;
}
void sol()
{
 int n;
//  cin>>n;
//  int a[n];
string t;
cin>>t;
n=t.length();
int z=0;
// vector<pair<int,int>> vecu;
// for(int i=0;i<n;i++){
  
// }
for(int i=0;i<n;i++){
  int x=t[i]-'0';
  int b=i;
  for(int j=i;j<min((i+10),n);j++){
    int y=t[j]-'0'-(j-i);
    if(y>x){
    b=j;
    x=y;
    }
  }
  while(b>i){
    swap(t[b],t[b-1]);
    b--;
  }
  t[i]=(char)(x+48);
  // cout<<t<<endl;
}
    // for (int i = 0; i < t.size(); i++) {
    //     int best = t[i] - '0', pos = i;
    //     for (int j = i; j < min(i + 10, (int) t.size()); j++) {
    //         if (t[j] - '0' - (j - i) > best) {
    //             best = t[j] - '0' - (j - i);
    //             pos = j;
    //         }
    //     }
    //     while (pos > i) {
    //         swap(t[pos], t[pos - 1]);
    //         pos--;
    //     }
    //     t[i] = char(best + '0');
    // }

cout<<t;
// //  vector<vector<int>> vecu(l+1);
// int z=0;
//  for(int i=0;i<n;i++){
//   cin>>a[i];
//  }
// cout<<ansu<<endl;
//  string t1,t2;
//  cin>>t1>>t2;
//  vector<vector<int>> vecu1(n+1,(vector<int> (26,0)));
//  vector<vector<int>> vecu2(n+1,(vector<int> (26,0)));

//  cout<<endl;
 
//  int a=t.length();
//  cout<<ansu<<endl;
// cout<<ansu;
cout<<endl;
//  cout<<ansu<<endl;
 return ;
 
 }
int32_t main(){
    int t;
    cin>>t;
    while(t--){
        sol();
    }
    // sol();
}



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

using namespace std;

void solve(){

   string s;cin>>s;

    int n=s.size();

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

        int tmp=s[i]-'0',pos=i;

        for(int j=i;j<min(i+10,int(s.size()));j++) {

            if(s[j]-'0'-(j-i)>tmp){tmp=s[j]-'0'-(j-i);pos=j;}

        }

        for(int k=pos;k>i;k--)swap(s[k],s[k-1]);

        s[i]=char(tmp+'0');

    }

    cout<<s<<endl;

}

int main(){

    int t;cin>>t;

    while(t--)solve();

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

Solution 1 (runtime: 77 ms):
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main() {
    int t;
    cin >> t;  // Read number of test cases

    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        
        int n = a.length();
        int m = b.length();
        
        // DP table initialization
        vector<vector<int>> dp(n + 1, vector<int>(m + 1, INT_MAX));
        dp[0][0] = 0;
        
        // Fill the dp table
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= m; j++) {
                if (i > 0 && c[i + j - 1] == a[i - 1]) {
                    dp[i][j] = min(dp[i][j], dp[i - 1][j]);
                }
                if (j > 0 && c[i + j - 1] == b[j - 1]) {
                    dp[i][j] = min(dp[i][j], dp[i][j - 1]);
                }
                if (i > 0 && c[i + j - 1] != a[i - 1]) {
                    dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
                }
                if (j > 0 && c[i + j - 1] != b[j - 1]) {
                    dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
                }
            }
        }

        // The answer is the minimum number of changes to match a and b to c
        cout << dp[n][m] << endl;
    }

    return 0;
}



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

int diffCount(string a, string b)
{
    int count = 0;
    for (int i = 0; i < a.size(); i++)
    {
        if (a[i] != b[i])
            count++;
    }
    return count;
}

int dp_helper(string &a, string &b, string &c, int i, int j, int k, vector<vector<int>> &arr)
{
    if(arr[i][j]!= -1){
        return arr[i][j];
    }
    if (i >= a.size() && j >= b.size())
    {
        return 0;
    }
    if (i >= a.size())
    {
        return arr[i][j] = diffCount(b.substr(j, b.size() - j), c.substr(k, c.size() - k));
    }
    else if (j >= b.size())
    {
        return arr[i][j] = diffCount(a.substr(i, a.size() - i), c.substr(k, c.size() - k));
    }
    if(a[i]==c[k] && b[j] == c[k]){
        return arr[i][j] =  min(dp_helper(a, b, c, i + 1, j, k + 1, arr), dp_helper(a, b, c, i, j + 1, k + 1, arr));
    }

    else if (a[i] == c[k])
    {
        return arr[i][j] = min(dp_helper(a, b, c, i + 1, j, k + 1, arr), 1 + dp_helper(a,b,c,i,j+1,k+1, arr));
    }
    else if (b[j] == c[k])
    {
        return arr[i][j] = min(dp_helper(a, b, c, i, j + 1, k + 1, arr), 1 + dp_helper(a, b, c, i + 1, j, k + 1, arr));
    }
    else
    {
        return arr[i][j] =  1 + min(dp_helper(a, b, c, i + 1, j, k + 1, arr), dp_helper(a, b, c, i, j + 1, k + 1, arr));
    }
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        
        string a, b, c;
        cin >> a >> b >> c;
        vector<vector<int>> arr(1002, vector<int> (1002, -1));
        cout << dp_helper(a, b, c, 0, 0, 0, arr)<<endl;
    }
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int tt;
    cin >> tt;
    while (tt--) {
        string A, B, C;
        cin >> A >> B >> C;
        int nA = int(A.size());
        int nB = int(B.size());
        vector<vector<int>> dp(nA + 1, vector<int>(nB + 1, nA + nB + 1));
        dp[0][0] = 0;
        for (int i = 0; i <= nA; i++) {
            for (int j = 0; j <= nB; j++) {
                if (i < nA) {
                    dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (A[i] != C[i + j]));
                }
                if (j < nB) {
                    dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (B[j] != C[i + j]));
                }
            }
        }
        cout << dp[nA][nB] << endl;
    }
}

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

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

const int INF = 1e9;

string a, b, c;

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

    int n = a.size();
    int m = b.size();

    vector<vector<int>> dp(n+1, vector<int>(m+1, INF));
    dp[0][0] = 0;

    for (int i=0; i<n; i++)
        dp[i+1][0] = dp[i][0] + (a[i] != c[i]);
    
    for (int j=0; j<m; j++)
        dp[0][j+1] = dp[0][j] + (b[j] != c[j]);

    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=m; j++)
        {
            dp[i][j] = min(dp[i-1][j] + (a[i-1] != c[i + j - 1]),
                            dp[i][j-1] + (b[j-1] != c[i + j - 1]));
        }
    }

    cout << dp[n][m] << "\n";
}

int main()
{
    fast_io();
    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}
Problem: 2049B - pspspsps
Language: c++17 

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

using namespace std;



int main()

{

    int t;

    cin>>t;

    while(t--)

    {

        int n;

        cin>>n;

        string s;

        cin>>s;

        if(s[0]=='s')

            s[0]='.';

        if(s[n-1]=='p')

            s[n-1]='.';

        bool f_s=false,f_p=false;



        for(char x:s)

        {

            if(x=='p')

                f_p=true;

            else if(x=='s')

                f_s=true;

        }

        cout<<((f_p && f_s)? "NO\n":"YES\n");

    }

    return 0;

}

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

using namespace std;

typedef long long ll;



void solve() {

    int n;

    cin >> n;

   

    string s;

    cin >> s;



    bool seen_s = false;

    bool seen_p = false;



    if(s[0] == 'p'){

        seen_p = true;

    }

    

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

        if(s[i] == 's'){

            if(seen_p){

                cout << "no\n";

                return;

            }

            seen_s = true;

        }

        else if(s[i] == 'p'){

            if(seen_s){

                cout << "no\n";

                return;

            }

            seen_p = true;

        }       

    }

    if(s[n-1] == 's' && seen_p){

        cout << "no\n";

        return;

    }



    cout << "yes\n";

}



int main() {

   ios_base::sync_with_stdio(false);

   cin.tie(nullptr);

   

   int t;

   cin >> t;

   while (t--) {

       solve();

   }

   return 0;

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

Solution 1 (runtime: 187 ms):
#include<iostream>

#include<algorithm>

using namespace std;

int main()

{

   int t;

   cin>>t;

   while(t--)

   {

    int n,l,r;

    cin>>n>>l>>r;

    int a[n];

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

        cin>>a[i];



    sort(a+l-1,a+r);

    sort(a,a+l-1);

    sort(a+r,a+n);





    int start = 0 , mid = r-1 , end = r;



    int long long  ans_1 = 0 ,  ans_2 = 0;



    while(mid>=l-1)

    {

        if(start<l-1)

            ans_1+=min(a[start],a[mid]);

        else

            ans_1+=a[mid];

        if(end<n)

            ans_2+=min(a[end],a[mid]);

        else

            ans_2+=a[mid];

        

        start++;

        mid--;

        end++;



    }



    cout<<min(ans_1,ans_2)<<endl;

   }

}

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;
        l--, r--; // Convert to 0-based indexing
        
        vector<long long> nums(n);
        for (int i = 0; i < n; i++) {
            cin >> nums[i];
        }
        
        vector<long long> a, b;
        
        // Get the first `r+1` elements
        for (int i = 0; i <= r; i++) {
            a.push_back(nums[i]);
        }
        
        // Get the elements from index `l` to `n-1`
        for (int i = l; i < n; i++) {
            b.push_back(nums[i]);
        }
        
        // Sorting
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());

        // Ensure valid sum range
        int len = r - l + 1;
        long long int sum1 = accumulate(a.begin(), a.begin() + min(len, (int)a.size()), 0LL);
        long long int sum2 = accumulate(b.begin(), b.begin() + min(len, (int)b.size()), 0LL);
        
        cout << min(sum1, sum2) << endl;
    }
}