ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049B - pspspsps
Language: c++17 

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

        using namespace std;

        #define ll long long

        #define test cout<<"ok"<<endl; 

        #define check(n) for(auto x:n)cout<<x<<" "

        //  p.push_back(make_pair(a,b));

        // pr.push_back({1,3});

        //factor and divisor are same which is limited & multiple are unlimited

        #define debug(x) cout << #x <<" " << x << endl;

        #define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

        #define MX  1000000+7

        vector < bool > is_prime(MX+ 1, true);

        /*is_prime[0] = false;

        is_prime[1] = true;

        for(int i = 2; i<= MX; i++){

            if(is_prime[i] == true && i * i <= MX)

                {

                    for(int j = i * i ; j <= MX ;j+= i)

                    {       

                        is_prime[j] = false;

                    }

                }



        }*/



        void solve(){

        ll n; cin >> n;    

         string s;

         cin >> s;

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

            s[0] = '.';

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

            s[n-1] = '.';

        

        bool flag1= false, flag2 = false;

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

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

                flag1 = true;

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

                flag2 = true;

        }

        if(flag1 & flag2)

            cout << "NO" << endl;

        else 

            cout <<"YES" << endl;

        

        }



        int main(){

        Faster;

        int t;   cin >> t;



        while(t --){    

            solve();

            }

        }

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

using namespace std;

#define endl '\n'

#define ll long long

#define vi vector<int>

#define vii vector<vi>

#define viii vector<vii>

#define vl vector<long long>

#define vll vector<vl>

#define vlll vector<vll>

#define pii pair<int, int>

#define pll pair<ll, ll>



void solve() {

	int n; cin >> n;

	

	string s; cin >> s;

	

	char ori = '.';

	

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

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

			ori = s[i];

			break;

		}

	

	if (ori == '.')

		return void (cout << "YES" << endl);

	

	ori = 's';

	

	int cnt = 0;

	

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

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

			continue;

		

		if (s[i] == ori)

			continue;

		

		if (s[i] != ori) {

			ori = s[i];

			cnt++;

		}

	}

	

	if (cnt > 1)

		return void (cout << "NO" << endl);

		

	ori = 'p';

	

	cnt = 0;

	

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

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

			continue;

		

		if (s[i] == ori)

			continue;

		

		if (s[i] != ori) {

			ori = s[i];

			cnt++;

		}

	}

	

	if (cnt > 1)

		return void (cout << "NO" << endl);

	

	cout << "YES" << endl;

}



int main() {

    

    ios::sync_with_stdio(false);

    cout.tie(NULL);

    

	int _ = 1;

	cin >> _;



    while (_--)

        solve();

    

    return 0;

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

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

#define ll long long
#define ull unsigned long long
#define dbl double
#define yes cout << "YES\n"
#define no cout << "NO\n"
constexpr dbl PI = 3.14159265359;
constexpr ll mod = 1e9 + 7;

using namespace std;

void solve() {
    int n;
    cin >> n;

    int j = 0;
    vector<int> vec(n);
    for (int i = 0; i < n; ++i) {
        cin >> vec[i];
        if (i > 0 && vec[i] < vec[i - 1]) j = i;
    }
    if (j == 0) {
        cout << "YES\n";
        return;
    }

    for (int i = 0; i < j; ++i) {
        ll minN = min(vec[i], vec[i+1]);
        vec[i] -= minN;
        vec[i+1] -= minN;
    }

    cout << (is_sorted(vec.begin(), vec.end()) ? "YES" : "NO") << '\n';
}

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

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

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

    return 0;
}

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

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;

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

        bool flag = true;
        for (int i = 0; i < n - 1; i++)
        {
            if (v[i] > v[i + 1])
            {
                flag = false;
                break;
            }

            v[i + 1] -= v[i];
            v[i] = 0;
        }

        if (flag)
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
#define PII pair<int,int>
#define int long long
#define ull unsigned long long
#define vii vector<int>
#define qwq ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;

