Problem: 2062C - Cirno and Operations
Language: c++23 

Code 1:
//
// Created by Mrlaolu on 2024/7/10.
//

#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include <format>


#define int long long
#define endl '\n'
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define x first
#define y second
#define lc v<<1
#define rc v<<1|1
const int N = 4e5 + 10;
using namespace std;
using PII = pair<int,int>;
using i128 = __int128;
#define debug0
const int base = 233;
const int ubase = 141;
using ull = unsigned long long;
const int MOD = 998244353;

int ans = -INT_MAX;
void dfs(vector<int>& arr,int sum){
    if(arr.size() == 1){
        return;
    }
    for(int k = 0;k <= 1;++k){
        if(k)reverse(arr.begin(),arr.end());
        int tsum = sum;
        vector<int>b;
        for(int i = 1;i < arr.size();++i){
            int t = arr[i] - arr[i - 1];
            tsum += t;
            b.push_back(t);
        }
        if(ans < (int)accumulate(b.begin(),b.end(),0)){
            ans = (int)accumulate(b.begin(),b.end(),0);
            for(auto it : b)cout << it << " ";
            cout << "ans :" << ans << endl;
        }

        dfs(b,0);
    }

};

void solve() {
    int n;cin >> n;
    vector<int>a(n);
    for(int i = 0;i < n;++i)cin >> a[i];
    int ans = accumulate(a.begin(),a.end(),0);
    auto diff = [&](int x,int y){
        return x > 0 && y < 0 || x < 0 && y > 0;
    };
    while(a.size() > 1){
        vector<int>b;int cntb = 0,absb = 0,sumb = 0;
        for(int i = 1;i < a.size();++i){
            b.push_back(a[i]-a[i-1]);
            if(i > 1 && diff(b[i-1],b[i-2]))cntb++;
            absb += abs(b[i-1]);
            sumb += b[i-1];
        }
        reverse(a.begin(),a.end());
        vector<int>c;int cntc = 0,absc = 0,sumc = 0;
        for(int i = 1;i < a.size();++i){
            c.push_back(a[i]-a[i-1]);
            if(i > 1 && diff(c[i-1],c[i-2]))cntc++;
            absc += abs(c[i-1]);
            sumc += c[i - 1];
        }
        ans = max({ans,sumb,sumc});
        if(cntb == cntc){
            if(absb < absc)a = c;
            else a = c;
        }else{
            if(cntb > cntc)a = b;
            else a = c;
        }
    }

    cout << ans << endl;
}

#define FILE
#define MULTI

signed main() {


#ifndef ONLINE_JUDGE
#ifdef FILE
    freopen("in.txt", "r",stdin);
    freopen("out.txt", "w",stdout);
#endif
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;

#ifdef MULTI
    cin >> T;
#endif


    auto be = chrono::steady_clock::now();
    while(T--){
        solve();
    }

    auto af = chrono::steady_clock::now();
//    cout << chrono::duration<double,milli>(af-be).count() << "ms" << endl;
    return 0;
}

Code 2:
//
// Created by Mrlaolu on 2024/7/10.
//

#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include <format>


#define int long long
#define endl '\n'
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define x first
#define y second
#define lc v<<1
#define rc v<<1|1
const int N = 4e5 + 10;
using namespace std;
using PII = pair<int,int>;
using i128 = __int128;
#define debug0
const int base = 233;
const int ubase = 141;
using ull = unsigned long long;
const int MOD = 998244353;

int ans = -INT_MAX;
void dfs(vector<int>& arr,int sum){
    if(arr.size() == 1){
        return;
    }
    for(int k = 0;k <= 1;++k){
        if(k)reverse(arr.begin(),arr.end());
        int tsum = sum;
        vector<int>b;
        for(int i = 1;i < arr.size();++i){
            int t = arr[i] - arr[i - 1];
            tsum += t;
            b.push_back(t);
        }
        ans = max(ans, (int)accumulate(b.begin(),b.end(),0));
        dfs(b,0);
    }
};

void solve() {
    int n;cin >> n;
    vector<int>a(n);
    for(int i = 0;i < n;++i)cin >> a[i];
    ans = accumulate(a.begin(),a.end(),0);
    dfs(a,0);
    
    cout << ans << endl;
}

#define FILE
#define MULTI

signed main() {


#ifndef ONLINE_JUDGE
#ifdef FILE
    freopen("in.txt", "r",stdin);
    freopen("out.txt", "w",stdout);
#endif
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;

#ifdef MULTI
    cin >> T;
#endif


    auto be = chrono::steady_clock::now();
    while(T--){
        solve();
    }

    auto af = chrono::steady_clock::now();
//    cout << chrono::duration<double,milli>(af-be).count() << "ms" << endl;
    return 0;
}

Answer: 1