ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: c++17 

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

using namespace std;
vector<vector<int>> dp;
int rec(string &a, string &b, string &c, int i, int j) {
    if(i == a.size() && j == b.size()) return 0;
    int pos = i+j;
    int res = INT_MAX;
    if(i < a.length()) {
        int cost = rec(a,b,c,i+1,j) + (a[i] != c[pos]);
        res = min(res, cost);
    }
    if(j < b.length()) {
        int cost = rec(a,b,c,i,j+1) + (b[j] != c[pos]);
        res = min(res, cost);
    }
    return res;
}

int mem(string &a, string &b, string &c, int i, int j) {
    if(i == a.size() && j == b.size()) return 0;
    if(dp[i][j] != -1) return dp[i][j];
    int pos = i+j;
    int res = INT_MAX;
    if(i < a.length()) {
        int cost = mem(a,b,c,i+1,j) + (a[i] != c[pos]);
        res = min(res, cost);
    }
    if(j < b.length()) {
        int cost = mem(a,b,c,i,j+1) + (b[j] != c[pos]);
        res = min(res, cost);
    }
    return dp[i][j] = res;
}

int tab(string &a, string &b, string &c) {
    dp[a.length()][b.length()] = 0;
    for(int j=0;j<b.length(); j++) dp[a.length()][j] = 0;
    for(int i=0;i<a.length(); i++) dp[i][b.length()] = 0;
    for(int i=a.length()-1;i >= 0; i--) {
        for(int j=b.length()-1; j >= 0; j--) { 
            int pos = i+j;
            int res = INT_MAX;
            if(i < a.length()) {
                int cost = dp[i+1][j] + (a[i] != c[pos]);
                res = min(res, cost);
            }
            if(j < b.length()) {
                int cost = dp[i][j+1] + (b[j] != c[pos]);
                res = min(res, cost);
            }
            dp[i][j] = res;         
        }
    }
    return dp[0][0];
}
int main() {
    #ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
    int t;
    cin >> t;
    string a, b, c;
    while (t--) {
        cin>>a>>b>>c; 
        dp.assign(a.length() + 1, vector<int> (b.length()+1, -1));
        //cout<<rec(a,b,c,0,0)<<'\n'
        cout<<mem(a,b,c,0,0)<<'\n';
        // cout<<tab(a,b,c)<<'\n';        
    }
}

/*
  
1 2 3 4 5
6 2 1 4 2
6 2 0 4 3
5 2 1 4 3
5 3 1 3 3
4 3 2 3 3
3 3 3 3 3

6 2 1 4 2
3 2 4 4 2
3 3 4 3 2
3 3 3 3 3

4 2 1 5 3

4 2 1 5 3
4 3 1 4 3

*/

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

// 计算最少修改次数
int minChanges(const string& a, const string& b, const string& c) {
    int n = a.size(), m = b.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 1e9));

    dp[0][0] = 0; // 初始状态
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            if (i > 0) { // 从 a 取字符
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + (a[i - 1] != c[i + j - 1]));
            }
            if (j > 0) { // 从 b 取字符
                dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));
            }
        }
    }

    return dp[n][m];
}

int main() {
    int t;
    cin >> t; // 读取测试用例数
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c; // 读取输入
        cout << minChanges(a, b, c) << endl; // 输出最少修改次数
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
int main() {
	int t;
	cin >> t;
	while (t--) {
		string a, b, c;
		getchar();
		cin >> a;
		getchar();
		cin >> b;
		getchar();
		cin >> c;
		vector < vector <int> > dp(a.size() + 1, vector <int>(b.size() + 1, 0x3f3f3f3f));
		dp[0][0] = 0;
		for (int i = 1;i <= b.size();i++) {
			dp[0][i] = dp[0][i - 1];
			if (b[i - 1] != c[i - 1]) {
				dp[0][i]++;
			}
		}
		for (int i = 1;i <= a.size();i++) {
			dp[i][0] = dp[i - 1][0];
			if (a[i - 1] != c[i - 1]) {
				dp[i][0]++;
			}
		}
		for (int i = 1;i <= a.size();i++) {
			for (int j = 1;j <= b.size();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]));
			}
		}
		/*for (int i = 0;i <= a.size();i++) {
			for (int j = 0;j <= b.size();j++) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}*/
		cout << dp[a.size()][b.size()] << endl;
	}
	return 0;
}