const int N = 2e5+5;

/*
f[i][j] 表示 c[i+j] 由 a[1~i] + b[1~j] 组成 的最少次数

最后一位要么是
a[i]：f[i-1][j]
b[j]：f[i][j-1]
任意一个的修改 min(f[i-1][j], f[i][j-1])+1;
*/
string a, b, c;

int f[1005][1005];

void solve() {
	cin >> a >> b >> c;
	a = " " + a;
	b = " " + b;
	c = " " + c;
	
	for (int i=0; i<a.size(); i++) {
		for (int j=0; j<b.size(); j++) f[i][j] = 2e9;
	}
	
	f[0][0] = 0;
	
	for (int k=1; k<c.size(); k++) {
		for (int i=0; i<a.size(); i++) {
			int j = k-i;
			if (j < 0) break;
			if (j >= b.size()) continue;
			
			if (i > 0 and a[i] == c[k]) f[i][j] = min(f[i][j], f[i-1][j]);
			else if (i > 0) f[i][j] = min(f[i][j], f[i-1][j]+1);
			if (j > 0 and b[j] == c[k]) f[i][j] = min(f[i][j], f[i][j-1]);
			else if (j > 0) f[i][j] = min(f[i][j], f[i][j-1]+1);
		}
	}
	
	cout << f[a.size()-1][b.size()-1] << '\n';
}

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

Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define MOD 998244353
#define mod 1000000007
#define INF 1000000000000000
//#define f first
//#define s second

void solve(){
  int n,m;
  string a,b,c; cin>>a>>b>>c;
  n=a.size();
  m=b.size();
  vector<vector<int>> dp(n+1,vector<int> (m+1,1000000));
  dp[0][0]=0;
  for(int i=0;i<n;i++){
    if(a[i]==c[i]) dp[i+1][0]=dp[i][0];
    else dp[i+1][0]=dp[i][0]+1;
  }
  for(int i=0;i<m;i++){
    if(b[i]==c[i]) dp[0][i+1]=dp[0][i];
    else dp[0][i+1]=dp[0][i]+1;
  }
  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(){
  ios_base::sync_with_stdio(false);  cin.tie(0);  cout.tie(0);
  int t; cin>>t; for(int T=0;T<t;T++) solve();
}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 264 ms):
#include <bits/stdc++.h>
#define ll long long
#define PII pair<ll, ll>
using namespace std;
const ll inf = 1e18+9;

void printvec(vector<ll> vec) { for (auto it = vec.begin(); it != vec.end(); ++it) { cout << *it << " ";} cout << endl;}
void print2dvec(const vector<vector<ll>>& vec) { for (const auto& row : vec) { for (const auto& element : row) { cout << element << " ";}cout << endl;}}
void printmap(const map<ll, vector<ll>>& g) {for (const auto& [key, value] : g) { cout << "key: " << key << " -> ";for (const auto& v : value) {cout << v << " ";}cout << endl;}}
void printPII(vector<PII> vec) { for (auto it = vec.begin(); it != vec.end(); ++it) {cout << (*it).first << ", " << (*it).second;}cout << endl;}

