Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#define ar array
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()

const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;

#define int long long

// #define SRIV

#ifdef SRIV
#include "debug.hpp"
#else
#define debug(...)  42
#endif

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

void solve() {
    int n; cin >> n;
    vector<int> a(n); 
    for (int &x : a) cin >> x;

    vector<int> b;
    int max_sum = accumulate(all(a), 0LL);
    while(a.size()>1){
        vector<int> temp;
        if(a[0]-a[n-1]>a[0]-a[n-1]){
            for(int i=0; i<a.size()-1; i++){
                temp.push_back(a[i+1]-a[i]);
            }
            a = temp;
            max_sum = max(max_sum, accumulate(all(a), 0LL));
        }else{
            reverse(a.begin(), a.end());
            for(int i=0; i<a.size()-1; i++){
                temp.push_back(a[i+1]-a[i]);
            }
            a = temp;
            max_sum = max(max_sum, accumulate(all(a), 0LL));
        }
    }
    cout << max_sum << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
}

Submission (verdict: Wrong answer on test 6):
#include <bits/stdc++.h>

using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#define ar array
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()

const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;

#define int long long

// #define SRIV

#ifdef SRIV
#include "debug.hpp"
#else
#define debug(...)  42
#endif

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

void solve() {
    int n; cin >> n;
    vector<int> a(n); 
    for (int &x : a) cin >> x;

    int max_sum = accumulate(all(a), 0LL);
    while(a.size()>1){
        vector<int> temp;
        if(a[0]-a[n-1]<a[n-1]-a[0]){
            for(int i=0; i<a.size()-1; i++){
                temp.push_back(a[i+1]-a[i]);
            }
            a = temp;
            max_sum = max(max_sum, accumulate(all(a), 0LL));
        }else{
            reverse(a.begin(), a.end());
            for(int i=0; i<a.size()-1; i++){
                temp.push_back(a[i+1]-a[i]);
            }
            a = temp;
            max_sum = max(max_sum, accumulate(all(a), 0LL));
        }
    }
    cout << max_sum << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
}