Solution 2 (runtime: 921 ms):
#include<bits/stdc++.h>
using namespace std;
int solve(string&a, string&b, string&c, int inda, int indb,map<pair<int,int>,int>&dp){
	if(inda==a.length() && indb==b.length()) return 0;
	if(dp.find({inda, indb})!=dp.end()) return dp[{inda, indb}];
	int ans = c.length();
	if(inda<a.length()){
		inda++;
		int curPos = inda+indb-1;
		int d = solve(a,b,c,inda,indb,dp);
		inda--;
		if(a[inda] == c[curPos]){
			ans = min(ans,d);
		} else{
			ans = min(ans, d+1);
		}
	}

	if(indb<b.length()){
		indb++;
		int curPos = inda+indb-1;
		int d = solve(a,b,c,inda,indb,dp);
		indb--;
		if(b[indb] == c[curPos]){
			ans = min(ans,d);
		} else{
			ans = min(ans, d+1);
		}
	}
	return dp[{inda, indb}] = ans;
}
int main(){
	int t;
	cin>>t;
	string a,b,c;
	while(t--){
		cin>>a>>b>>c;
		map<pair<int,int>,int>dp;
		cout<<solve(a,b,c,0,0,dp)<<"\n";
	}
}
Problem: 2049B - pspspsps
Language: c++17 

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

using namespace std;

using ll = long long;

using pii = pair<int,int>;

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

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

#define pb push_back

const int N = 5000;

char s[N];

void solve(){

	int n; cin >> n; scanf("%s",s + 1);

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

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

			for(int j = i - 1; j >= 1; -- j){

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

					cout << "NO" << endl;

					return; 

				}

			}

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

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

					if(j != n && (i != 1)){

						cout << "NO" << endl;

						return ;

					}

				}

			}

		}

	}

	cout << "YES" << endl;

	return;

}

int main(){

	int _;cin >> _;

	while(_--){

		solve();

	}

	return 0;

}

/*   /\_/\

*   (= ._.)

*   / >  \>

*/





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

using namespace std;

#define int long long

const int N = 1e7 + 10;



int a[200010];



void solve()

{

    int n;

    cin >> n;

    string s;

    cin >> s;

    int fp = 0;

    int fs = 0;

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

    {

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

        {

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

            {

                cout << "NO\n";

                return;

            }

        }

    }

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

    {

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

        {

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

            {

                cout << "NO\n";

                return;

            }

        }

    }

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

    {

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

        {

            fs = 1;

        }

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

        {

            fp = 1;

        }

        if (fs && fp){

            cout << "NO\n";

            return;

        }

    }

    cout << "YES\n";

    return;

}

signed main()

{



    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int t = 1;

    cin >> t;

    while (t--)

        solve();

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

Solution 1 (runtime: 77 ms):
/* God is Great !
    Author : SANIDHIYA */
#include<bits/stdc++.h>
using namespace std;
int dp[1005][1005];
int checker(string &a, string &b, string &c, int i1 = 0, int i2 = 0){
    if(i1 + i2 == c.size()){
        return 0;
    }
    if(dp[i1][i2] != -1){
        return dp[i1][i2];
    }
    int a1 = 5000, b1 = 5000, c1 = 5000,d1 = 5000;
  
    
    if(i1 != a.size() and a[i1] == c[i1 + i2]){
        a1 = checker(a, b, c, i1 + 1, i2);
    }
    if(i2 != b.size() and b[i2] == c[i1 + i2]){
        b1 = checker(a, b, c, i1, i2 + 1);
    }
    if(i1 != a.size())
    c1 = 1 + checker(a, b, c, i1 + 1, i2);
    if(i2 != b.size())
    d1 = 1 + checker(a, b, c, i1, i2 + 1);
    return dp[i1][i2] = min({a1, b1, c1, d1});
}
void solve()
{
    int t; cin >> t;
    while(t--){
        string a, b,c;
        cin >> a >> b >> c;
        for(int i = 0; i < a.size() + 2; i++){
            for(int j = 0; j < b.size() + 2; j++){
                dp[i][j] = -1;
            }
        }
        int ans = checker(a, b, c);
        cout<<ans<<endl;
    }
    
}
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
solve();
return 0;
}

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