void MIKUUUUUU() {
    ll n;
    cin >> n;
    vector<vector<ll>> g(n+1);
    for (int i = 0; i < n-1; i++) {
        ll u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    ll mx = -1;
    ll mx2 = -1;
    ll mxind = 0;
    vector<ll> sz(n+1);
    for (int i = 1; i <= n; i++) {
        sz[i] = g[i].size();
    }
    auto isz = sz;
    // printvec(sz);
    ll mxind2 = 0;
    for (int u = 1; u <= n; u++) {
        if (g[u].size() > mx) {
            mx = sz[u];
            mxind = u;
            mxind2 = 0;
        }
        else if (sz[u] == mx) mxind2 = u;
    }
    for (auto v: g[mxind]) {
        sz[v] -= 1;
    }
    for (int u = 1; u <= n; u++) {
        if (u != mxind && sz[u] > mx2) {
            mx2 = sz[u];
        }
    }
    ll miku = mx2 + mx -1;
    if (mxind2 != 0) {
        sz = isz;
        mx2 = -1;
        for (auto v:g[mxind2]) {
            sz[v]--;
        }
        for (int i = 1; i <= n; i++) {
            if (i != mxind2) mx2 = max(sz[i], mx2);
        }
        miku = max(miku, mx+mx2-1);
    }
    cout << miku << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tt; cin >> tt; while (tt--)
        MIKUUUUUU();
    return 0;
} 

Solution 2 (runtime: 749 ms):
#include<iostream>
#include<vector>
#include<set>
#define add(a,b) e[a].push_back(b)
#define rep for(int v:e[i])
#define siz(a) e[a].size()
using namespace std;

const int N=1e6+5;

int t;

vector<int>e[N];
multiset<int>s;


inline void work(){
	s.clear();
	int n,ans=0;
	cin>>n;
	for(int i=0;i<=n;++i)e[i].clear();
	for(int i=1;i<n;++i){
		int u,v;
		cin>>u>>v;
		add(u,v),add(v,u);
	}
	for(int i=1;i<=n;++i){
		s.insert(siz(i));
	}
	for(int i=1;i<=n;++i){
		s.erase(s.find(siz(i)));
		rep{
			s.erase(s.find(siz(v)));
			s.insert(siz(v)-1);
		}
		ans=max(ans,(int)siz(i)+*s.rbegin()-1);
		s.insert(siz(i));
		rep{
			s.erase(s.find(siz(v)-1));
			s.insert(siz(v));
		}
	}
	cout<<ans<<"\n";
	return ;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--)work();
	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 343 ms):
#include<bits/stdc++.h>
#define ll long long 
#define st first
#define pii pair<ll,ll>
#define nd second
#define pb push_back
using namespace std;
const int N = 2e5+10;
bool CASE = true;
void solve (){
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0; i < n; i++) cin >> arr[i];
    bool ch = false, can = true;
    for(int i = 1; i < n; i++){
        if(arr[i] < arr[i-1]){
           if(!ch){
               can = false;
               break;
           }
           break;
        }
        if(arr[i] > arr[i-1]){
            ch = true;
        }
    }
    // if(!ch) can = false;
    if(can) cout << "YES\n";
    else cout << "NO\n";
}
int main(){   
    ios_base::sync_with_stdio(false);cin.tie(0);
    int t = 1;
    if(CASE) cin >> t;
    while(t--){   
        solve();
    }
}

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

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> a(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n-1;i++){
            if (a[i]<=a[i+1]){
                a[i+1]-=a[i];
                a[i]=0;
            }
        }
        // for(auto e:a){
        //     cout<<e<<" ";
        // }
        // cout<<endl;
        bool f=false;
        for(int i=0;i<n-1;i++){
            if (a[i]>a[i+1]){
                f=true;
                break;
            }
        }
        if (f){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
        }
    }
    
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 92 ms):
/*
    https://codeforces.com/contest/2057/problem/C
    (C. Trip to the Olympiad)
*/

#include <bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ll long long    // range : -9*10^18 ~ 9*10^18

/*
    Algorithm
        115 = 0111'0011
        127 = 0111'1111

        128 = 1000'0000
        137 = 1000'1001
*/

const int MAX_BIT = 30;

int t;
int l, r;

void solve_wrong(){
    int num = r;
    int msb = 1;
    while(num){
        num >>= 1;
        msb <<= 1;
    }

    int a = (msb >>= 1);
    int b;
    if(l <= a - 1){
        b = a - 1;
    }
    else{
        b = r;
    }
    int c;
    for(int num=l; num<=r; ++num){
        if(num != a && num != b){
            c = num;
            break;
        }
    }
    cout << a << " " << b << " " << c << endl;
    // cout << "   " << (a^b + b^c + a^c) << endl; // WRONG : operator precedence (addition + precedes bitwise xor ^)
    // cout << "   " << (a^b) + (b^c) + (a^c) << endl; // AC
}

