Problem: 2062C - Cirno and Operations
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define KeepGoing ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define Yes cout << "Yes"
#define No cout << "No"
#define YES cout << "YES"
#define NO cout << "NO"
#define endl '\n'
#define nl cout << "\n";
#define print(x) for(auto &y : x)cout << y << ' ';
#define debug(...) cerr << "(" << #__VA_ARGS__ << ") = ", dbg(__VA_ARGS__)
void dbg() { cerr << endl; }
template <typename T, typename... Args>
void dbg(T first, Args... rest) {
    cerr << first << " ";
    dbg(rest...);
}
#define debugArr(arr) cerr << #arr << " = "; for (auto x : arr) cerr << x << " "; cerr << endl;
#define trace() cerr << __FUNCTION__ << " called at line " << __LINE__ << endl;
#define NDEBUG  // Disable assertions
bool valid(int i, int j, int nx, int ny){
    return (nx >= 0 && nx < i && ny >= 0 && ny < j);
}
void solve() {
int n;
cin >> n;
vector<int> v(n);
int ans = 0;
for(auto &x: v) {
    cin >> x;
    ans += x;
}
while(v.size() > 1){
    vector<int> t2, t3;
    int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
    for(auto x: v){
        sum4 += x;
    }
    for(int i = 1; i < v.size(); ++i){
        t2.push_back(v[i] - v[i - 1]);
        sum1 += (v[i] - v[i - 1]);
    }
    reverse(all(v));
    for(auto x: v){
        sum3 += x;
    }
    for(int i = 1; i < v.size(); ++i){
        t3.push_back(v[i] - v[i - 1]);
        sum2 += (v[i] - v[i - 1]);
    }
    if(sum1 >= sum2){
        v = t2;
    }
    else{
        v = t3;
    }
    ans = max({ans, sum1, sum2, sum3, sum4});
}
cout << ans;
}
int main() {
        
    KeepGoing
    int t = 1; 
    cin >> t;    
    while (t--) {
        solve();
        cout << "\n";
        }
        return 0;
    }


    /*

            .  .
            |\_|\
            | a_a\
            | | "]
        ____| '-\___
        /.----.___.-'\
        //        _    \
    //   .-. (~B~) /|
    |'|  /\:  .--  / \
    // |-/  \_/____/\/~|
    |/  \ |  []_|_|_] \ |
    | \  | \ |___   _\ ]_}
    | |  '-' /   '.'  |
    | |     /    /|:  | 
    | |     |   / |:  /\
    | |     /  /  |  /  \
    | |    |  /  /  |    \
    \ |    |/\/  |/|/\    \
    \|\ |\|  |  | / /\/\__\
    \ \| | /   | |__
        / |   |____)
        |_/



    */

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define KeepGoing ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define Yes cout << "Yes"
#define No cout << "No"
#define YES cout << "YES"
#define NO cout << "NO"
#define endl '\n'
#define nl cout << "\n";
#define print(x) for(auto &y : x)cout << y << ' ';
#define debug(...) cerr << "(" << #__VA_ARGS__ << ") = ", dbg(__VA_ARGS__)
void dbg() { cerr << endl; }
template <typename T, typename... Args>
void dbg(T first, Args... rest) {
    cerr << first << " ";
    dbg(rest...);
}
#define debugArr(arr) cerr << #arr << " = "; for (auto x : arr) cerr << x << " "; cerr << endl;
#define trace() cerr << __FUNCTION__ << " called at line " << __LINE__ << endl;
#define NDEBUG  // Disable assertions
bool valid(int i, int j, int nx, int ny){
    return (nx >= 0 && nx < i && ny >= 0 && ny < j);
}
void solve() {
int n;
cin >> n;
vector<ll> v(n);
ll ans = 0;
for(auto &x: v) {
    cin >> x;
    ans += x;
}
while(v.size() > 1){
    vector<ll> t2, t3;
    ll sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
    for(auto x: v){
        sum4 += x;
    }
    for(int i = 1; i < v.size(); ++i){
        t2.push_back(v[i] - v[i - 1]);
        sum1 += (v[i] - v[i - 1]);
    }
    reverse(all(v));
    for(auto x: v){
        sum3 += x;
    }
    for(int i = 1; i < v.size(); ++i){
        t3.push_back(v[i] - v[i - 1]);
        sum2 += (v[i] - v[i - 1]);
    }
    if(sum1 > sum2){
        v = t2;
    }
    else{
        v = t3;
    }
    ans = max({ans, sum1, sum2, sum3, sum4});
}
cout << ans;
}
int main() {
        
    KeepGoing
    int t = 1; 
    cin >> t;    
    while (t--) {
        solve();
        cout << "\n";
        }
        return 0;
    }


    /*

            .  .
            |\_|\
            | a_a\
            | | "]
        ____| '-\___
        /.----.___.-'\
        //        _    \
    //   .-. (~B~) /|
    |'|  /\:  .--  / \
    // |-/  \_/____/\/~|
    |/  \ |  []_|_|_] \ |
    | \  | \ |___   _\ ]_}
    | |  '-' /   '.'  |
    | |     /    /|:  | 
    | |     |   / |:  /\
    | |     /  /  |  /  \
    | |    |  /  /  |    \
    \ |    |/\/  |/|/\    \
    \|\ |\|  |  | / /\/\__\
    \ \| | /   | |__
        / |   |____)
        |_/



    */