ll solve(ll idx,ll i,ll j,string&a,string &b,string&c,vector<vector<ll>>&dp)
{
    if(idx==c.size())
    return 0;
    if(dp[i][j]!=-1)
    return dp[i][j];
    set<ll>ch;
    if((i<a.size() &&  a[i]==c[idx]))
    {
        ch.insert(solve(idx+1,i+1,j,a,b,c,dp));
    }
    if((j<b.size() && b[j]==c[idx]))
    {
        ch.insert(solve(idx+1,i,j+1,a,b,c,dp));

    }
    if(i==a.size())
    {
        ch.insert(1+solve(idx+1,i,j+1,a,b,c,dp));
    }
    if(j==b.size())
    {
        ch.insert(1+solve(idx+1,i+1,j,a,b,c,dp));

    }
    if(i<a.size() && j<b.size())
    {
        ch.insert(1+solve(idx+1,i,j+1,a,b,c,dp));
        ch.insert(1+solve(idx+1,i+1,j,a,b,c,dp));

    }
    return  dp[i][j]=*(ch.begin());
}
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;
    vector<vector<ll>>dp(a.size()+1,vector<ll>(b.size()+1,-1));
    cout<<solve(0,0,0,a,b,c,dp)<<endl;

}

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

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
const char nl = '\n';
using ll = long long;
using namespace std;

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

    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        ll sum = 0;
        ll cnt2 = 0; ll cnt3 = 0;
        for (int i=0; i<s.size(); i++)
        {
            int digit = s[i]-'0';
            sum += digit;
            if (digit == 2)
                cnt2 += 1;
            else if (digit == 3)
                cnt3 += 1;
        }
        cnt2 = min(cnt2,(ll)8);
        cnt3 = min(cnt3,(ll)8);
        int validate = 0;
        for(int i=0; i<=cnt2 ; i++)
        {
            if (i>0)
                sum += 2;
            for (int j=0; j<=cnt3; j++)
            {
                if (j>0)
                    sum += 6;
                if (sum%9 == 0)
                {
                    cout << "YES" << nl;
                    validate = 1;
                    break;
                }
            }
            sum -= 6*cnt3;
            if (validate == 1)
                break;
        }
        if (validate == 0)
            cout << "NO" << nl;
    }
    return 0;
}


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

int32_t main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int sum = 0;
        for (char c : s)
        {
            sum += c - '0';
        }
        int twos = 0;
        int threes = 0;
        for (char c : s)
        {
            if (c == '2')
            {
                twos++;
            }
            else if (c == '3')
            {
                threes++;
            }
        }
        int flag = 0;
        for (int i = 0; i <= min(10ll, twos); i++)
        {
            for (int j = 0; j <= min(10ll, threes); j++)
            {
                if ((sum + 2 * i + 6 * j) % 9 == 0)
                {
                    flag = 1;
                    break;
                }
            }
        }
        if (flag)
        {
            cout << "YES\n";
        }
        else
        {
            cout << "NO\n";
        }
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define mi map<int,int>
#define umi unordered_map<int,int>
#define si set<int>
#define ms multiset<int>
#define usi unordered_set<int>
#define lb lower_bound
#define ub upper_bound
template<class T> using min_pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> using max_pq = priority_queue<T>;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define prDouble(x) cout << fixed << setprecision(6) << x
void if_Solution_Hack_karne_aya_hai_next_sem_fail_hoga()
{
    int n,l,r;
    cin >> n >> l >> r;
    l--,r--;
    vi a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    vi v1,v2;
    for(int i=0;i<n;i++)
    {
        if(i<l) v1.pb(a[i]);
        else if(i>r) v2.pb(a[i]);
        else v1.pb(a[i]),v2.pb(a[i]);
    
    }
    sort(all(v1));
    sort(all(v2));
    int ans1=0,ans2=0;
    int x=r-l+1;
    for(int i=0;i<x;i++)
    {
        ans1+=v1[i];
        ans2+=v2[i];
    }
    
    


    cout << min(ans1,ans2) << endl;
}
signed main()
{
    fast_io;
    int t=1;
    cin >> t;
    while(t--)
    {
        if_Solution_Hack_karne_aya_hai_next_sem_fail_hoga();
    }
    return 0;
}

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