void solve(){
    vector<int> left;
    vector<int> right;
    int val;
    val = l;
    while(val){
        if(val & 1){
            left.push_back(1);
        }
        else{
            left.push_back(0);
        }
        val >>= 1;
    }
    // NOTE : leading zeros
    for(int ith=1; ith<=MAX_BIT; ++ith){
        left.push_back(0);
    }

    val = r;
    while(val){
        if(val & 1){
            right.push_back(1);
        }
        else{
            right.push_back(0);
        }
        val >>= 1;
    }

    int bit_l = left.size();
    int bit_r = right.size();

    int base = 0;
    int msb;
    for(int bit=bit_r-1; bit>=0; --bit){
        if(left[bit] != right[bit]){
            msb = bit;
            break;
        }
        else{
            if(left[bit]){
                base += (1 << bit);
            }
        }
    }

    int a = base + (1 << msb);
    int b = a - 1;
    int c;
    for(int num=l; num<=r; ++num){
        if(num != a && num != b){
            c = num;
            break;
        }
    }

    cout << a << " " << b << " " << c << endl;
}

void input(){
    cin >> t;
    while(t--){
        cin >> l >> r;

        solve();
    }
}

void debug(){

}

int main(){
    IOS;

    // freopen("_.in", "rt", stdin);
    // freopen("_.out", "wt", stdout);

    // debug();

    input();

    // solve();

    return 0;
}


Solution 2 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int t;
    cin>>t;
    while(t--){
        ll l,r,a=0,b=0,c=0;
        scanf("%lld%lld",&l,&r);
        for(int i=29;i>=0;i--){
            if(((l^r)>>i)&1){
                a+=(1<<i);
                b+=(1<<i)-1;
                break;
            }
            else{
                a+=l&(1<<i);
                b+=l&(1<<i);
            }
        }
        c=l;
        while(c==a||c==b) c++;
        cout<<a<<" "<<b<<" "<<c<<endl;
    }
    return 0;
}
Problem: 2049C - MEX Cycle
Language: c++17 

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

using namespace std;



#pragma GCC optimize ("unroll-loops")

#pragma GCC optimize ("O2")

using ll = long long;

const ll MAXN =2e5 + 5;

const ll INF = 2e18;

const ll MOD = 1e9 + 7;

const ll LOG = 30;

#define fi first

#define se second

#define pll pair <ll, ll>

#define vll vector <ll>

#define endl '\n'

#define debug(x) cout << #x << ": " << (x) << endl;



ll n, m, k;

ll a [MAXN];



void solve(){

    cin >> n >> m >> k;

    if(m > k) swap(m, k);

    a[m] = 0;

    a[k] = 1;

    for(ll i = m+1; i < k; i++) a[i] = !a[i-1];

    if(a[k-1] == 1) a[k-1] = 2;

    for(ll i = m-1; i >= 1; i--) a[i] = !a[i+1];

    for(ll i = n; i > k; i--){

        ll pre = i+1;

        if(pre == n+1) pre = 1;

        a[i] = !a[pre];

    }

    ll pre = k+1;

    if(pre == n+1) pre = 1;

    if(a[pre] == 1) a[pre] = 2;

    for(ll i = 1; i <= n; i++) cout << a[i] << " ";

    cout << endl;

}



int main(){

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

    ll t; cin >> t;

    while(t--){

        solve();

    }

}

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

using namespace std;

#define endl '\n'

#define ll long long

#define vi vector<int>

#define vii vector<vi>

#define viii vector<vii>

#define vl vector<long long>

#define vll vector<vl>

#define vlll vector<vll>

#define pii pair<int, int>

#define pll pair<ll, ll>



void solve() {

	int n, x, y; cin >> n >> x >> y;

	

	vi a(n + 1);

	

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

		a[i] = i % 2;

	

	if (n & 1) {

		a[n - 1] = 2;

		a[n] = 0;

	}

	

	if ((y + 1) % n == x || x + 1 == y);

	else if (a[x] == a[y]) {

		a[x] = 2;

		

		if (n % 2 == 1 && x == n - 3 && y == n) {

			a[n - 2] = 0;

			a[n - 1] = 1;

		}

	}

	

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

		cout << a[i] << " \n"[i == n];

}



int main() {

    

    ios::sync_with_stdio(false);

    cout.tie(NULL);

    

	int _ = 1;

	cin >> _;



    while (_--)

        solve();

    

    return 0;

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

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

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

    int t; 
    cin >> t;  

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

       
        long long totalSum = 0;
        vector<int> toggles;  

        for (char c : s) {
            int d = c - '0';
            totalSum += d;
            if (d == 2) {
                toggles.push_back(2);  
            } else if (d == 3) {
                toggles.push_back(6);  
            }
           
        }

        int baseMod = (int)(totalSum % 9);

        
        array<bool,9> dp{};
        dp[baseMod] = true;  

        
        for (int tgl : toggles) {
            
            array<bool,9> newdp = dp; 
            for (int r = 0; r < 9; r++) {
                if (dp[r]) {
                    int nr = (r + tgl) % 9;
                    newdp[nr] = true;
                }
            }
            dp = newdp;
        }

        
        if (dp[0]) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }
    return 0;
}


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

using namespace std;



#define RADHE_RADHE ios_base::sync_with_stdio(false);

#define endl '\n'



int main() {

    RADHE_RADHE;



    int t;

    cin >> t;

    while (t--) {

        // First of all if no.s sum%9==0, then "YES"...

        // If not the case and there is no presence of 2 or 3 then "NO"...

        // Its not required to have more than 8 2's and 3 6's...



        string s;

        cin>>s;



        int n = s.size();

        int cnt2 = 0;

        int cnt3 = 0;



        long long sum = 0;



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

            if(s[i]=='3')cnt3++;

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

            sum+=(s[i]-'0');

        }



        if(sum%9==0){

            cout<<"YES"<<endl;

            continue;

        }

        if(!cnt3 && !cnt2){

            cout<<"NO"<<endl;

        }

        else{

            bool ok = false;

            for(int i = 0;i<=min(cnt2,8);i++){

                for(int j = 0;j<=min(cnt3,3);j++){

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

                        ok = true;

                    }

                }

            }



            cout<<(ok?"YES":"NO")<<endl;

        }

    }

    return 0;

}
Problem: 2049B - pspspsps
Language: c++17 

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

using namespace std;

int T,n;

string s;

int main() {

	ios::sync_with_stdio(0);

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

	cin>>T;

    while(T--){

	    cin>>n>>s;

	    bool f=0;

	    s=' '+s;

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

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

	            if(s[i]=='s'&&s[j]=='p'&&i>1&&j!=n){

	                f=1;

	                break;

	            }

	        }

	        if(f) break;

	    }

	    if(f) cout<<"NO"<<"\n";

	    else cout<<"YES"<<"\n";

    }

    return 0;

}

Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
#define pb push_back
#define endl ("\n")
#define all(aa) aa.begin(), aa.end()
typedef long long ll;
using namespace std;

void solve(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	array<int, 2> cnt = {0, 0};
	for(int i = 0; i < n; i++){
		if(s[i] == 's') cnt[0]++;
		if(s[i] == 'p') cnt[1]++;
	}
	if(cnt[0] >= 2 && cnt[1] >= 2){
		cout << "No" << endl;
		return;
	}
	if(cnt[0] == 0 || cnt[1] == 0){
		cout << "Yes" << endl;
		return;
	}
	if(cnt[0] == 1 && s[0] == 's'){
		cout << "Yes" << endl;
		return;
	}
	if(cnt[1] == 1 && s[n - 1] == 'p'){
		cout << "Yes" << endl;
		return;
	}
	cout << "No" << endl;
}