using namespace std;

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<long long>v(n);

    l--;r--;

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

    {

        cin>>v[i];

    }

   vector<long long>a;

   vector<long long>b;

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

   {

     a.push_back(v[i]);

   }

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

   {

       b.push_back(v[i]);

   }

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

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

   int k=r-l+1;

   long long sum=0,sum1=0;

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

   {

       sum=sum+a[i];

       sum1=sum1+b[i];

   }

   cout<<min(sum,sum1)<<"\n";

    }

return 0;

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

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define frfr for (int i = 0; i < n; i++)
#define vi vector<int>
#define ll long long
#define pii pair<int, int>
#define ump unordered_map<int, int>
#define vpii vector<pair<int, int>>

void solve1() {
    string a, b, c;
    cin >> a >> b >> c;
    int n = a.size(), m = b.size();
    if (n + m != c.size()) {
        cout << -1 << endl; // Impossible to merge
        return;
    }

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

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

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


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

using namespace std;

typedef long long ll;

typedef pair<int,int>pll;

const int N=1e3+5;

void solved()

{

    string a,b,c;

    cin>>a>>b>>c;

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

    vector<vector<int>>dp(n+2,vector<int>(m+2));

    //dp[1][0]=(a[0]!=c[0]);

    //dp[0][1]=(b[0]!=c[0]);

    //a=' '+a;b=' '+b;c=' '+c;

    dp[0][0]=0;

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

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

            if(i==0&&j==0)

                continue;

            if(j==0&&i>0)

                dp[i][j]=dp[i-1][j]+(a[i-1]!=c[i+j-1]);

            if(i==0&&j>0)

                dp[i][j]=dp[i][j-1]+(b[j-1]!=c[i+j-1]);

            if(i>0&&j>0)

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

{   

    ios::sync_with_stdio(false);    

    cin.tie(nullptr); 

    cout.tie(nullptr);

    //int t=1;

    int t;cin>>t;

    while(t--)

        solved();

    return 0;

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

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

void solve() {
    int n;
    cin >> n;
    vector<long long> arr(n);

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

    int len = n;
    long long ans = LLONG_MIN;

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

        for (int j = 0; j < len; j++) 
            sum += arr[j];

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

        for (int j = 0; j < len - 1; j++) 
            arr[j] = arr[j+1] - arr[j];

        len--;
    }

    cout << ans << endl;
}

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


Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define int long long
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define test(x) for(auto i:x){cout << i << ' ';}cout<< endl;
using namespace std;

const int MOD = 998244353;

// Function to compute (2^exp) % MOD using binary exponentiation
int pow2(int exp) {
    int result = 1, base = 2;
    while (exp > 0) {
        if (exp % 2 == 1) result = (result * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return result;
}
bool done(ll n)
{
    while (n)
    {
        if (n % 10 == 7)
        {
            return true;
        }
        n /= 10;
    }
    return false;
}
void solve()
{
    ll 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;
        return;
    }
    int maxi = -1e18;
    for(int k = 1;k<=n-1;k++){
        vector<int>temp;
        maxi = max(maxi,(a.size()!=1?(abs(a[a.size()-1]-a[0])):abs(a[0])));
        for(int i = 0;i<a.size()-1;i++){
            temp.push_back(a[i+1]-a[i]);
        }
        a = temp;
    }
    cout << max(maxi,sum) << endl;
}


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

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

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
 
const int maxn = (int)2e5 + 10;
int t, f[maxn][10];
string n;

 
int main()
{
    cin >> t;
    while(t--)
    {
        cin >> n;
        n = " " + n;
        for (int i = 0; i < n.length(); i++)
            for (int j = 0; j <= 9; j++) f[i][j] = 0;
        f[0][0] = 1;
        for (int i = 1; i < n.length(); i++)
        {
            int d = n[i] - '0';
            for (int j = 0; j <= 9; j++)
            {
                if (f[i - 1][j])
                {
                    f[i][(j + d) % 9] = 1;
                    if (d <= 3)
                    {
                        f[i][(j + d * d) % 9] = 1;
                    }
                }
            }
        }
        
        if (f[n.length() - 1][0]) cout << "YES\n";
        else cout << "NO\n";
    }
}


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

int main()
{
    int t;cin>>t;
    while(t--)
    {
        string s;cin>>s;
        long long sum=0,dui=0,tin=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='2')dui++;
            if(s[i]=='3')tin++;
            sum+=(s[i]-'0');
        }
        if(sum%9==0)cout<<"YES"<<endl;
        else
        {
            sum=sum%9;bool b=false;
            for(int i=0;i<=min(dui,(long long)8);i++)
            {
                for(int j=0;j<=min(tin,(long long)2);j++)
                {
                    if((sum+2*i+6*j)%9==0)
                    {
                        b=true;break;
                    }
                }
            }
            (b)?cout<<"YES"<<endl:cout<<"NO"<<endl;
        }
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <vector>
#include <iostream>
#include <cmath>

using namespace std;
typedef long long ll;
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];
        }
        ll dp=0;
        for (int i=0;i<n;i++){
            dp+=a[i];
        }
        vector<ll> old=a;
        ll ans=dp;
        for (int i=0;i<a.size()-1;i++){
            vector<ll> ne;
            ll dsun=0;
            for (int j=1;j<old.size();j++){
                ne.push_back(old[j]-old[j-1]);
                dsun+=old[j]-old[j-1];
            }
            dp=max(abs(dsun),dp);
            old=ne;
        }
        cout<<dp<<endl;
    }
}

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