int main(){
	int tt;
	cin >> tt;
	while(tt--){
		solve();
	}
}
Problem: 2062C - Cirno and Operations
Language: c++17 

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

vector<int> l;
int t,n;
int ans;

int get(vector<int> l){
    int res = 0;
    for(int i : l){
        res += i;
    }
    return res;
}

void dfs(vector<int> l){
    //这个数组rep后的数值和就是rep前的最后一项减第一项
    if(l.size() == 1) return;
    int temp = l[l.size()-1] - l[0];
    // printf("temp = %lld\n",temp);
    ans = max(ans,max(temp,-temp));//数值rep后的和的大小
    vector<int> rep;
    for(int i=0;i<l.size();i++){
        if(i > 0) rep.push_back(l[i]-l[i-1]);
    }
    //记录rep后的数值和翻转后的数组
    dfs(rep);
}

signed main(){
    scanf("%lld",&t);
    while(t--){
        scanf("%lld",&n);
        l.clear();

        for(int i=1;i<=n;i++){
            int x;
            scanf("%lld",&x);
            l.push_back(x);
        }

        ans = get(l);//记录最开始的数值
        dfs(l);
        printf("%lld\n",ans);
    }
    return 0;
}

Solution 2 (runtime: 46 ms):
#include <iostream>
#include<vector>
#include<cmath>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<long long> arr(n+1);
        for(int i=1;i<=n;i++){
            cin>>arr[i];
        }
        if(n==1){
            cout<<arr[1]<<endl;
            continue;
        }
        int temp=n;
        long long ans = -1e18;
        
        for(int i=1;i<=n;i++){
            long long sum=0;
            for (int i = 1; i <= temp; i++) sum = (sum + arr[i]);
			if (i == 1) ans = max(ans, sum);
			else ans = max(ans, max(sum, ( - sum) ));
			for (int i = 1; i < temp; i++) arr[i] = (arr[i + 1] - arr[i]);
			temp--;
        }
        
       
        cout<<abs(ans)<<endl;
    
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int mod = 1e9 + 7  ;
using ll = long long int ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
ll gcd(ll a, ll b) { return((b == 0) ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return (b / gcd(a, b)) * a; }

string a,b,c;
int n,m;
int dp[1010][1010];
int rec(int i,int j){
    // cout<<i<<" "<<j<<endl;
    int k=i+j;
    if(i==n && j==m){
        return 0;
    }
    if(dp[i][j]!=-1)return dp[i][j];
    int ans=1e9;
    if(i<n)
    ans=min(ans,rec(i+1,j)+(a[i]!=c[k]));
    if(j<m)
    ans=min(ans,rec(i,j+1)+(b[j]!=c[k]));
    return dp[i][j]=ans;
}


void solve(){
    
    cin>>a>>b>>c;
    n=a.size();
    m=b.size();
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            dp[i][j]=-1;
        }
    }
    cout<<rec(0,0)<<endl;
	
}
signed main() {
	// your code goes here
	ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	int t;
	cin>>t;
	while(t--){
	    solve();
	   // cout<<solve()<<endl;
	   // if(solve())cout<<"YES"<<endl;
	   // else cout<<"NO"<<endl;
	    

	}
}


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

const int N = 2010;
int f[N][N];//f[i][j]表示a匹配到第i个位置 b匹配到第j个位置最大相同的字母个数

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        string a,b,c;
        cin >> a;
        cin >> b;
        cin >> c;
        int n = a.size();
        int m = b.size();
        a = " " + a;
        b = " " + b;
        c = " " + c;
        memset(f,0,sizeof f);
        for(int i = 0;i <= n;i++)
        {
            for(int j = 0;j <= m;j++)
            {
                
                if(i >= 1 ) f[i][j] = f[i-1][j] + (a[i] == c[i + j] ? 1 : 0);
                if(j >= 1 ) f[i][j] = max(f[i][j],f[i][j-1] + (b[j] == c[i + j] ? 1 : 0));
            }
        }

        cout << n + m - f[n][m] << endl;
    }
}