int main(){
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<ll> a(n);
        ll sum = 0;
        for(int i = 0; i < n; i++){
            cin >> a[i];
            sum+=a[i];
        }
        if(n == 1){
            cout << a[0] << endl;
            continue;
        }

        while (n)
        {   
            ll tmp = a[n-1] - a[0];
            for(int i=0; i<n-1; i++){
                a[i] = a[i+1] - a[i];
            }
            n--;
            sum = max(sum, max(tmp, -tmp));
        }
        cout << sum << endl;
        
    }
    
}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

void solve(){
    string s;
    cin >> s;
    int sum = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    for(int i = 0;i<s.length();i++){
        sum += s[i] -'0';
        if(s[i]-'0' == 2) cnt2++;
        else if(s[i]-'0' == 3) cnt3++;
    }
    
    for(int i = 0;i<=cnt2;i++){
        for(int j = 0;j<=cnt3;j++){
            if((sum + i*2 + j*6)%9 == 0){
                cout << "YES" << endl;
                return ;
            }
        }
    }
    cout <<"NO" <<endl;
    return ;
}

int main(){
    int tc;
    cin >> tc;
    while(tc--){
        solve();
    }
}

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

#include <bits/stdc++.h>

using namespace std;



#define endl '\n'

typedef long long ll;





int main(){



	ios_base::sync_with_stdio(false);

	cin.tie(NULL);







	ll t; cin>>t;

	while(t--> 0){

		

		string str; 

		ll sum=0;

		cin>>str;

		int freq[10]{};

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

			int curr = str[i]-'0';

			sum+=(curr);

			if(str[i]=='2'){

				freq[2]++;

			}

			if(str[i]=='3'){

				freq[3]++;

			}





		}

		

		if(!(sum%9)){

			cout<<"YES"<<endl;

		}else{

			string ans="NO";

			for(int i = 0;i<=min(freq[2],9);i++){

				for(int j = 0;j<=min(freq[3],9);j++){

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

						ans="YES";

						break;

						i = freq[2]+1;

					}



				}

			}

			cout<<ans<<endl;



		}









		}	





 

 

 

	return 0;

}